Monday, May 5, 2014

Understanding Android Project Structure

        Its very important to understand the structure of the Android Project before you start developing
your applications . So in a very short tutorial we are going to understand the structure of Android
project .

 1. src - This folder will contain all your java source files .
 2. gen - Generated java library , no tampering with this folder . It is used for Android internal
              purpose only.
 3. libs - This will contain all the external libraries that required for the project .
 4. res -  (Resources directory) As the name suggests , the resources you need for your
              project needs to be placed here. The res will contain sub folders to segregate the
              resources . Some of the important sub-folders are .
     a) drawable - It will contain all the images and logos that are required in your android
         application . In your project you will find 4 different types of drawable resources
         folder , this is to support different type of screen densities .  There is a good description
         on Android Developer Docs on Screen Densities .
     b) values - It will contain a strings.xml , styles.xml and dimens.xml in which you will be
         storing values that you are going to mostly reuse in your application . Its a good practice
         to store the string values in string resource file and access it using the identifier in your code.
    c) layout - It will contain all the layout resource files the Android Application Activities will
       be using in your application .    

5. Android Manifest File 

       It presents important information about your app to the Android system . Its the
information the Android system must have before it runs any  of your App's code .
All the the activities, services, broadcast receivers, and content providers that your
application is using must be declared inside the Android Manifest file .  Apart from
that the manifest file will contain the list of permissions the application will be needing
to run on your phone . It also declares permissions other apps will require to interact with
your app . 


Sample Android Manifest file from one of my apps . 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.taxidriverapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.CAMERA" />

    <uses-feature android:name="android.hardware.camera" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.taxidriverapp.TaxiActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


An activity having the android.intent.action.MAIN and android.intent.category.LAUNCHER settings in the intent-filter indicates that it will be the launcher Activity for the Application. We will also
be specifying the icon , label and default theme of the app inside the Application tag .


The target sdk and the minimum sdk required for the App is also displayed in the Android
manifest file . As you can see the permissions required for the App to run on the Android
system is also displayed on the Manifest file . This means we will be requiring internet access
and camera hadrware access for the Application .



 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
 <uses-permission android:name="android.permission.CAMERA" />

1 comments :

It is really a great work and the way in which u r sharing the knowledge is excellent.Thanks for helping me to understand basic concepts. As a beginner in android programming your post help me a lot.Thanks for your informative article. Android Training in chennai | Android Training institute in chennai