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:
sudo apt update
sudo apt install -y curl unzip ca-certificates
java -versionThe 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:
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:
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 --versionCheck 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:
sdkmanager --licensesOn 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:
sdkmanager "platforms;android-37.1" "build-tools;36.0.0" "platform-tools"
sdkmanager --list_installedCheck 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.
Make a folder for the project:
mkdir -p ~/compose-ticket-demo/gradle
cd ~/compose-ticket-demoThe 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.
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" }
EOFSettings. 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.
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")
EOFThe 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.
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
EOFThe 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.
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)
}
EOFThe three SDK numbers mean different things:
compileSdkis the API your code is compiled against, so you can call anything up to Android 17. Therelease(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 atcheckDebugAarMetadataand says so.minSdk = 24is 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 = 37tells 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.
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)
}
EOFNext, 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:
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,
)
}
EOFNow 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 atA-001.bylets you read and assigncounterlike a normal variable.
Each button's onClick replaces the counter. Nothing in the code sets text on screen directly.
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@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.
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>
EOFThe 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.
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 --versionFrom 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.
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.
./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:
adb devices
adb install -r app/build/outputs/apk/debug/app-debug.apkOpen 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.
cd ~/compose-ticket-demo
./gradlew --stop
cd ~
rm -rf ~/compose-ticket-demoWhen 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
- Keep the ticket number through rotation, move state into a ViewModel and show a list: Manage state and lists in Jetpack Compose with a ViewModel.
- Get more confident with the Kotlin used here, including
data classand nullable types: Use Kotlin null safety, data classes and extension functions. - Review how
kotlincand the JVM work underneath Gradle: Hello World in Kotlin. - Compare the same ideas in Flutter's widget model: Build Flutter screens from widgets, rows, columns and lists.
Part of these paths
Related tutorials
- Hello World in Kotlin: kotlinc, a runnable JAR and null safetyYou will install the Kotlin 2.4 command-line compiler, build Hello World into a self-contained JAR that runs with java -jar, and extend it to read a name safely when no input arrives.
- Use Kotlin null safety, data classes and extension functionsYou will build a small Kotlin 2.4 contact book that imports a CSV file using nullable types, data classes, extension functions, a sealed class, scope functions and collection operations, then call it from a Java file.
- Manage state and lists in Jetpack Compose with a ViewModelYou will build a market list app whose ViewModel exposes loading, error and content states through a StateFlow, draw the items in a LazyColumn with stable keys, keep a draft through rotation with rememberSaveable, and prove the ViewModel with plain unit tests.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials