Skip to content

Commit 26b9c08

Browse files
committed
comments suggestions
1 parent e22e0d9 commit 26b9c08

File tree

4 files changed

+34
-171
lines changed

4 files changed

+34
-171
lines changed
Lines changed: 18 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
//// SNIPPET:BUILD
2-
// This section sets up a basic Android project using Mill.
3-
// We utilize `AndroidAppModule` and `AndroidSdkModule` to streamline the process of
4-
// building an Android application with minimal configuration.
5-
//
6-
// By extending `AndroidAppModule`, we inherit all Android-related tasks such as
7-
// resource generation, APK building, DEX conversion, and APK signing.
8-
// Additionally, `AndroidSdkModule` is embedded, making SDK management seamless.
9-
1+
// R8 is a code shrinker and obfuscator for Android applications. Is designed to optimize the size of the APK
2+
// while maintaining the functionality of the app.
3+
// When using R8, you can configure the rules for code shrinking and obfuscation in a ProGuard configuration file.
4+
// You need 2 files on the root of your project:
5+
// 1. proguard-rules.pro: This file contains the rules for R8 to follow when shrinking and obfuscating the code.
6+
// 2. test-proguard-rules.pro: This file contains the rules for R8 to follow when shrinking and obfuscating the unit and instrumented tests.
7+
// You can also override the default Proguard files by using override def proguardConfigs: T[Seq[PathRef]]
8+
// See Also: app/proguard-rules.pro & app/test-proguard-rules.pro
109
package build
1110

1211
import mill._, javalib._
1312
import mill.javalib.android.{AndroidAppModule, AndroidSdkModule}
1413
import mill.javalib.android.AndroidTestModule
1514

