Skip to main content

Mobile development · Beginner · 26 min

Build your first Android screen with Kotlin and Jetpack Compose

By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · Eclipse Temurin JDK 25 · Kotlin 2.4.21 · Android Gradle Plugin 9.5.3 · Gradle 9.9.2 · Compose BOM 2026.11.01

You will install the Android SDK from the command line, build a one-screen Jetpack Compose app that calls the next queue ticket when a button is tapped, and prove it builds with Gradle unit tests, lint and a debug APK.

On this page

Jetpack Compose is how Android screens are written today. Instead of laying out XML files and then finding views to change them, you write Kotlin functions marked @Composable that describe what the screen shows for the current data. When the data changes, Compose calls those functions again and updates only what changed.

In this tutorial you build a small, real app: a queue-ticket screen for a clinic or a bank counter. It shows the ticket being served, the next one in line, and two buttons, Call next and Reset. Along the way you set up everything an Android build needs from the command line, the same steps a CI server takes, and you read each build file so you know what it does rather than treating it as boilerplate.

You prove the app with Gradle: a unit test for the ticket logic, Android lint, and a debug APK you can install on a phone. Running it on a phone or emulator is the last, optional step.

The first build downloads roughly 1 GB: the SDK, Gradle and the libraries. If you are on prepaid mobile data, do the first three steps over Wi-Fi. Later builds reuse the caches and download almost nothing.

Step 1 · Install the Android command-line tools

Android Studio bundles the SDK, but you do not need it to build. Google publishes the SDK's sdkmanager on its own as the "command line tools only" download. Install curl and unzip, then confirm Java is there, because sdkmanager and Gradle both run on the JVM:

Bash
sudo apt update
sudo apt install -y curl unzip ca-certificates
java -version

The SDK lives in one folder that you name with ANDROID_HOME. ~/Android/Sdk is where Android Studio puts it on Linux, so if you install Studio later it finds the same SDK. Download the tools, check the file against the SHA-256 that Google publishes on the download page, and move them to cmdline-tools/latest, the path sdkmanager expects. The rm -rf line removes only an older copy of these tools, if you had one:

Bash
export ANDROID_HOME="$HOME/Android/Sdk"
mkdir -p "$ANDROID_HOME/cmdline-tools"
cd "$(mktemp -d)"
curl -fsSLO https://dl.google.com/android/repository/commandlinetools-linux-15859902_latest.zip
echo "4e4c464f145a7512b57d088ac6c278c03c9eea610886b35a5e0804e74eedf583  commandlinetools-linux-15859902_latest.zip" | sha256sum -c -
unzip -q commandlinetools-linux-15859902_latest.zip
rm -rf "$ANDROID_HOME/cmdline-tools/latest"
mv cmdline-tools "$ANDROID_HOME/cmdline-tools/latest"

Add the SDK to your path for future terminals, and for this one:

Bash
cat >> ~/.bashrc <<'EOF'
export ANDROID_HOME="$HOME/Android/Sdk"
export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
EOF
export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
sdkmanager --version

Check it worked

sha256sum prints commandlinetools-linux-15859902_latest.zip: OK, and sdkmanager --version prints a version number such as 22.0. If it says command not found, open a new terminal or run the export PATH line again.

Step 2 · Install the SDK platform and build tools

Before sdkmanager downloads anything it needs you to accept Google's licences. Read them first, answering y to each:

Bash
sdkmanager --licenses

On a build server, where nobody is there to type, the usual form pipes in the answers: yes | sdkmanager --licenses.

Now install three packages. platforms;android-37.1 is the Android 17 API your code compiles against, at its first minor release (37.1), which the current Compose libraries need; build-tools;36.0.0 is the version the Android Gradle Plugin 9.5 uses by default, and platform-tools gives you adb for talking to a phone:

Bash
sdkmanager "platforms;android-37.1" "build-tools;36.0.0" "platform-tools"
sdkmanager --list_installed

Check it worked

sdkmanager --list_installed lists build-tools;36.0.0, cmdline-tools;latest, platform-tools and platforms;android-37.1, each with a version and its folder under ~/Android/Sdk.

Step 3 · Create the project and read its build files

There are two ways to start. In Android Studio, choose File, New, New Project and the Empty Activity template, which creates a Compose project with the same build files, plus extras such as resources, a ui/theme package and instrumented tests; compare them with this step and change the versions to match. Or write the files yourself, which is what the rest of this tutorial does, so every line is one you have seen.

A two-column map of the project. On the left, the build files Gradle reads: the version catalog, settings, the root build file, the app build file and the Gradle wrapper. On the right, the app source: the manifest, MainActivity, TicketScreen and Theme, TicketCounter, and a dashed box for the unit test.
What each file in the queue-ticket project does

Make a folder for the project:

