Project Structure and Folder Layout in Android Studio
Understanding the project structure and folder layout in Android Studio is essential for efficient Android application development. This article explains the key components of an Android Studio project and their purposes with examples.
Overview of the Project Structure
When you create a new Android project in Android Studio, it generates a default structure with folders and files organized in a way to simplify development and maintenance. Below is an overview of the main parts of the project structure:
1. App Module
The "app" module is the core module of the project, where the actual Android application code resides. It contains the following folders:
-
manifests/
This folder contains the AndroidManifest.xml file, which defines the application's structure, permissions, components, and entry points.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp"> <application android:allowBackup="true" android:label="MyApp" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
-
java/
This folder contains the Java or Kotlin source files, organized by package names.
com.example.myapp MainActivity.java
For example, a simple MainActivity might look like this:
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
-
res/
The "res" folder contains all the app's resources, such as layouts, images, and strings.
-
layout/
XML files for UI design. For example, activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, World!" /> </LinearLayout>
-
drawable/
Images and vector files.
-
values/
Files for constants, such as strings.xml:
<resources> <string name="app_name">MyApp</string> </resources>
-
layout/
2. Gradle Scripts
The project includes build scripts for managing dependencies and configurations. The main files are:
-
build.gradle (Project Level)
This file defines configurations for the entire project, such as the Gradle version and repositories.
buildscript { repositories { google() mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:8.0.0" } } allprojects { repositories { google() mavenCentral() } }
-
build.gradle (Module Level)
This file defines dependencies and settings for the app module.
plugins { id 'com.android.application' } android { compileSdk 33 defaultConfig { applicationId "com.example.myapp" minSdk 21 targetSdk 33 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } } dependencies { implementation 'androidx.appcompat:appcompat:1.6.1' }
3. External Libraries
Android Studio organizes third-party libraries under the "External Libraries" section in the project view. These libraries are managed through the Gradle scripts.
Conclusion
Android Studio's project structure is organized to separate concerns, making it easier to manage the different components of an Android application. Understanding this structure will help you navigate and build efficient applications.