Click here to Skip to main content
15,884,099 members
Articles / Mobile Apps / Android

Basic structure of an Android project

Rate me:
Please Sign up or sign in to vote.
4.80/5 (4 votes)
31 May 2012CPOL4 min read 140.8K   1.7K   33   5
The basic structure of an Android project and its major files and classes.


In this article I will explain about the basic structure of an Android project and its major files and classes.


I assume that you have some knowledge in Java programming and you know how to develop in Eclipse. In order to develop an Android project, you have to install the Android plug in for Eclipse. In order to do that, choose (in the top menu) Help -> Install new software, and in the window that opens, insert the address: "". The installation wizard will guide you to download the full Android SDK if it is necessary.

Basic Android project structure

After you have installed all the plug-ins necessary for the development of an Android file, you can now begin to develop an Android application. From the top menu, choose File -> Project, and from the "New Project window", choose "Android Project". Follow the project setup wizard and after finishing the wizard, you will have a basic Android application. Every Android project contains several folders:

  • src: This folder contains the Java source files.
  • gen: Generated Java library, this library is for Android internal use only.
  • Res: Here we can store resource files such as pictures, XML files for defining layouts, and so forth. Within this folder there are additional folders such as Drawable, Layout, and Values.
  • Drawable: Here we store the various graphic files. We can see three types of drawable folders. This is because there are many Android devices with different screen resolutions. By default, there are several versions of this folder such as: Drawable-mdpi, drawable-hdpi, and so forth. This is required in order to adapt to different screen resolutions.
  • Layout: This is the place for XML layout files. Layout files are XML files which define how various Android objects (such as textboxes, buttons, etc.) are organized on the screen.
  • Values: XML files which store various string values (titles, labels, etc.).

Major files in the Android project:

  • AndroidManifest.xml: This is the Android definition file. It contains information about the Android application such as minimum Android version, permission to access Android device capabilities such as internet access permission, ability to use phone permission, etc.
  • MainLayout.xml: This file describes the layout of the page. This means the placement of every component (such as textboxes, labels, radio buttons, user defined components, etc.) on the app screen.
  • Activity class: Every application that occupies the entire device screen needs at least one class which inherits from the Activity class. One major method is called OnCreate. This method initiates the app and loads the layout page.

The Android manifest file

A typical Android.Manifest file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="7" />
        android:label="@string/app_name" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />
		<category android:name="android.intent.category.LAUNCHER" />

Some important definitions in this file:

  • Android:versionCode: This is a numerical value. This is an important attribute because that is how the Android device knows when to alert the user to upgrade the application to a newer version.
  • Android:sdkMinVersion: Defines what is the earliest version of the Android operating system available to this application.
  • Activity element: Defines what the activities available in this application are and which activity has to be loaded at startup.

Layout file

A typical layout file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:text="@string/hello" />


This layout defines one object, a TextView. This is a text label and it is used when a programmer wants to place a text title in your application.

Activity class

One major class is the Activity class. We already defined this class in the android.manifest file as the main activity class. Which is the first class to be loaded and executed right after the Android application will be launched:

package com.firstproject;

import android.os.Bundle;

public class MynewprojectActivity extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

We can see here one major method called "onCreate" which is called when the Activity class is activated. In our specific example, we define a layout file by the line setContentView(R.layout.main).

Let's have some code

We want to change the text in the label from "Hello World" to Hello "New Application". First of all we have to link the label in the layout to a Java object. Before that we have to give an ID to our label object. This is done by opening our layout file, which is called in our specific project "main.xml" and is located in the "res/layout" folder.

In the "TextView" element, we have to add the following attribute:


After that, let's open out main activity class, which in our case is called "" and add the following line in the "OnCreate" method:

TextView mTextView = (TextView)this.findViewById(;
mTextView.setText("Hello my New Project");

The first line defines the linkage between the "TextView" object on the screen and the Java TextView object, and the second line defines the text string in the "TextView" object.


This article explains only the fundamentals of programming for Android devices. If you want to see a full featured Android application, you are welcome to see my chess application at My chess application is also downloadable to Android devices through this address at Google Play:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

SuggestionDemo project is not working. Pin
Member 1095206016-Jul-14 19:23
Member 1095206016-Jul-14 19:23 
QuestionDirectory Structure of an Android Project Pin
boss prabu10-Mar-13 8:25
boss prabu10-Mar-13 8:25 
QuestionThanks Pin
su_penguin7-Jun-12 13:46
su_penguin7-Jun-12 13:46 
SuggestionWhere's the beef? Pin
Slacker00731-May-12 23:55
professionalSlacker00731-May-12 23:55 
GeneralRe: Where's the beef? Pin
wob200019-Aug-12 14:55
wob200019-Aug-12 14:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.