Bash
mkdir -p ~/compose-ticket-demo/gradle
cd ~/compose-ticket-demo

The version catalog. Every version the build uses goes in gradle/libs.versions.toml, so upgrading means changing one line here instead of hunting through build files. The Compose libraries have no versions of their own: the BOM (bill of materials) picks a set of Compose versions that are tested together.

Bash
cat > gradle/libs.versions.toml <<'EOF'
[versions]
agp = "9.5.3"
kotlin = "2.4.21"
composeBom = "2026.11.01"
activityCompose = "1.13.0"
junit = "4.13.2"

[libraries]
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
junit = { group = "junit", name = "junit", version.ref = "junit" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
EOF

Settings. settings.gradle.kts tells Gradle where to download plugins and libraries from (Google's Maven repository for Android, Maven Central for the rest) and which modules make up the project. This project has one, :app.

Bash
cat > settings.gradle.kts <<'EOF'
pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "QueueTicket"
include(":app")
EOF

The root build file declares the two plugins with apply false: it fixes their versions for the whole project without applying them to the root, which has no code.

Bash
cat > build.gradle.kts <<'EOF'
plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.kotlin.compose) apply false
}
EOF

cat > gradle.properties <<'EOF'
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
EOF

The app build file is where the Android decisions live. Two plugins are applied. com.android.application is the Android Gradle Plugin (AGP); since AGP 9 it compiles Kotlin itself, so older tutorials' org.jetbrains.kotlin.android plugin is no longer needed and fails if you add it. org.jetbrains.kotlin.plugin.compose is the Compose compiler, which turns @Composable functions into code that can be re-run when state changes. Its version is always the Kotlin version, and declaring it also sets the Kotlin version AGP uses.

Bash
mkdir -p app
cat > app/build.gradle.kts <<'EOF'
plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin.compose)
}

android {
    namespace = "com.example.queueticket"
    compileSdk {
        version = release(37) { minorApiLevel = 1 }
    }

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

    buildFeatures {
        compose = true
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
}

dependencies {
    implementation(libs.androidx.activity.compose)
    implementation(platform(libs.androidx.compose.bom))
    implementation(libs.androidx.compose.ui)
    implementation(libs.androidx.compose.material3)
    implementation(libs.androidx.compose.ui.tooling.preview)
    debugImplementation(libs.androidx.compose.ui.tooling)
    testImplementation(libs.junit)
}
EOF

The three SDK numbers mean different things:

  • compileSdk is the API your code is compiled against, so you can call anything up to Android 17. The release(37) { minorApiLevel = 1 } form picks API 37.1, Android 17's first minor SDK release. The current Compose libraries require at least 37.1 here; with 37.0 or lower the build stops at checkDebugAarMetadata and says so.
  • minSdk = 24 is the oldest Android the app installs on: Android 7.0. Material 3 for Compose needs at least 24. Many low-cost phones still in use across Africa run Android versions well behind the latest, so check your own users' devices before raising this number; each step up cuts some of them off.
  • targetSdk = 37 tells Android which version's behaviour rules the app has been tested with. Google Play requires a recent target for new apps and updates. Raising it can change how the app behaves (for example, from API 35 the app draws edge to edge, behind the status bar), so treat it as a change to test, not a number to bump.

applicationId is the app's identity on a phone and in Play. Replace com.example.queueticket with a domain you control before publishing anything.

Check it worked

Run find . -type f | sort. You see five files: ./app/build.gradle.kts, ./build.gradle.kts, ./gradle.properties, ./gradle/libs.versions.toml and ./settings.gradle.kts.

Step 4 · Write the screen with composables

Start with the logic, kept as plain Kotlin with no Android in it, so a unit test can check it without a phone. A TicketCounter knows the current number, how to show it as A-007, and what comes next. It wraps back to 1 after 999. Because it is a data class with val fields, next() returns a new counter rather than changing the old one.

Bash
mkdir -p app/src/main/java/com/example/queueticket
cat > app/src/main/java/com/example/queueticket/TicketCounter.kt <<'EOF'
package com.example.queueticket

data class TicketCounter(val number: Int = 1) {
    val label: String
        get() = "A-" + number.toString().padStart(3, '0')

    fun next(): TicketCounter =
        TicketCounter(number = if (number >= 999) 1 else number + 1)
}
EOF

Next, the theme. MaterialTheme hands colours, type and shapes down to every Material 3 component inside it, so a Button picks up your primary colour without being told. This theme has a light and a dark colour scheme and follows the phone's setting:

Bash
cat > app/src/main/java/com/example/queueticket/Theme.kt <<'EOF'
package com.example.queueticket

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

private val LightColours = lightColorScheme(
    primary = Color(0xFF00658B),
    secondary = Color(0xFF4F616E),
)

private val DarkColours = darkColorScheme(
    primary = Color(0xFF82CFFF),
    secondary = Color(0xFFB6C9D8),
)

@Composable
fun QueueTicketTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit,
) {
    MaterialTheme(
        colorScheme = if (darkTheme) DarkColours else LightColours,
        content = content,
    )
}
EOF

