Tek Eye Logo

Tek Eye

Android Project Structure

New to Android App development? After you have installed Android Studio, Google's preferred Integrated Development Environment (IDE), and run you first App, get familiar with the structure of an Android project. This article provides a very brief overview of the directories and files created.

Mike Bugdroid the Android Logo

With Android Studio running and a project open use the Project explorer to browse through all the folders and files. (In Studio's default configuration open the Project explorer by clicking on the Project tab on the left hand side.) The Project explorer supports different views, via the drop down list on the tab. With Project selected in Project explorer you get an everything view. Notice how it reflects the structure of the project as stored in the file system:

Android App Project Structure

(Make sure that the drop-drop down at the top of the Project view is set to Project to see a complete reflection of the project structure.)

If a file is added to the directories outside of studio it will appear in the project structure in studio. Likewise deleting a file from the project in Studio will delete it from the file system (note it will not appear in the Recycle Bin in Windows).

Browse around the project to see where various files reside. In sub-folders there are source code files and resource files (e.g. layouts and images). There are folders and files for the build system (Gradle), and there are IDE configuration and settings files (Android Studio is based upon the IntelliJ IDE).

The First Level Folder

In the project structure the highest level folder is named after the project, as in the HelloWorld example above. In this first level project folder there are several (five) default folders and some configuration files for Gradle (the build tool), Git (a source control tool) and the IDE (IntelliJ based).

Only one of the first level folders is used in day-to-day development. The first level folders are (after the first automatic build):

  • .gradle - A Gradle cache and information directory (stores the version of Gradle being used for the project).
  • .idea - stores the Android Studio (IntelliJ) settings for the project.
  • app - The important folder, where our App code resides.
  • build - A build cache directory (folders storing output from build processes).
  • gradle - The Gradle build wrapper for the project.

The Important Source Code Folder

All the main Android related files and folders for the project live in (by default) the app folder. Under the app folder are a few (four) more Gradle, Git and IntelliJ configuration files. There are three second level folders:

  • build - Build outputs.
  • libs - For additional libraries.
  • src - The important source code folder.

The src folder contains three folders:

  • androidTest - For application unit tests.
  • main - For App code and resources.
  • test - Class unit tests.

The main folder in src is where all the elements that make up an App go. Here is where the source code, screen designs, images and other media, strings and definitions are stored and organised. The names of the folders the various files are stored in are important because the folder structure is used to reference the files.

In the main folder is the vital AndroidManifest.xml file. This is used to configure the App and gives the final constructed App important properties. These properties appear in the compiled Android Application Package (APK) and are used by App stores, e.g. Google Play, and the Android Operating System (OS) to understand the requirements and abilites of the App. The default folders under main are:

  • java - Contains the source code in folders named after the packages to which the Java classes belong.
  • res - Contains all the various types of resources used by an App.

The app folder can be renamed (refactored) if required. As some of the SDK samples have done.

The Day-to-Day View

To simplify the view for day-to-day development select the Android setting in the the Project dropdown. This allows you to concentrate on the code and resources for the App. The Android view by default only shows the java and res folders, the manifest file and build scripts for the App.

Android Project App Only View

Similarly use the Test view to concentrate on test code, if you are writing automated tests for your App.

Android App Source Code Files

The code for an Android App is stored in Java class files. The Java classes are grouped into packages. Each class is stored in a .java file in a folder named after the package. The package name usually contains a reversed URL as a namespace, commonly based on an organisations web address or a persons personal web page or blog. The same namespace is used to uniquely identify an App to the App stores and Android OS.

Studio Android View

The res folder stores all the separate resources for an App, this includes:

  • drawable - Images and screen elements (different screen sizes can be supported, e.g. drawable-hdpi).
  • layout - Store screen and fagment definitions (for portrait or landscape specific layouts create layout-port or layout-land folders).
  • menu - Menu definitions.
  • mipmap - Launcher icons to support different screen densities.
  • values - Strings and constants (e.g. colors) definitions.

See the Android Developers Providing Resources page for full details.

The Commonly Used Strings Resource

One of the most commonly used resource files are those that store string values. Almost all strings in an App are stored as a string resource in XML resource files. The initial default string's file is called strings.xml in the values folder. Unlike some resources, e.g. layouts, the file name is not important for strings. There can be many XML files storing string values. This helps with organising large projects, e.g. screen_1_strs.xml, screen_2_strs.xml, etc. See the Resource Types pages on Android Developers for further detail on naming resources.

Gradle, the App Project Builder

Gradle is the default builder for Android projects. The Gradle related script files are:

  • build.gradle - A build file for each Module and the overall project
  • settings.gradle - Project settings
  • gradle.properties - Project properties
  • local.properties - Automatically generated local configuration settings
  • proguard-rules.pro - ProGuard rules for the app (edit if using the WebView with JavaScript)
  • gradlew and gradlew.bat - Unix and Windows scripts for starting Gradle (ensuring the correct version of Gradle used by the project is available)

Miscellaneous Files

  • .gitignore - Folders and files that Git repositories should not store
  • *.iml - iml files store Module information for Android Studio (IntelliJ)

All of the above is for a basic App and the default Studio installation. As with most modern IDEs a lot of settings can be modified and the structure can be changed to fit in with an organisation's requirements. However, sticking to the default settings usually produces less problems in the long run.

See Also

This article is intended to provide a brief guide to the Android project structure in Android Studio. There is a lot more information available on the Android Developers Studio web pages and IntelliJ Help. Don't forget to try out the example Apps that come with the Android Software Development Kit (SDK) to see how their files are organised. Enjoy your Android coding.

Author:  Published:  Updated:  

markdown CMS Small Logo Icon ↓markdown↓ CMS is fast and simple. Build websites quickly and publish easily. For beginner to expert.

Articles on:

Android, HTML, ↓markdown↓ CMS, VPS, Computing, Computer History