Skip to content

Android/cleanup app release install #4996

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 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">
Expand All @@ -9,7 +8,4 @@
</intent-filter>
</activity>
</application>
<instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.helloworld.app" />
</manifest>
4 changes: 1 addition & 3 deletions example/androidlib/java/1-hello-world/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ object app extends AndroidAppModule {

def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)

override def instrumentationPackage = "com.helloworld.app"

/* TODO currently the dependency resolution ignores the platform type and kotlinx-coroutines-core has
* conflicting classes with kotlinx-coroutines-core-jvm . Remove the exclusions once the dependency
* resolution resolves conflicts between androidJvm and jvm platform types
Expand Down Expand Up @@ -141,7 +139,7 @@ object app extends AndroidAppModule {
]
...

> cat out/app/it/testTask.dest/test-report.xml
> cat out/app/it/testForked.dest/test-report.xml
...
<?xml version='1.0' encoding='UTF-8'?>
<testsuites tests="1" failures="0" errors="0" skipped="0" time="...">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 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">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 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">
Expand Down
4 changes: 2 additions & 2 deletions example/androidlib/java/3-linting/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ lint.xml
src

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="35"/>
<application android:label="Calculator" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true">
<activity android:name=".Main"
android:exported="true">
Expand Down
2 changes: 2 additions & 0 deletions example/androidlib/java/4-sum-lib-java/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ object lib extends AndroidLibModule with PublishModule {
def androidMinSdk = 19
def androidCompileSdk = 35

def androidLibPackage = "com.example"

def publishVersion = "0.0.1"
def pomSettings = PomSettings(
description = "sumlib",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example" android:versionCode="1" android:versionName="1.0">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<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"/>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0">
<application android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true">
<activity android:name=".MainActivity"
android:exported="true">
Expand All @@ -9,7 +8,4 @@
</intent-filter>
</activity>
</application>
<instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.helloworld.app" />
</manifest>
1 change: 1 addition & 0 deletions example/androidlib/java/5-R8/app/test-proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Keep all annotation metadata (needed for reflection-based test frameworks)
-keepattributes *Annotation*

-keep class com.helloworld.app.** { *; }
# Keep all Espresso framework classes and specifically ensure that the idling resources aren’t stripped
-keep class androidx.test.espresso.** { *; }
-keep class androidx.test.espresso.IdlingRegistry { *; }
Expand Down
42 changes: 36 additions & 6 deletions example/androidlib/java/5-R8/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ object app extends AndroidAppModule { // <2>
def androidReleaseKeyStorePass: T[Option[String]] = Task { Some("MillBuildTool") }

override def androidVirtualDeviceIdentifier: String = "java-test"
override def androidIsDebug: T[Boolean] = Task { false }

override def androidReleaseSettings: T[AndroidBuildTypeSettings] = Task {
super.androidReleaseSettings().withProguardLocalFiles(
Seq(
moduleDir / "proguard-rules.pro"
)
)
}

// Unit tests for the application
object test extends AndroidAppTests with TestModule.Junit4 {
Expand All @@ -54,7 +63,14 @@ object app extends AndroidAppModule { // <2>
// Instrumented tests (runs on emulator)
object it extends AndroidAppInstrumentedTests with AndroidTestModule.AndroidJUnit {
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)
override def instrumentationPackage = "com.helloworld.app"

override def androidIsDebug: T[Boolean] = Task {
false
}

override def androidReleaseSettings: T[AndroidBuildTypeSettings] = Task {
AndroidBuildTypeSettings(isMinifyEnabled = false)
}

/* TODO currently the dependency resolution ignores the platform type and kotlinx-coroutines-core has
* conflicting classes with kotlinx-coroutines-core-jvm . Remove the exclusions once the dependency
Expand All @@ -80,25 +96,39 @@ object app extends AndroidAppModule { // <2>
/** Usage

> ./mill show app.androidApk
".../out/app/androidApk.dest/app.apk"

> ./mill show app.createAndroidVirtualDevice
...Name: java-test, DeviceId: medium_phone...

> ./mill show app.startAndroidEmulator

> ./mill show app.androidReleaseInstall
> ./mill show app.androidInstall
...All files should be loaded. Notifying the device...

> ./mill show app.it
...
[
"",
[
{
"fullyQualifiedName": "com.helloworld.app.ExampleInstrumentedTest.useAppContext",
"selector": "com.helloworld.app.ExampleInstrumentedTest.useAppContext",
"duration": ...,
"status": "Success"
}
]
]


> ./mill show app.stopAndroidEmulator

> ./mill show app.deleteAndroidVirtualDevice

*/

// R8 will run automatically when you run the `androidReleaseInstall` task.
// If you want to create the APK without R8, you can use the `androidApk` task to create the not-optimized APK. You can also
// R8 will run automatically when you run the `androidInstall` task with androidIsDebug set to false.
// If you want to create the APK without R8, you can set the androidReleaseSettings isMinifyEnabled to false. You can also
// run the `andoidInstall` task that will automaticaly run the `androidApk` and also install it in the emulator.
// The `androidReleaseInstall` task will install the optimized APK on the emulator.
// The release settings used in `androidInstall` task will install the optimized APK on the emulator.
// So first you need to create the emulator and start it.
// After the emulator is started, you can run the `androidReleaseInstall` task and see the app in the emulator.
10 changes: 4 additions & 6 deletions example/androidlib/kotlin/1-hello-kotlin/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# Suppress warnings
-ignorewarnings