Now the screen. Column stacks its children top to bottom and Row places them side by side; Arrangement.spacedBy puts a fixed gap between them. Read the first line of TicketScreen closely, because it is the whole state model:

  • mutableStateOf(TicketCounter()) makes a value Compose watches. When it changes, Compose re-runs every composable that read it. That re-run is called recomposition.
  • remember { ... } keeps that value across recompositions. Without it, each re-run would build a fresh counter at A-001.
  • by lets you read and assign counter like a normal variable.

Each button's onClick replaces the counter. Nothing in the code sets text on screen directly.

Bash
cat > app/src/main/java/com/example/queueticket/TicketScreen.kt <<'EOF'
package com.example.queueticket

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Composable
fun TicketScreen(modifier: Modifier = Modifier) {
    var counter by remember { mutableStateOf(TicketCounter()) }

    Column(
        modifier = modifier
            .fillMaxSize()
            .padding(24.dp),
        verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically),
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {
        Text("Now serving", style = MaterialTheme.typography.titleMedium)
        Text(
            counter.label,
            style = MaterialTheme.typography.displayLarge,
            color = MaterialTheme.colorScheme.primary,
        )
        Text(
            "Next in line: ${counter.next().label}",
            style = MaterialTheme.typography.bodyLarge,
        )
        Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
            OutlinedButton(onClick = { counter = TicketCounter() }) {
                Text("Reset")
            }
            Button(onClick = { counter = counter.next() }) {
                Text("Call next")
            }
        }
    }
}

@Preview(showBackground = true, widthDp = 360)
@Composable
private fun TicketScreenPreview() {
    QueueTicketTheme {
        TicketScreen()
    }
}
EOF
Four boxes joined by arrows: a Button onClick sets counter to counter.next(), the mutableStateOf value changes from A-007 to A-008 and is kept by remember, Compose re-runs TicketScreen, and the screen shows A-008 with A-009 next in line. A dashed arrow returns to the start to wait for the next tap.
A tap changes state, and Compose redraws what reads it

@Preview is for Android Studio. In a file with a preview function, the Split or Design view draws the screen without a phone, here at 360 dp wide, the width of many budget phones. The preview function is private and only used by the IDE; it does not appear in the app.

Last, the activity and the manifest. MainActivity is the entry point Android starts; setContent hands its window to Compose. enableEdgeToEdge() and Scaffold deal with the status and navigation bars: the app draws behind them, and Scaffold passes in innerPadding so your content stays clear of them. The manifest names the app and marks MainActivity as the one the launcher opens.

Bash
cat > app/src/main/java/com/example/queueticket/MainActivity.kt <<'EOF'
package com.example.queueticket

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.ui.Modifier

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            QueueTicketTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    TicketScreen(modifier = Modifier.padding(innerPadding))
                }
            }
        }
    }
}
EOF

cat > app/src/main/AndroidManifest.xml <<'EOF'
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application
        android:label="Queue ticket"
        android:theme="@android:style/Theme.Material.Light.NoActionBar">
        <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>
EOF

The labels are typed straight into the code to keep this first screen short. For an app used in more than one language (English and Swahili, or French and Wolof, for example), move them into res/values/strings.xml and read them with stringResource, so a translator can work on one file.

Check it worked

ls app/src/main/java/com/example/queueticket lists MainActivity.kt, Theme.kt, TicketCounter.kt and TicketScreen.kt, and app/src/main/AndroidManifest.xml exists. In Android Studio, open TicketScreen.kt and choose Split: the preview shows "Now serving", a large A-001, "Next in line: A-002" and the two buttons.

Step 5 · Add the Gradle wrapper and run a unit test

The wrapper is a small script, gradlew, plus a properties file that pins the Gradle version. Anyone who clones the project runs ./gradlew and gets Gradle 9.9.2, whatever is installed on their machine. To create it you need Gradle once, so download that version, check it, and run its wrapper task. The --gradle-distribution-sha256-sum flag makes the wrapper check every future download of Gradle against the same checksum, and --network-timeout 60000 gives each of those downloads 60 seconds without data before it gives up, instead of the default 10, which helps on a slow or shared connection. The first ./gradlew run downloads Gradle again into ~/.gradle/wrapper/dists, about 135 MB.

