Skip to content

Commit ee30b0a

Browse files
authored
Android/cleanup app release install (#4996)
## Summary - **better organisation** between androidmodule and androidappmodule (separate properly what things are used in apps and things that are shared between lib building and app building) - R8 and D8 **dex generation** depending on build type settings - **Instrumented tests** now use the android application namespace and id and adding a "variant" indicator - introduced a lite version of **build type settings** with main motivation to control r8 and d8 but also serve as a scaffolding for build variants - **Android manifest** has less hardcoded parameters (uses-sdk and instrumentation tags are now generated) - Minor change into **testTask** to keep it consistent with the rest of modules(Task.Anon) and thus the test-report is now in `testForked.dest` ## R8 and Proguard Followed similar configuration style with gradle ![image](https://github.com/user-attachments/assets/c2c99135-6381-4c91-9ce2-ac5e666f5a33) Although there's still work to be done in that area, if minification is enabled, we use the R8 tool to generate the dex otherwise the d8 (which also uses proguard for now) . This needs further work and clarification as AGP seems to be using R8 by default when minification is enabled, otherwise d8 is used. Proguard default files are also fetched (as an opt-in setting) from the Android SDK directories ## Build settings I've introduced a first very minimal step for doing build variants, mainly out of necessity to manage R8 and D8 variations better, but this will be expanded once we need to fully support build variants. The settings so far concerned the R8 use case at hand and it's a case class that has the parameters to feed proguard files and flags into R8. ## R8 enhancements Extending the work from #4892 , I've made some usability enhancements and enriched the examples to demonstrate how instrumented tests can be used alongside R8 and release builds. I think R8 now can be fairly usable to generate minified and optimised release builds without getting in the middle of development (e.g. running tests and testing in the emulator) although more work needs to be done towards that area, but we'll follow up after we do more exploratory usability testing! ## Future work Following this work, we can move to complete the work on architecture samples by testing instrumented tests, unit tests and later on debug variants. The cleanup also reduced a lot of duplication between `AndroidAppModule` and `AndroidModule` so it will make our development efforts a bit easier to add more features! More discovery work will follow to align the instrumented test apk installation more in line with AGP
1 parent f796397 commit ee30b0a

File tree

27 files changed

+566
-702
lines changed

27 files changed

+566
-702
lines changed
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0">
2-
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="35"/>
32
<application android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true">
43
<activity android:name=".MainActivity"
54
android:exported="true">
@@ -9,7 +8,4 @@
98
</intent-filter>
109
</activity>
1110
</application>
12-
<instrumentation
13-
android:name="androidx.test.runner.AndroidJUnitRunner"
14-
android:targetPackage="com.helloworld.app" />
1511
</manifest>

example/androidlib/java/1-hello-world/build.mill

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ object app extends AndroidAppModule {
4545

4646
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)
4747

48-
override def instrumentationPackage = "com.helloworld.app"
49-
5048
/* TODO currently the dependency resolution ignores the platform type and kotlinx-coroutines-core has
5149
* conflicting classes with kotlinx-coroutines-core-jvm . Remove the exclusions once the dependency
5250
* resolution resolves conflicts between androidJvm and jvm platform types
@@ -141,7 +139,7 @@ object app extends AndroidAppModule {
141139
]
142140
...
143141

144-
> cat out/app/it/testTask.dest/test-report.xml
142+
> cat out/app/it/testForked.dest/test-report.xml
145143
...
146144
<?xml version='1.0' encoding='UTF-8'?>
147145
<testsuites tests="1" failures="0" errors="0" skipped="0" time="...">

example/androidlib/java/2-app-bundle/bundle/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0">
2-
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="35"/>
32
<application android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true">
43
<activity android:name=".MainActivity"
54
android:exported="true">

example/androidlib/java/3-linting/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0">
2-
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="35"/>
32
<application android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true">
43
<activity android:name=".MainActivity"
54
android:exported="true">

example/androidlib/java/3-linting/build.mill

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ lint.xml
6767
src
6868

6969
> cat out/app/androidLintRun.dest/report.txt # Display content of the linting report
70-
AndroidManifest.xml:3: ...Error: Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one [HardcodedDebugMode]
70+
AndroidManifest.xml:2: ...Error: Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one [HardcodedDebugMode]
7171

7272
> sed -i.bak 's/ android:debuggable="true"//g' app/src/main/AndroidManifest.xml # Fix the HardcodedDebugMode warning issue from `AndroidManifest.xml`
7373

@@ -91,7 +91,7 @@ AndroidManifest.xml:3: ...Error: Avoid hardcoding the debug mode; leaving it out
9191
> ./mill app.androidLintRun # Rerun it for new changes to reflect
9292

9393
> cat out/app/androidLintRun.dest/report.txt # Output the changes in the report
94-
AndroidManifest.xml:3: ...Warning: Should explicitly set android:icon, there is no default [MissingApplicationIcon]
94+
AndroidManifest.xml:2: ...Warning: Should explicitly set android:icon, there is no default [MissingApplicationIcon]
9595

9696
> sed -i.bak 's/severity="warning"/severity="ignore"/g' app/lint.xml # Revert the severity level of `MissingApplicationIcon`
9797

example/androidlib/java/4-sum-lib-java/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0">
3-
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="35"/>
43
<application android:label="Calculator" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true">
54
<activity android:name=".Main"
65
android:exported="true">

example/androidlib/java/4-sum-lib-java/build.mill

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ object lib extends AndroidLibModule with PublishModule {
2828
def androidMinSdk = 19
2929
def androidCompileSdk = 35
3030

31+
def androidLibPackage = "com.example"
32+
3133
def publishVersion = "0.0.1"
3234
def pomSettings = PomSettings(
3335
description = "sumlib",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example" android:versionCode="1" android:versionName="1.0">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0">
33

44
</manifest>
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.helloworld.app" android:versionCode="1" android:versionName="1.0">
2-
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="35"/>
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0">
32
<application android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true">
43
<activity android:name=".MainActivity"
54
android:exported="true">
@@ -9,7 +8,4 @@
98
</intent-filter>
109
</activity>
1110
</application>
12-
<instrumentation
13-
android:name="androidx.test.runner.AndroidJUnitRunner"
14-
android:targetPackage="com.helloworld.app" />
1511
</manifest>

example/androidlib/java/5-R8/app/test-proguard-rules.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Keep all annotation metadata (needed for reflection-based test frameworks)
1010
-keepattributes *Annotation*
1111

12+
-keep class com.helloworld.app.** { *; }
1213
# Keep all Espresso framework classes and specifically ensure that the idling resources aren’t stripped
1314
-keep class androidx.test.espresso.** { *; }
1415
-keep class androidx.test.espresso.IdlingRegistry { *; }

0 commit comments

Comments
 (0)