# If you keep the line number information, uncomment this to
# hide the original source file name.
-renamesourcefileattribute SourceFilex
# Keep all annotation metadata (needed for reflection-based test frameworks)
-keepattributes *Annotation*

-keep class com.helloworld.** { *; }
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 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">
Expand All @@ -9,8 +8,4 @@
</intent-filter>
</activity>
</application>
<!-- TODO this needs to be constructed by Mill's integration tests (android tests) -->
<instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.helloworld.app" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

# Keep all Espresso framework classes and specifically ensure that the idling resources aren’t stripped
-keep class androidx.test.espresso.** { *; }
-keep class androidx.test.** { *; }
-keep class androidx.test.espresso.IdlingRegistry { *; }
-keep class androidx.test.espresso.IdlingResource { *; }

Expand Down
39 changes: 25 additions & 14 deletions example/androidlib/kotlin/1-hello-kotlin/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,36 @@ object app extends AndroidAppKotlinModule {
override def androidVirtualDeviceIdentifier: String = "kotlin-test"
override def androidEmulatorPort: String = "5556"

override def androidIsDebug: T[Boolean] = Task { false }

override def androidReleaseSettings: T[AndroidBuildTypeSettings] = Task {
super.androidReleaseSettings()
.withDefaultProguardFile("proguard-android.txt")
.withProguardLocalFiles(
Seq(
moduleDir / "proguard-rules.pro"
)
)
}

object test extends AndroidAppKotlinTests with TestModule.Junit4 {
def junit4Version = "4.13.2"
}

object it extends AndroidAppKotlinInstrumentedTests with AndroidTestModule.AndroidJUnit {

override def instrumentationPackage = "com.helloworld.app"
// TODO currently instrumented tests debug mode
// is coupled with the app debug mode. Fix so
// that instrumented tests can be built with debug
// configuration but the apk signature will match
// the app apk
override def androidIsDebug: T[Boolean] = Task {
false
}

override def androidReleaseSettings: T[AndroidBuildTypeSettings] = Task {
AndroidBuildTypeSettings(isMinifyEnabled = false)
}

/* TODO currently the dependency resolution ignores the platform type and kotlinx-coroutines-core has
* conflicting classes with kotlinx-coroutines-core-jvm . Remove the exclusions once the dependency
Expand Down Expand Up @@ -75,18 +98,6 @@ object app extends AndroidAppKotlinModule {
> ./mill show app.androidApk
".../out/app/androidApk.dest/app.apk"

> ./mill show app.createAndroidVirtualDevice
...Name: kotlin-test, DeviceId: medium_phone...

> ./mill show app.startAndroidEmulator

> ./mill show app.androidReleaseInstall
...All files should be loaded. Notifying the device...

> ./mill show app.stopAndroidEmulator

> ./mill show app.deleteAndroidVirtualDevice

*/

// This command triggers the build process, which installs the Android Setup, compiles the kotlin
Expand Down Expand Up @@ -156,7 +167,7 @@ object app extends AndroidAppKotlinModule {
]
...

> cat out/app/it/testTask.dest/test-report.xml
> cat out/app/it/testForked.dest/test-report.xml
...
<?xml version='1.0' encoding='UTF-8'?>
<testsuites tests="1" failures="0" errors="0" skipped="0" time="...">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Adopted from AGP screenshot test template, a sample can be found in-->
<!-- https://github.com/vaslabs-ltd/android-screenshot-test-sample/blob/main/app/src/main/AndroidManifest.xml-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.screenshottest">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 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">
Expand Down
2 changes: 2 additions & 0 deletions example/androidlib/kotlin/4-sum-lib-kotlin/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ object lib extends AndroidLibKotlinModule with PublishModule {
def androidCompileSdk = 35
def kotlinVersion = "2.0.20"

def androidLibPackage = "com.example"

def publishVersion = "0.0.1"
def pomSettings = PomSettings(
description = "sumlib",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example" android:versionCode="1" android:versionName="1.0">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0">

</manifest>
7 changes: 3 additions & 4 deletions example/thirdparty/androidtodo/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ object app extends AndroidAppKotlinModule with AndroidBuildConfig with AndroidHi
)
}

object androidTest extends AndroidAppKotlinInstrumentedTests with AndroidTestModule.AndroidJUnit {
override def instrumentationPackage = "com.example.android"

}
// TODO support instrumented tests on Hilt setups
object androidTest extends AndroidAppKotlinInstrumentedTests
with AndroidTestModule.AndroidJUnit {}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ trait AndroidAppKotlinModule extends AndroidAppModule with AndroidKotlinModule {

override def androidCompileSdk: T[Int] = outer.androidCompileSdk()

override def androidMergedManifest: T[PathRef] = outer.androidMergedManifest()

override def androidSdkModule: ModuleRef[AndroidSdkModule] = outer.androidSdkModule

// FIXME: avoid hardcoded version
Expand Down
Loading
Loading