Bash
mkdir -p ~/.local/opt
cd "$(mktemp -d)"
curl -fsSLO https://services.gradle.org/distributions/gradle-9.9.2-bin.zip
echo "971fcd7150ca4ba04852c0b2ca0d2d0ab9468e14b03473eab19528809914c76b  gradle-9.9.2-bin.zip" | sha256sum -c -
unzip -q gradle-9.9.2-bin.zip -d ~/.local/opt
cd ~/compose-ticket-demo
~/.local/opt/gradle-9.9.2/bin/gradle wrapper --gradle-version 9.9.2 --gradle-distribution-sha256-sum 971fcd7150ca4ba04852c0b2ca0d2d0ab9468e14b03473eab19528809914c76b --network-timeout 60000 --no-daemon
./gradlew --version

From now on this project only uses ./gradlew. Keep ~/.local/opt/gradle-9.9.2 if you are going on to the next Compose tutorial: it starts a new project and generates that project's wrapper from this download.

Now write a test for TicketCounter. Files under src/test are local unit tests: they run on your computer's JVM in seconds, with no phone or emulator. That is why the ticket logic lives in its own class rather than inside the composable.

Bash
mkdir -p app/src/test/java/com/example/queueticket
cat > app/src/test/java/com/example/queueticket/TicketCounterTest.kt <<'EOF'
package com.example.queueticket

import org.junit.Assert.assertEquals
import org.junit.Test

class TicketCounterTest {
    @Test
    fun firstTicketIsA001() {
        assertEquals("A-001", TicketCounter().label)
    }

    @Test
    fun nextAddsOne() {
        assertEquals("A-008", TicketCounter(7).next().label)
    }

    @Test
    fun wrapsBackToOneAfter999() {
        assertEquals("A-001", TicketCounter(999).next().label)
    }
}
EOF
./gradlew testDebugUnitTest
ls app/build/test-results/testDebugUnitTest/

The first run takes several minutes: Gradle downloads the Android Gradle Plugin, Kotlin and the Compose libraries, then compiles your composables as well as the test, so this also proves the screen code compiles.

Check it worked

./gradlew --version reports Gradle 9.9.2. The test run ends with BUILD SUCCESSFUL, and ls shows TEST-com.example.queueticket.TicketCounterTest.xml. For a readable report, open app/build/reports/tests/testDebugUnitTest/index.html in a browser: 3 tests, 0 failures. To see a failure, change "A-008" to "A-009" in the test, run it again, read the message, and change it back.

Step 6 · Run lint and build the debug APK

Android lint reads your code, manifest and build files for problems the compiler does not catch: missing exported flags, calls to APIs newer than minSdk, and Compose mistakes such as creating mutableStateOf without remember. Errors fail the build; warnings go in the report. In the same command, assembleDebug packages the app as an APK signed with a debug key that Gradle creates for you.

Bash
./gradlew lintDebug assembleDebug
ls -lh app/build/outputs/apk/debug/

Expect a handful of lint warnings, such as the app having no launcher icon and no backup rules. They are worth fixing before a release, and none of them stop a debug build.

The debug APK is larger than a release build would be, because it is not shrunk and includes the preview tooling. A release build with R8 shrinking turned on is much smaller, which matters to users who pay for every megabyte of data.

Check it worked

The command ends with BUILD SUCCESSFUL, and ls -lh lists app-debug.apk with its size. Open app/build/reports/lint-results-debug.html in a browser: it shows 0 errors and lists each warning with the file and line it refers to.

Step 7 · Run the app on a phone and clean up

To see the screen, plug in an Android phone running Android 7.0 or newer, with USB debugging turned on in Developer options, and accept the prompt on the phone to trust this computer. Then check it is connected and install the APK:

Bash
adb devices
adb install -r app/build/outputs/apk/debug/app-debug.apk

Open Queue ticket from the phone's app list. If you use Android Studio instead, open ~/compose-ticket-demo with File, Open, create an emulator in Device Manager, and press Run.

Try rotating the phone after calling a few tickets: the number goes back to A-001. Rotation recreates the activity, and remember only lasts as long as the composition. Keeping state through that is the subject of the next tutorial in this path.

When you have finished with the project, stop the Gradle background process and delete the folder. If you are going straight on to managing state and lists, keep the SDK and ~/.local/opt/gradle-9.9.2; the next tutorial starts a new project in its own folder, so this one can go.

Bash
cd ~/compose-ticket-demo
./gradlew --stop
cd ~
rm -rf ~/compose-ticket-demo

When you no longer need any of it, remove everything else this tutorial installed: delete ~/Android/Sdk, ~/.local/opt/gradle-9.9.2, the Gradle caches in ~/.gradle, and the two export lines you added to the end of ~/.bashrc.

Check it worked

On the phone, the screen shows "Now serving A-001". Each tap on Call next moves the big number on by one and updates "Next in line", and Reset returns it to A-001. After cleanup, ls ~/compose-ticket-demo reports that there is no such file or directory.

Next steps

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.