Auto-generate Flow Chart from Java/C++ Codes:

Raptor Flowchart Tutorial For Beginners

Monday, July 23, 2012

Android Project Structure in Eclipse



In this article, we will examine the Android project structure and file organization in detail, by creating a new Android project in Eclipse. Before that, it will be better to read my earlier post on how to setup a complete Android development environment in the Android development tutorial series.
When we start a new Android project in Eclipse, it will automatically creates a lot of files and folders for us. We will look at the meaning and functions of each of these folders in the Android project structure one by one.
You have to create a new Android project in Eclipse to see the project structure.
Follow these steps:
(The screens shown here may vary from yours as it depends on the version of your ADT and SDK)
Open Eclipse
Go to File→New→Project
Android Project Structure

Expand Android Folder, select Android Project and click Next
Android Project Structure

Enter Project Name as ‘TestApp’, leave other options unchanged and click Next
Android Project Structure

Select a build target here from the list of installed Platforms. I’ve selected here 2.3.3 API level 10. Click Next
Android Project Structure
Application Info window appears. Enter these values:
Application Name: ‘TestApp’
Package Name: com.’testapp’
Check Create Activity enter the activity name as ‘TestAppActivity’. Click Finish
Android Project Structure

You’ve created a new Android Project in Eclipse and now you can see the project structure in the Package Explorer window.

Android Project Structure Tree in Package Explorer

Android Project Structure
Here is the brief description of important files/folders in the Android project structure:

/SRC

The src folder contains the Java source code files of your application organized into packages. You can have more than one package in your Android application. Its always a good practice to break the source code of your application into different packages based on its core functionality.  All the source files of your Activities, Services etc. Goes into this folder. In the above screen, you can see the source file of the Activity that we created for our project.

/GEN

The files in the gen folder are automatically generated by the ADT. Here the R.java file contains reference/index  to all the resources in the res we use in our program. Each time we add a new resource to the project, ADT will automatically regenerate the R.java file containing reference to the newly added resource. You should not edit the contents of R.java file manually or otherwise your application may not compile.

/ANDROID

This folder is also called Android target library in Android project structure. The version number will be  same as the build target version that we choose while creating a new project. The android.jar file contains all the essential libraries required for our program.

/ASSETS

The assets folder is used to store raw asset files. You can keep any raw data in the assets folder and there’s an asset manager in Android to read the data stored in the folder. The raw data can be anything such as audio, video, images etc. On important point about assets folder is that the data stored in this folder can’t be referenced by an ID. To access a data in this folder, we have to work with bits and bytes.

/BIN

/bin folder is where our compiled application files go. When we successfully compile an application, this folder will contain java class files, dex files which are executable under Dalvik virtual machine, apk archives etc.

/RES

Res folder is where we store all our external resources for our applications such as images, layout XML files, strings, animations, audio files etc.
Sub folders:

/res/drawable

This folder contains the bitmap file to be used in the program. There are three different folders to store drawables. They are drawable-ldpidrawable-mdpi, drawable-hdpi. The folders are to provide alternative image resources to specific screen configurations. Ldpi, mdpi & hdpi stands for low density, medium density & high density screens respectively. The resources for each screen resolutions are stored in respective folders and the android system will choose it according to the pixel density of the device.

/res/layout

XML files that defines the User Interface goes in this folder.

/res/values

XML files that define simple values such as strings, arrays, integers, dimensions, colors, styles etc. are placed in this folder.

/res/menu

XML files that define menus in your application goes in this folder

Android Manifest file

AndroidManifest.xml is one of the most important file in the Android project structure. It contains all the information about your application. When an application is launched, the first file the system seeks is the AndroidManifest file. It actually works as a road map of your application, for the system.
The Android Manifest file contains information about:
  • Components of your application such as Activities, services etc.
  • User permissions required
  • Minimum level of Android API required

No comments: