= Android Kotlin Projects
:page-aliases: android_app_kotlin_examples.adoc



This page provides an example of using Mill as a build tool for Android applications.
This workflow is still pretty rough and nowhere near production ready, but can serve as
a starting point for further experimentation and development.

*Relevant Modules*

These are the main Mill Modules that are relevant for building Android apps:

* {mill-doc-url}/api/latest/mill/androidlib/AndroidSdkModule.html[`mill.androidlib.AndroidSdkModule`]: Handles Android SDK management and tools.
* {mill-doc-url}/api/latest/mill/androidlib/AndroidAppKotlinModule.html[`mill.kotlinlib.android.AndroidAppKotlinModule`]: Provides a framework for building Android applications.
* {mill-doc-url}/api/latest/mill/kotlinlib/KotlinModule.html[`mill.kotlinlib.KotlinModule`]: General Kotlin build tasks like compiling Kotlin code and creating JAR files.

== Simple Android Hello World Application

include::partial$example/androidlib/kotlin/1-hello-kotlin.adoc[]

This example demonstrates how to create a basic "Hello World" Android application
using the Mill build tool. It outlines the minimum setup required to compile Kotlin code,
package it into an APK, and run the app on an Android device.

== Understanding `AndroidSdkModule` and `AndroidAppKotlinModule`

The two main modules you need to understand when building Android apps with Mill
are `AndroidSdkModule` and `AndroidAppKotlinModule`.

`AndroidSdkModule`:

* This module manages the installation and configuration of the Android SDK, which includes
tools like `aapt`, `d8`, `zipalign`, and `apksigner`. These tools are used
for compiling, packaging, and signing Android applications.

`AndroidAppKotlinModule`:
This module provides the step-by-step workflow for building an Android app. It handles
everything from compiling the code to generating a signed APK for distribution.

1. **Compiling Kotlin code**: The module compiles your Kotlin code into `.class` files, which is the first step in creating an Android app.
2. **Packaging into JAR**: It then packages the compiled `.class` files into a JAR file, which is necessary before converting to Android's format.
3. **Converting to DEX format**: The JAR file is converted into DEX format, which is the executable format for Android applications.
4. **Creating an APK**: The DEX files and Android resources (like layouts and strings) are packaged together into an APK file, which is the installable file for Android devices.
5. **Optimizing with zipalign**: The APK is optimized using `zipalign` to ensure better performance on Android devices.
6. **Signing the APK**: Finally, the APK is signed with a digital signature, allowing it to be distributed and installed on Android devices.
