Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

Android Studio Folder Structure

Hi,

Let’s start with Android studio folder structure. In previous post we learned how to set up android environment to your system and how to build your first application with Android Studio.

In this tutorial we are getting familiar with Project overview. A project in Android Studio contains everything that defines your workspace for an app, from source code and assets, to test code and build configurations. You will learn basic information about structure of a project and Android Studio interface.
When we start a new project in Android Studio it will automatically creates a lot of files and folders for for us.In this tutorial we will learn briefly the functions of each of these folders in the android project structure one by one.

Modules


When you start a new project, Android Studio creates necessary structure for all files and makes them visible in the project window on the left side of (IDE).
In this tutorial we will learn about,

Modules
Project Files
Project Structure Settings

Let us getting started with Modules.
A Module is a collection of source files and build build settings that allow you to divide your project into discrete units of functionality. Your project can have one or many modules and one module may use another module as dependency. Each module can be independently build,tested and debugged.

You can add a new module to your project by clicking File > New >New Module.
Android studio offers different types of Modules.

Android App Module
Provides a container for your app’s source code, resource files, and app level settings such as the module-level build file and Android Manifest file. When you create a new project, the default module name is “app”.

In the Create New Module window,Android Studio offers the following app modules:

  • Phone & Tablet Module
  • Android Wear Module
  • Android TV Module
  • Glass Module

Now, Library Module
Library module provides container for reusable code.Which you can use as a dependency in other app modules or import into other projects.
Structurally app module and library modules are same. but when we built it it creates Archive file instead of an APK, so it can’t be installed on a device.

In the Create New Module window, Android Studio offers offers the following library modules:

  • Android Library : This type of library can contain all file types supported in an Android project, including source code, resources and manifest files. The build result is an Android Archive (AAR) file that you can add as a dependency for your project Android app module.
  • Java Library : This type of library contains only java source files. and the build result is an Java Archive (JAR) file that you can add as a dependency for your Android app module or other java projects.

and another one is Google Cloud Module

Provide a container for your Google Cloud backend code.
You can also refer to module as sub-projects. Because gradle also refers to Module as projects.
For Ex : when you create a library module and want to add it as a dependency to your android app module. You must declare it as below,

dependencies {
  compile project(':my-library-module')
}

 

Project Files

 
After talking about Modules now, we will talk about Project Files :
By default, Android studio displays your project files in Android view.This view does not reflect the actual file hierarchy on disk,but is organized by modules and file types to simplify navigation between key source files of your project, hiding certain files or directories that are not commonly used.

Some of the structural changes compared to the structure on disc include the following.

  • Shows all the project’s build related configurations files in a top level Gradle Script group.
  • Shows all manifest for each module in a module-level group.
  • Shows all alternative resource files in a single group,instead of separate folders per resource qualifier.

Within android app module, files are shown in the following groups :

manifests

Contains the AndroidManifest.xml file.

java

Contains the java source code files, separated by package names, including JUnit test code.

res

Contains all non-code resources, such as XML layouts, UI strings, and bitmap images,divided into corresponding sub-directories.

The Android Project View

To see the actual file structure of the project including all files hidden from the android view, select project from the dropdown from the top of the Project window.

When you select Project view, you can see a lot more files and directories. The most important of them are following:

module-name/

     build/
         Contains build outputs.
      
     libs/
         Contains private libraries.

     src/
         Contains all and resource files for the module in the following subdirectories: 

            androidTest/
                    Contains code for the instrumentation tests that run on an Android device.

            main/
                    Contains "main" source set files: the android code and resources shard by all build varients. 

                        AndroidManifest.xml/
                              Describe the nature of application and each of its components. Every application must    have an AndroidManifest.xml file in its root directory.

                        java/
                              Contains java source files.
                        
                        jni/
                              Contains native code using Java Native Interface.(JNI)

                        gen/
                               Contains the java files generated by android studio, such as R.java file and interfaces.
                         res/
                               Contains application resources, such as drawable files, layout files,and UI strings.

                       assets/
                               Contains files that should be compiled into an .apk file. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes. 
                           
               test/
                   Contains the code for local tests that run on your host JVM.
       
      build.gradle(module)
              his defines the module specific build configurations.

build.gradle(project)
      This defines your build configuration that apply to all modules. This file is integral to the project, so you should maintain them in revision control with all other source code            

This is all about Android folder structure.

Share: