Skip to content

Latest commit

 

History

History
125 lines (98 loc) · 3.61 KB

File metadata and controls

125 lines (98 loc) · 3.61 KB

Android Project Setup

Create a New Project

Open Android Studio and create a new project:

  1. Click New Project
  2. Select Empty Activity (this template uses Jetpack Compose)
  3. Set Name to MyApp
  4. Set Package name to com.example.myapp
  5. Set Language to Kotlin
  6. Set Minimum SDK to API 24 (covers ~98% of devices)
  7. Click Finish

Android Studio downloads Gradle and builds the project. The first build takes a few minutes.

Project Structure

Diagram: The key files and folders of an Android project.

flowchart TD
    Root["project-root/"] --> Set["settings.gradle.kts"]
    Root --> GradleTop["build.gradle.kts (project)"]
    Root --> App["app/"]
    App --> BuildApp["build.gradle.kts (module)"]
    App --> Src["src/main/"]
    Src --> Manifest["AndroidManifest.xml"]
    Src --> Kotlin["java/com/example/myapp/"]
    Kotlin --> MainActivity["MainActivity.kt"]
    Src --> Res["res/"]
    Res --> Theme["themes/"]
    Res --> Values["values/ (strings, colors)"]
Loading
Path Purpose
settings.gradle.kts Lists modules and plugin/version management
build.gradle.kts (project) Plugins and SDK locations
app/build.gradle.kts Module dependencies, minSdk, targetSdk, app id
AndroidManifest.xml Declares the app, activities, and permissions
MainActivity.kt The entry activity, hosts your Compose UI
res/ Themes, strings, colors, images

The Module Build File

// app/build.gradle.kts
plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin.android)
    alias(libs.plugins.kotlin.compose)   // Compose compiler (K2)
}

android {
    namespace = "com.example.myapp"
    compileSdk = 35

    defaultConfig {
        applicationId = "com.example.myapp"
        minSdk = 24
        targetSdk = 35
        versionCode = 1
        versionName = "1.0"
    }

    buildFeatures {
        compose = true
    }
}

dependencies {
    val composeBom = platform("androidx.compose:compose-bom:2025.06.01")
    implementation(composeBom)
    implementation("androidx.activity:activity-compose:1.10.1")
    implementation("androidx.compose.material3:material3")
}

Key terms:

  • minSdk = 24 — the oldest Android version the app supports
  • targetSdk = 35 — the Android version the app targets (API 35 = Android 15)
  • compileSdk = 35 — the SDK used to compile (must be >= targetSdk)

The AndroidManifest

<!-- AndroidManifest.xml -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:label="MyApp"
        android:theme="@style/Theme.MyApp">

        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

The <intent-filter> with MAIN and LAUNCHER marks MainActivity as the screen shown when the user taps the app icon.

Run the App

  1. Open the Device Manager and create a Pixel 7 emulator (API 35)
  2. Click the green Run button (or press Control + R)
  3. Android Studio builds, installs, and launches the app

You should see the default Compose template — a greeting text centered on screen.

// Emulator output:
// Hello Android!

Practice Exercise

Create a new project, then change the greeting in MainActivity.kt to show your own name. Run it on the emulator and confirm your name appears on screen.