Phase 1 · Getting Started with ComposeModule 2~25 min read

How Android Works: From Code to App

Follow an animated journey from Android Studio and Kotlin source through compilation, packaging, installation, and the running app.

Learning goals

The text in your editor and the app on your phone are connected by a build pipeline. Follow one small app through that pipeline, then see how Android turns its installed code into a running screen.

  • Separate the jobs of Android Studio, Gradle, the compiler, and the Android Runtime.
  • Trace Kotlin source, resources, and the manifest into a signed application.
  • Explain which artifact a device installs and how an Activity displays Compose UI.

Before you begin

You only need basic Kotlin to follow the animation. For the practice task, use an Android Studio project created with the Empty Activity Compose template. Keep its generated build configuration.

Watch code become an app

Press Play to follow the journey. Pause at a stage, inspect its input and output, or move one step at a time. The diagram is a teaching model: a real build has many dependent tasks and can reuse cached results.

Interactive walkthrough 01 / 08

From your first line to a running app

Follow one Kotlin screen through the tools that build it and the Android system that runs it.

Development computerAndroid device
MainActivity.ktKotlin
1class MainActivity : ComponentActivity()
2override fun onCreate(…)
3  setContent {
4    Text("Hello, Android!")
5  }
res/AndroidManifest.xmlbuild.gradle.kts
Run app debug variant
Build pipeline Ready
Gradle + AGPCoordinate tasks
Kotlin compiler.kt → JVM bytecode
D8 + AAPT2DEX + resources
Package + signInstallable APK
Simplified debug build · tasks may overlap
9:41
Ready for an appWaiting for the build
Emulator / physical device
Current artifactKotlin source + project resources
SOURCE

Write

Android Studio is your workspace. Write Kotlin in the editor, describe the UI with Compose, and add resources and an Android manifest. The editor helps you write code; it is not the compiler.

Text("Hello, Android!")
Press Play to follow the sequence, or select any step to explore at your own pace.

Editor, compiler & build system

Android Studio is the development environment: its editor helps you write code, its debugger helps inspect a running app, and its device tools let you test. Pressing Run asks the build system to prepare an application and then deploy it to the selected device.

ToolIts responsibilityWhat to remember
Android StudioEditing, previews, debugging, and device tools.The editor is where you work.
Gradle + Android Gradle PluginCoordinate dependencies, build variants, and Android build tasks.The build system organizes the work.
Kotlin compilerCheck and translate Kotlin source into JVM bytecode for this Android project.A compiler translates code.
Android SDK toolsProcess resources, produce DEX code, package, and sign.Different tools handle different inputs.
Android Runtime (ART)Execute managed app code on the Android device.The runtime operates after installation.

Gradle can also run from a terminal without opening the IDE. That is why the same project can be built on your laptop or a build server. See the Android build guide for the underlying configuration.

Inside the build

Start with three inputs: Kotlin files contain behavior, res/ holds resources such as strings and icons, and AndroidManifest.xml declares app components and other platform information. Libraries contribute code and may contribute resources and manifest entries too.

The Kotlin compiler produces JVM bytecode. The Android build then needs DEX, the managed bytecode format used on Android. D8handles this conversion in a typical debug build. When release optimization is enabled, R8also shrinks and optimizes code while producing DEX output. A release build does not automatically mean every optimization is enabled.

Alongside code processing, AAPT2 compiles and links Android resources. The build merges manifest information and packages the required outputs. These are related task paths; resources do not pass through the Kotlin compiler as Kotlin source.

Compose still uses the Android build pipeline

Compose describes UI in Kotlin, but your app still has a manifest, resources, dependencies, compiled code, and a packaged output. The Compose compiler plugin transforms composable code as part of compilation.

APK, AAB & installation

ArtifactPurposeInstalled directly?
APK · Android PackageContains installable app code, resources, manifest information, and a signature.Yes, when compatible and properly signed.
AAB · Android App BundlePublishing artifact used to generate APKs suited to a device.No. A device installs the resulting APKs.

Debug builds are signed with a development key so you can install and test them. Distribution uses a deliberate release signing setup. With Google Play App Signing, an upload key signs the uploaded bundle and the app signing key signs the APKs delivered to users. See the app signing guide and App Bundle guide for these delivery details.

What happens on the device

After installation, tapping a launcher icon asks Android to open the declared launcher Activity. Android starts the app process if needed and creates that Activity. ART executes managed DEX code, using interpretation and compiled code as appropriate; your phone is not opening the original Kotlin file.

MainActivity.kt
// Keep the package declaration generated for your project.
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme {
                Text(text = "Hello from my Android app!")
            }
        }
    }
}
A minimal Compose Activity. Use your existing Compose template and keep its package declaration. You can retain the generated app theme instead of MaterialTheme.

Android calls onCreate. The Activity calls setContent to host Compose, and composable functions describe the interface. Compose manages composition, layout, and drawing as needed. Later state changes can update the UI without rebuilding or reinstalling the application.

Follow your own build

  1. Open your Compose project. Find MainActivity.kt, AndroidManifest.xml, and res/.
  2. Change the greeting to a phrase you will recognize, then run the app on an emulator.
  3. Inspect the Build output. Identify a Kotlin compilation task and Android packaging tasks; exact task names vary by plugin and variant.
  4. Build a debug APK and inspect it with Android Studio's APK Analyzer. Look for DEX files and the packaged manifest.
  5. Explain the journey aloud: source inputs → build tasks → signed APK → installation → Activity → visible UI.

Check your result

Your changed greeting appears on the emulator, and you can identify both source files and build outputs. If compilation fails, start with the first useful Build error. If a successful build crashes after launch, inspect Logcat: building and running are different stages.

Quick check & references

Key takeaways

  • Android Studio supports development; Gradle coordinates a build; compilers and SDK tools transform its inputs.
  • Kotlin source becomes JVM bytecode and then Android DEX code. Resources follow their own processing path.
  • APKs are installed. An AAB is used to generate APKs for distribution.
  • On the device, Android manages components and ART executes managed code; Compose produces the screen from state.

Quick check

1. Which tool coordinates the build tasks and dependencies?

2. What does a device install when an app is delivered from an Android App Bundle?

3. What is the role of D8 in a typical debug build?

Continue with the Android build guide, APK Analyzer documentation, and Android Runtime overview. In the callback lesson, follow the framework calls that bring an Activity to life.