Friday, May 4, 2012

Folder Structure of an Android Project


Folder Structure of an Android Project



This tutorial explains the common folder structure and files of an Android Project.
In Eclipse, the package Explorer expands the HelloAndroid project so that it resembles the following figure.
Every Android project structure includes the following list of subfolders.
  • src
  • gen
  • Android version(such as Android 2.2)
  • assets
  • res
These folders aren't the only ones that you can have inside an Android Project, but they're the default folders created by the New Android Project wizard. Other folders include bin,libs and referenced libraries. you won't see the bin library initially, because it's hidden from view in the latest version of the ADT. The libs and referenced libraries folders don't show up until  you add a third party library and reference it in your project.
The two other files in the project are AndroidManifest.xml and default.properties.
Src Folder:
The Source folder - known as src folder in Android project includes stub MainActivity.Java file. They contain the java code of the application.
gen Folder:
This folder contains  java files generated by ADT. These files have references to various resources placed in the application.It contains a special class ‘R’ which contains all these references. For eg. If one wants a reference to an image placed in drawable folders, it will be referred as, R.drawable.imageName. A project's R.Java is an auto-generated file indexing all the resources of the project. You use this class in your source code as a sort of short-hand way to refer to resources you have included in your project. This particularly powerful with the code-completion features of IDEs like Eclipse because it lets you quickly and interactively locate the specific reference you are looking for. Additionally you gain compile-time safety that the resource you want to use really exisits.
asset Folder:
The assets folder is empty by default. This folder is used to store raw asset files. A raw asset file could be one of many assets you may need for the application to work. For example, A file that contains data in a proprietary format for consumption on the device. Android has Asset Manager which can return all the assets currently in the assets directory. If you were to create an application that had its own dictionary for word lookups, you may want to bundle this dictionary into the project by placing the dictionary file in the assets directory.
res Folder:
This folder contains all the resources required like images, layouts and values. Resources are external files(non-code files) that are used by your code and compiled  into your application at build time. Android Supports a number of different kinds of resources files, including XML,PNG and JPEG files. The XML files have very different formats depending on what they describe.
Resources are externalized from source code, and XML files are compiled into a binary, fast loading format for efficiency reasons. Strings are compressed into a more efficient storage form.
List of Resources:
Rescource-types and where to place them:
  • layout-files ------------> "/res/layout/"
  • Images ---------------->"/res/drawable"
  • animations------------->"res/anim/"
  • styles, strings and arrays ---> "/res/values/"
   1.     Names do not have to be exactly like:
   2.
    'arrays.xml'  to define arrays
   3.
    'colors.xml'   to define colors (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
   4. 
   'dimens.xml'  to define dimensions
   5.
    'strings.xml'   to define strings
   6.
    'styles.xml'  to define objects
raw files like mp3 or videos ----------->"/res/raw/"

AndroidManifest.xml
The AndroidManifest.xml is a required file for every Android application. It is located in the root folder of the application, and describes global values for your package, including the application components(activites, services, etc) that the package exposes to the 'outer world' what kind of data each of our activities can handle and how  they can be launched.
An important thing to mention of this file are its so called IntentFilters. These filters describe where and when that activity can be started. Besides declaring your application's Activities, Content Providers, Services and Intent Receivers, you can also specify permissions in AndroidManifest.xml
default.properties
This file helps you identify the default properties of the Android project (such as Android Version). It contains project settings such as build target. This file is integral to the project.

No comments: