Android Setup & App Anatomy
This part requires Android Studio and either an emulator or a physical
device. The example project lives in examples/android/.
Create a project
- Install Android Studio.
- New Project → Empty Activity (Compose).
- Set a package name (e.g.
com.example.kotlinguide) and Kotlin as the language. - Let Gradle sync finish.
Project anatomy
app/
├── build.gradle.kts # module config: SDK versions, dependencies
├── src/main/
│ ├── AndroidManifest.xml # components, permissions, app metadata
│ ├── kotlin/.../MainActivity.kt
│ └── res/ # resources: strings, themes, drawables
│ └── values/
│ ├── strings.xml
│ └── themes.xml
build.gradle.kts # root build (plugin versions)
settings.gradle.kts # modules + repositories
gradle/libs.versions.toml # version catalog
Key files:
| File | Purpose |
|---|---|
AndroidManifest.xml |
Declares activities, permissions, and the launcher entry point |
build.gradle.kts (app) |
compileSdk, minSdk, dependencies, build features |
res/ |
Strings, themes, images — referenced as R.string.app_name |
MainActivity.kt |
The entry-point screen |
Running
Pick a device in the toolbar (create an emulator via Device Manager if needed) and press Run (▶). Android Studio builds the APK, installs it, and launches the app.
From the command line (in examples/android/):
./gradlew :app:assembleDebug # build the debug APK
./gradlew :app:installDebug # install on a running device/emulator
assembleDebug and unit tests run in CI. Installing and instrumented
(emulator) tests are run locally — they need a device.
The minimal app
The example’s MainActivity sets Compose content:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
Surface { CounterScreen() }
}
}
}
}
We will unpack CounterScreen and setContent in the
UI & Jetpack Compose chapter.
Exercises
-
Create and run the Empty Activity project on an emulator.
-
Change the launcher label in
res/values/strings.xmland confirm it updates.
Next: Activity Lifecycle