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
109package build
1110
1211import mill._, javalib._
1312import mill.javalib.android.{AndroidAppModule, AndroidSdkModule}
1413import 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.
0 commit comments