Learn about the Basic Android Application Project Structure - Manifests, Java/Kotlin, Resources, and Gradle Scripts
Basic Android Application Project Structure, includes files like app modules, code files, resources files, etc. which are classified under folders like:
Manifests Folder
Java/Kotlin Folder
res(Resources) Folder
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 applicationres/layout
folder consists of all the XML layout filesres/midmap
folder consists of app icons with different size and densityres/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