diff --git a/example/androidlib/java/1-hello-world/build.mill b/example/androidlib/java/1-hello-world/build.mill index 3d6a9be7d269..6a651f95bdf6 100644 --- a/example/androidlib/java/1-hello-world/build.mill +++ b/example/androidlib/java/1-hello-world/build.mill @@ -99,7 +99,7 @@ object app extends AndroidAppModule { /** Usage > ./mill show app.test -...compiling 1 Java source... +...compiling 2 Java sources to out/app/test/compile.dest/classes... > cat out/app/test/testForked.dest/out.json ["",[{"fullyQualifiedName":"com.helloworld.ExampleUnitTest.textSize_isCorrect","selector":"com.helloworld.ExampleUnitTest.textSize_isCorrect","duration":...,"status":"Success"}]] diff --git a/libs/androidlib/src/mill/androidlib/AndroidAppModule.scala b/libs/androidlib/src/mill/androidlib/AndroidAppModule.scala index 5bab22d92083..12ed9a347167 100644 --- a/libs/androidlib/src/mill/androidlib/AndroidAppModule.scala +++ b/libs/androidlib/src/mill/androidlib/AndroidAppModule.scala @@ -235,6 +235,10 @@ trait AndroidAppModule extends AndroidModule { outer => ) } + override def androidAaptNonFinalIds: T[Boolean] = Task { + false + } + /** * Regex patterns of files to be excluded from packaging into the APK. */ diff --git a/libs/androidlib/src/mill/androidlib/AndroidModule.scala b/libs/androidlib/src/mill/androidlib/AndroidModule.scala index e8e426a0f337..17eae993e6b0 100644 --- a/libs/androidlib/src/mill/androidlib/AndroidModule.scala +++ b/libs/androidlib/src/mill/androidlib/AndroidModule.scala @@ -128,20 +128,44 @@ trait AndroidModule extends JavaModule { outer => def androidVersionCode: T[Int] = 1 /** - * Specifies AAPT options for Android resource compilation. + * Specifies AAPT options for Android resource linking. */ def androidAaptOptions: T[Seq[String]] = Task { - if (androidIsDebug()) { - Seq( - "--proguard-minimal-keep-rules", - "--debug-mode", - "--auto-add-overlay" - ) - } else { - Seq("--auto-add-overlay") + val debugOptions = Seq( + "--proguard-minimal-keep-rules", + "--debug-mode" + ) + + val extraPackages = androidAaptLinkExtraPackages().flatMap(ns => Seq("--extra-packages", ns)) + + Seq( + "--auto-add-overlay", + "--no-version-vectors", + "--no-proguard-location-reference" + ) ++ extraPackages + ++ Option.when(androidAaptNonFinalIds())(Seq("--non-final-ids")).toSeq.flatten + ++ Option.when(androidIsDebug())(debugOptions).toSeq.flatten + } + + /** + * Collect the namespaces from the Android module dependencies to be + * passed to AAPT during resource linking. + */ + def androidAaptLinkExtraPackages: T[Seq[String]] = Task { + // TODO: cleanup once we properly pass resources from dependencies + recursiveModuleDeps.collect { + case p: AndroidModule => p.androidNamespace } } + /** + * Sets whether resource IDs generated by AAPT should be non-final. + * Default is true for non-app modules. + */ + def androidAaptNonFinalIds: T[Boolean] = Task { + true + } + def androidProviderProguardConfigRules: T[Seq[String]] = Task { val androidNs = "http://schemas.android.com/apk/res/android" val manifest = androidMergedManifest().path @@ -487,7 +511,8 @@ trait AndroidModule extends JavaModule { outer => // * it will generate R.java for the library even library has no resources declared // * R.java will have not only resource ID from this library, but from other libraries as well. They should be stripped. val rClassDir = androidLinkedResources().path / "generatedSources/java" - val mainRClassPath = os.walk(rClassDir) + val rSources = os.walk(rClassDir).filter(p => os.isFile(p) && p.ext == "java") + val mainRClassPath = rSources .find(_.last == "R.java") .get @@ -508,7 +533,7 @@ trait AndroidModule extends JavaModule { outer => ) } yield PathRef(libRClassPath) - libClasses :+ PathRef(mainRClassPath) + libClasses ++ rSources.map(PathRef(_)) } /** diff --git a/libs/androidlib/src/mill/androidlib/hilt/AndroidHiltSupport.scala b/libs/androidlib/src/mill/androidlib/hilt/AndroidHiltSupport.scala index 506dee24e9d7..6fa1f1072cd5 100644 --- a/libs/androidlib/src/mill/androidlib/hilt/AndroidHiltSupport.scala +++ b/libs/androidlib/src/mill/androidlib/hilt/AndroidHiltSupport.scala @@ -24,6 +24,11 @@ import mill.{T, Task} @mill.api.experimental trait AndroidHiltSupport extends KspModule, AndroidKotlinModule { + // Dagger does not work with the bt api + override def kotlincUseBtApi: T[Boolean] = Task { + false + } + override def kspProcessorOptions: T[Map[String, String]] = Task { super.kspProcessorOptions() ++ Map( "dagger.fastInit" -> "enabled",