Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes:#3868 Added Android Bundle Support #3935

Merged
merged 12 commits into from
Nov 13, 2024
23 changes: 22 additions & 1 deletion docs/modules/ROOT/pages/javalib/android-examples.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This page provides an example of using Mill as a build tool for Android applicat
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
==== Relevant Modules

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

Expand Down Expand Up @@ -45,4 +45,25 @@ everything from compiling the code to generating a signed APK for distribution.
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.

After creating Simple Android Application now let's focus on how to create Android App Bundle Using Mill Build Tool

== Android App Bundle

include::partial$example/javalib/android/2-app-bundle.adoc[]

== Understanding `AndroidAppBundle`

The `AndroidAppBundle` trait is used to create and manage Android App Bundles (AAB) in Mill. It provides tasks for creating, building, and signing an AAB from Android resources and DEX files.

* {mill-doc-url}/api/latest/mill/javalib/android/AndroidAppBundle.html[`mill.javalib.android.AndroidAppBundle`]: Provides a framework for building Android App Bundle.

==== Key Functions

- **androidAaptOptions:** Here, Overrides `androidAaptOptions` to add the `--proto-format` option to AAPT commands, enabling protocol buffer format for assets.

- **androidBundleZip:** Creates a zip archive containing: `Compiled DEX files`, `Resources`, `libraries`, and `assets`, The `Android manifest`.
This zip follows the Android App Bundle format, as outlined in the official documentation.

- **androidUnsignedBundle:** Uses the `bundleTool` to build an unsigned AAB from the bundle zip.

- **androidBundle:** Signs the AAB using a specified keystore with the `jarsigner` tool, producing a signed Android App Bundle (AAB).
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/kotlinlib/android-examples.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This page provides an example of using Mill as a build tool for Android applicat
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
=== Relevant Modules

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

