An android project is a combination of required files and folders which further builds a directory to complete any android application. As android is a most popular open source mobile platform so the need of the android applications is growing very rapidly. In this article i explained the directory structure for any android project. The directory structure is a foundation of any android project. It acts like a container which holds necessary logic’s,images,customization in its real form. During the generation(compilation) of a project, android looks into these folder to locate each type of assets it needs.
Note: Android directory structure typically includes XML layouts,Java code,rich media files and XML animation definitions.
Android Directory Structure
Generally we have three kinds of android projects such as: Android Projects: An Android project is the container for our application's source code, resource files, and files such as the Ant build and Android Manifest file. An application project is the main type of project and the contents are eventually built into an .apk file that you install on a device. Test Projects: These projects contain code to test our application projects and are built into applications that run on a device. Library Projects: These projects contain shareable Android source code and resources that we can reference in Android projects. This is useful when we have common code that we want to reuse. Library projects cannot be installed onto a device, however, they are pulled into the .apk file at build time. Source: http://developers.android.com/
The main objective of an android project is to build an .apk file from it. And for this when we start with an android project then some directories creates by default and some needs few customization to enhance android applications. So let’s understand the directory structure in android project to develop an android application.
/src – This is the most common folder in any android project. It contains our java source code for android application. Under this folder we can see our java source files in which we write logic for android applications.
/gen – In most IDE(such as Eclipse) this folder is created by IDE for configuration purpose. Under this folder we can find two java files such as BuildConfig.java and R.java. Both files are auto generated by IDE which helps android project to work smoothly.
Note: We should not modify these files until we have proper knowledge or requirement to change both files.
/Android(version name) – Under this folder we can see some android.jar file which relates to android sdk platform. We should not modify this file for smooth functioning of our project.
/assets – By default this folder is empty, but we can store raw asset files such as music file,data file etc in this folder. The files retains its original name and structure when compiled into an .apk file.
/bin – This is a very important folder in our directory structure as it contains AndroidManifest.xml file and serve as a output directory for our project which further build an .apk file.
Note: AndroidManifest.xml is a very important file of any android application and works like a control file as it stores the necessary information for any application to work smoothly such as entry point of an application and its components.
/libs – This folder contains private libraries.
/res – This folder contains lots of required sub folders for the project. Let’s understand these folders one by one.
a) /drawable – Under this folder we store images(PNG,JPEG,GIF) for our project. Generally this folder comes with five types of sub folders which ensures rendering of images on mobile devices according to its screen resolution. There are five sub folders with different names such as: drawable-hdpi,drawable-ldpi,drawable-mdpi,drawable-xhdpi,drawable-xxhdpi (where dpi refers to dot per inch). Normally Google prefers .PNG format for images.
b) /layout – Under this folder we store UI layouts file for our android project, which is written in xml format. we can store as many activity file under this folder. In other words this folder relates to our application UI layouts.
c) /menu – For XML files that define application menus.
d) /values – In this folder we place predefined application values in the form of XML files that define the variable names and their value that will be later referenced in our java source code. In simple words, it holds all our constant values for our application in one place. In this way we can customize our applications at one place as per our requirements. Within this folder we can find three xml files such as:
i) dimens.xml: This XML file defines the dimension values such as font sizes and standard heights for our UI.
ii) strings.xml: In this file we define text strings which is used in the application. for example: if we wish to change the title of an application, then we can simply change in this file instead of doing any hard coding in application.
iii) styles.xml: This XML file defines styles which is used in the application. Generally we apply these styles to our UI elements. With the help of style we can separate the look of our application from the layout and functionality.
/project.properties: This file contains project settings, such as the build target. We can edit project properties in eclipse(IDE).
Note: Above mentioned directory structure might be different on other systems because of developer project requirements. So please don’t confuse with other directory structure than this. If anybody feel any problem while understanding directory structure then kindly contact me at: neerajkumar[@]87android[dot]com.
Uploaded by: Author