0
0
Android Kotlinmobile~5 mins

Project structure (app, gradle, manifests) in Android Kotlin

Choose your learning style9 modes available
Introduction

Understanding the project structure helps you find and organize your app files easily. It makes building and running your app smoother.

When you start a new Android app project and want to know where to put your code and resources.
When you need to change app settings like app name or permissions.
When you want to add libraries or dependencies to your app.
When you want to understand how your app is built and packaged.
When you want to fix errors related to app configuration or build.
Syntax
Android Kotlin
ProjectRoot/
  app/
    src/
      main/
        java/ (Kotlin code here)
        res/ (UI resources here)
        AndroidManifest.xml
    build.gradle (Module-level)
  build.gradle (Project-level)
  settings.gradle

app/ folder contains your app code and resources.

build.gradle files control how your app is built and what libraries it uses.

Examples
This file describes your app to the system, like its name and permissions.
Android Kotlin
app/src/main/AndroidManifest.xml
This file lists dependencies and build settings specific to your app module.
Android Kotlin
app/build.gradle
This file manages settings and dependencies for the whole project.
Android Kotlin
build.gradle (Project-level)
Sample App

This shows a simple project structure with a MainActivity Kotlin file inside the app module. The AndroidManifest.xml and build.gradle files are in their usual places.

The MainActivity displays a simple text on the screen.

Android Kotlin
/*
Project structure overview:

ProjectRoot/
  app/
    src/
      main/
        java/com/example/myapp/MainActivity.kt
        res/layout/activity_main.xml
        AndroidManifest.xml
    build.gradle
  build.gradle
  settings.gradle
*/

// MainActivity.kt
package com.example.myapp

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Text

class MainActivity : ComponentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
      Text("Hello from MainActivity")
    }
  }
}
OutputSuccess
Important Notes

Always keep your AndroidManifest.xml inside app/src/main/.

Use the module-level build.gradle to add libraries your app needs.

The project-level build.gradle manages overall project settings and plugin versions.

Summary

The app folder holds your app code and resources.

AndroidManifest.xml describes your app to Android.

build.gradle files control building and dependencies.