Expand Down
7 changes: 3 additions & 4 deletions example/javalib/android/1-hello-world/app/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.helloworld.app">
<uses-sdk android:minSdkVersion="9"/>
<uses-sdk android:targetSdkVersion="35"/>
<application android:label="Hello World" android:debuggable="true">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.helloworld.app" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="35"/>
<application android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<color name="white">#FFFFFF</color>
<color name="text_green">#34A853</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="app_name">HelloWorldApp</string>
<string name="hello_world">Hello, World Java!</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ protected void onCreate(Bundle savedInstanceState) {
// Create a new TextView
TextView textView = new TextView(this);

// Set the text to "Hello, World!"
textView.setText("Hello, World!");
// Set the text to the string resource
textView.setText(getString(R.string.hello_world));

// Set text size
textView.setTextSize(32);

// Center the text within the view
textView.setGravity(Gravity.CENTER);

// Set layout parameters (width and height)
// Set the layout parameters (width and height)
textView.setLayoutParams(
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

// Set the text color using a resource
textView.setTextColor(getResources().getColor(R.color.text_green));

// Set the background color using a resource
textView.setBackgroundColor(getResources().getColor(R.color.white));

// Set the content view to display the TextView
setContentView(textView);
}
Expand Down
16 changes: 10 additions & 6 deletions example/javalib/android/1-hello-world/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import mill.javalib.android.{AndroidAppModule, AndroidSdkModule}
// Create and configure an Android SDK module to manage Android SDK paths and tools.
object androidSdkModule0 extends AndroidSdkModule {
def buildToolsVersion = "35.0.0"
def bundleToolVersion = "1.17.2"
}

// Actual android application
Expand All @@ -39,15 +40,18 @@ object app extends AndroidAppModule {
// By extending `AndroidAppModule`, we leverage its predefined Android build tasks, ensuring that
// all necessary steps (resource generation, APK creation, and signing) are executed automatically.
//
// ### Project Structure:
// #### Project Structure:
// The project follows the standard Android app layout. Below is a typical project folder structure:
//
// ----
// .
// ├── build.mill
// ├── AndroidManifest.xml
// └── src/main/java
// └── com/helloworld/app
// └── MainActivity.java
// ├── app
// │ ├── AndroidManifest.xml
// │ ├── resources
// │ │ └── values
// │ │ ├── colors.xml
// │ │ └── strings.xml
// │ └── src/main/java/com/helloworld/app/MainActivity.java
// └── build.mill
// ----
//
52 changes: 52 additions & 0 deletions example/javalib/android/2-app-bundle/build.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// This Example provides the basic setup for building Android App Bundle using Mill Build Tool.

// By extending `AndroidAppBundle`, we inherit all Android Bundle tasks such as
// Android Bundle zip generation, Bundle Creation and Bundle signing.
// Additionally, `AndroidSdkModule` is embedded, making SDK management seamless.

//// SNIPPET:BUILD
package build

import mill._
import mill.javalib.android.{AndroidSdkModule, AndroidAppBundle}

object androidSdkModule0 extends AndroidSdkModule {
def buildToolsVersion = "35.0.0"
def bundleToolVersion = "1.17.2"
}

object bundle extends AndroidAppBundle {
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)
}

////SNIPPET:END

/** Usage

> ./mill show bundle.androidBundle
".../out/bundle/androidBundle.dest/signedBundle.aab"

*/

// This command triggers the App Bundle Build process, which installs Bundle Tool then resource compilation,
// and then building Android Bundle Zip then Creation of Android App Bundle and finally signs it.
//
// This Mill build configuration is designed to build a simple "Hello World" Android App Bundle.
// By extending `AndroidAppBundle`, we leverage its predefined Android App Bundle build tasks,
// ensuring that all necessary steps (generation, creation, and signing) are executed automatically.
//
// #### Project Structure:
// The project follows the standard Android App Bundle layout. Below is a typical project folder structure:
//
// ----
// .
// ├── app
// │ ├── AndroidManifest.xml
// │ ├── resources
// │ │ └── values
// │ │ ├── colors.xml
// │ │ └── strings.xml
// │ └── src/main/java/com/helloworld/app/MainActivity.java
// └── build.mill
// ----
//
12 changes: 12 additions & 0 deletions example/javalib/android/2-app-bundle/bundle/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.helloworld.app" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="35"/>
<application android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true">
<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<color name="white">#FFFFFF</color>
<color name="text_green">#34A853</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="app_name">HelloWorldBundleApp</string>
<string name="hello_world">Hello, World Bundle!</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.helloworld.app;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Create a new TextView
TextView textView = new TextView(this);

// Set the text to the string resource
textView.setText(getString(R.string.hello_world));

// Set text size
textView.setTextSize(32);

// Center the text within the view
textView.setGravity(Gravity.CENTER);

// Set the layout parameters (width and height)
textView.setLayoutParams(
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

// Set the text color using a resource
textView.setTextColor(getResources().getColor(R.color.text_green));

// Set the background color using a resource
textView.setBackgroundColor(getResources().getColor(R.color.white));

// Set the content view to display the TextView
setContentView(textView);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.helloworld.app">
<uses-sdk android:minSdkVersion="9"/>
<uses-sdk android:targetSdkVersion="35"/>
<application android:label="Hello World" android:debuggable="true">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.helloworld.app" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="35"/>
<application android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<color name="white">#FFFFFF</color>
<color name="text_green">#34A853</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="app_name">HelloWorldApp</string>
<string name="hello_world">Hello, World Kotlin!</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.helloworld.app

import android.app.Activity
import android.os.Bundle
import android.widget.TextView
import android.view.Gravity
import android.view.ViewGroup.LayoutParams
import android.widget.TextView

class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -13,8 +13,8 @@ class MainActivity : Activity() {
// Create a new TextView
val textView = TextView(this)

// Set the text to "Hello, World!"
textView.text = "Hello, World Kotlin!"
// Set the text to the string resource
textView.text = getString(R.string.hello_world)

// Set text size
textView.textSize = 32f
Expand All @@ -23,10 +23,13 @@ class MainActivity : Activity() {
textView.gravity = Gravity.CENTER

// Set layout parameters (width and height)
textView.layoutParams = LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT
)
textView.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)

// Set the text color using a resource
textView.setTextColor(getColor(R.color.text_green))

// Set the background color using a resource
textView.setBackgroundColor(getColor(R.color.white))

// Set the content view to display the TextView
setContentView(textView)
Expand Down
18 changes: 11 additions & 7 deletions example/kotlinlib/android/1-hello-world/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import mill.javalib.android.AndroidSdkModule
// Create and configure an Android SDK module to manage Android SDK paths and tools.
object androidSdkModule0 extends AndroidSdkModule {
def buildToolsVersion = "35.0.0"
def bundleToolVersion = "1.17.2"
}

// Actual android application
object app extends AndroidAppKotlinModule {

def kotlinVersion = "2.0.0"
def kotlinVersion = "2.0.20"
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)
}

Expand All @@ -43,15 +44,18 @@ object app extends AndroidAppKotlinModule {
// By extending `AndroidAppKotlinModule`, we leverage its predefined Android build tasks, ensuring that
// all necessary steps (resource generation, APK creation, and signing) are executed automatically.
//
// ### Project Structure:
// #### Project Structure:
// The project follows the standard Android app layout. Below is a typical project folder structure:
//
// ----
// .
// ├── build.mill
// ├── AndroidManifest.xml
// └── app/src/main/kotlin
// └── com/helloworld/app
// └── MainActivity.kt
// ├── app
// │ ├── AndroidManifest.xml
// │ ├── resources
// │ │ └── values
// │ │ ├── colors.xml
// │ │ └── strings.xml
// │ └── src/main/java/com/helloworld/app/MainActivity.kt
// └── build.mill
// ----
//
Loading
Loading