16-
// Create and configure an Android SDK module to manage Android SDK paths and tools.
17-
object androidSdkModule0 extends AndroidSdkModule {
15+
object androidSdkModule0 extends AndroidSdkModule { // <1>
1816
def buildToolsVersion = "35.0.0"
1917
}
2018

21-
// Actual android application
22-
object app extends AndroidAppModule {
19+
object app extends AndroidAppModule { // <2>
2320
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)
2421
def androidMinSdk = 19
2522
def androidCompileSdk = 35
@@ -66,9 +63,9 @@ object app extends AndroidAppModule {
6663
}
6764

6865
}
69-
//// SNIPPET:END
7066

71-
////SNIPPET:END
67+
// <1> Create and configure an Android SDK module to manage Android SDK paths and tools.
68+
// <2> The actual Android application
7269

7370
/** Usage
7471

@@ -89,86 +86,9 @@ object app extends AndroidAppModule {
8986

9087
*/
9188

92-
// This command triggers the build process, which installs the Android Setup, compiles the Java
93-
// code, generates Android resources, converts Java bytecode to DEX format, packages everything
94-
// into an APK, optimizes the APK using `zipalign`, and finally signs it.
95-
//
96-
// This Mill build configuration is designed to build a simple "Hello World" Android application.
97-
// By extending `AndroidAppModule`, we leverage its predefined Android build tasks, ensuring that
98-
// all necessary steps (resource generation, APK creation, and signing) are executed automatically.
99-
//
100-
// #### Project Structure:
101-
// The project follows the standard Android app layout. Below is a typical project folder structure:
102-
//
103-
// ----
104-
// .
105-
//├── app
106-
//│ └── src
107-
//│ ├── androidTest/java/com/helloworld/app/ExampleInstrumentedTest.java
108-
//│ ├── main
109-
//│ │ ├── AndroidManifest.xml
110-
//│ │ ├── java/com/helloworld/app/MainActivity.java
111-
//│ │ └── res
112-
//│ │ └── values
113-
//│ │ ├── colors.xml
114-
//│ │ └── strings.xml
115-
//│ └── test/java/com/helloworld/app/ExampleUnitTest.java
116-
//└── build.mill
117-
// ----
118-
//
119-
120-
/** Usage
121-
122-
> ./mill show app.test
123-
...compiling 2 Java source...
124-
125-
> cat out/app/test/testForked.dest/worker-0/out.json
126-
["",[{"fullyQualifiedName":"com.helloworld.ExampleUnitTest.textSize_isCorrect","selector":"com.helloworld.ExampleUnitTest.textSize_isCorrect","duration":...,"status":"Success"}]]
127-
128-
*/
129-
130-
// This command runs unit tests on your local environment.
131-
132-
/** Usage
133-
134-
> ./mill show app.createAndroidVirtualDevice
135-
...Name: java-test, DeviceId: medium_phone...
136-
137-
> ./mill show app.startAndroidEmulator
138-
139-
> ./mill show app.adbDevices
140-
...emulator-5554...device...
141-
142-
> ./mill show app.it
143-
...
144-
[
145-
"",
146-
[
147-
{
148-
"fullyQualifiedName": "com.helloworld.app.ExampleInstrumentedTest.useAppContext",
149-
"selector": "com.helloworld.app.ExampleInstrumentedTest.useAppContext",
150-
"duration": ...,
151-
"status": "Success"
152-
}
153-
]
154-
]
155-
...
156-
157-
> cat out/app/it/testTask.dest/test-report.xml
158-
...
159-
<?xml version='1.0' encoding='UTF-8'?>
160-
<testsuites tests="1" failures="0" errors="0" skipped="0" time="...">
161-
<testsuite name="com.helloworld.app.ExampleInstrumentedTest.useAppContext" tests="1" failures="0" errors="0" skipped="0" time="0.0" timestamp="...">
162-
<properties>
163-
</properties>
164-
<testcase classname="com.helloworld.app.ExampleInstrumentedTest.useAppContext" name="com.helloworld.app.ExampleInstrumentedTest.useAppContext" time="...">
165-
</testcase>
166-
</testsuite>
167-
</testsuites>
168-
...
169-
170-
> ./mill show app.stopAndroidEmulator
171-
172-
> ./mill show app.deleteAndroidVirtualDevice
173-
174-
*/
89+
// R8 will run automatically when you run the androidReleaseInstall task.
90+
// If you want to create the APK without R8, you can use the androidApk task to create the not-optimized APK. You can also
91+
// run the andoidInstall task that will automaticaly run the androidApk and also install it in the emulator.
92+
// The androidReleaseInstall task will install the optimized APK on the emulator.
93+
// So first you need to create the emulator and start it.
94+
// After the emulator is started, you can run the androidReleaseInstall task and see the app in the emulator.

example/android/kotlinlib/1-hello-kotlin/build.mill

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ object app extends AndroidAppKotlinModule {
7878
> ./mill show app.androidApk
7979
".../out/app/androidApk.dest/app.apk"
8080

81+
> ./mill show app.createAndroidVirtualDevice
82+
...Name: kotlin-test, DeviceId: medium_phone...
83+
84+
> ./mill show app.startAndroidEmulator
85+
86+
> ./mill show app.androidReleaseInstall
87+
...All files should be loaded. Notifying the device...
88+
89+
> ./mill show app.stopAndroidEmulator
90+
91+
> ./mill show app.deleteAndroidVirtualDevice
92+
8193
*/
8294

8395
// This command triggers the build process, which installs the Android Setup, compiles the kotlin

website/docs/modules/ROOT/pages/android/build-docs.adoc

Lines changed: 0 additions & 73 deletions
This file was deleted.

website/docs/modules/ROOT/pages/android/java.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ The `AndroidAppBundle` trait is used to create and manage Android App Bundles (A
6767
- **androidUnsignedBundle:** Uses the `bundleTool` to build an unsigned AAB from the bundle zip.
6868

6969
- **androidBundle:** Signs the AAB using a specified keystore with the `jarsigner` tool, producing a signed Android App Bundle (AAB).
70+
71+
== Using the R8 optimization tool in Android modules
72+
73+
include::partial$example/android/javalib/5-R8.adoc[]

0 commit comments

Comments
 (0)