Learn about the Basic Android Application Project Structure - Manifests, Java/Kotlin, Resources, and Gradle Scripts

Learn about the Basic Android Application Project Structure - Manifests, Java/Kotlin, Resources, and Gradle Scripts

ยท

2 min read

Basic Android Application Project Structure, includes files like app modules, code files, resources files, etc. which are classified under folders like:

  1. Manifests Folder

  2. Java/Kotlin Folder

  3. res(Resources) Folder

  4. Gradle Scripts


๐Ÿ“ Manifests Folder

Consists of the AndroidManifest.xml which acts as an intermediate between the application and the OS. It communicates the necessary Android Details, packages and data and includes the declaration of all the components used in our application. Also

  • identifies user permissions like storage, gallery, etc.

  • declares minimum API level

  • declares hardware/software requirements like Bluetooth, USB, etc.

  • declares API libraries

Therefore, Android knows about our Application Components through the Manifest file, before starting those components.

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:icon="@drawable/app_icon.png" ... >
        <activity android:name="com.example.project.ExampleActivity"
                  android:label="@string/example_label" ... >
        </activity>
        ...
    </application>
</manifest>

<application> element refers to our application and its android:icon attribute points to the resource for our app icon.

<activity> element refers to our activities and its android:name attribute points to the class of our Activity Subclass.

Application components are declared using <activity>, <service> , <receiver> and <provider>. Thus, Activities, Services and Content Providers that aren't declared in the Manifest, can never be run by the system.

However, Broadcast Receivers can be declared in the Manifests as well as created dynamically in the code.


๐Ÿ—‚๏ธ Java/Kotlin Folder

Consists of all our source code files.


๐Ÿ“ฆ Resources Folder

Consists of all non-code sources like images, audios, etc. Every Resource in our Android Project is mapped with a Unique Integer ID also known as the Resource ID by the SDK build tools. This ID is then mapped with an app-specific integer, which is used to reference that image and insert it in our application user interface.

  • res/drawable folder consists of all the images used in our application

  • res/layout folder consists of all the XML layout files

  • res/midmap folder consists of app icons with different size and density

  • res/values folder consists of XML files like strings, colors, etc.

When the application is compiled, a R class is created which contains resource IDs for all the resources in our res/ directory.

Resource ID is composed of resource type (drawable, layout, etc) and resource name (android:name attribute)

Resources can be accessed :

in code: R.resourceType.resourceName eg. R.string.hello R.drawable.myImage

in xml: @resourceType/resourceName eg. @string/hello @drawable/myImage


๐Ÿ“œ Gradle Scripts

Gradle means automated build system, Gradle Scripts consists of files that define the build configuration that can be applied to all the modules in our application


ย