Reverse order of transitive R.jar classpath entries
Reverse the order of transitive R.jar classpath entries so that
the R.jar from the current module comes first, and so that R.jar
from any direct dependency comes before the R.jar of any transitive
dependencies through the direct dependency. Also swap the order of
shared and static dependencies so that static dependencies come first
in the final classpath.
Bug: 294256649
Test: m javac-check
Test: TestAndroidResourceProcessor
Change-Id: Id9ea5b53ca563f79d0a25fb52b24552dbea70605
diff --git a/java/aar.go b/java/aar.go
index 7cb362a..54fca81 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -453,6 +453,11 @@
// as imports. The resources from dependencies will not be merged into this module's package-res.apk, and
// instead modules depending on this module will reference package-res.apk from all transitive static
// dependencies.
+ for _, sharedDep := range sharedDeps {
+ if sharedDep.usedResourceProcessor {
+ transitiveRJars = append(transitiveRJars, sharedDep.rJar)
+ }
+ }
for _, staticDep := range staticDeps {
linkDeps = append(linkDeps, staticDep.resPackage)
linkFlags = append(linkFlags, "-I "+staticDep.resPackage.String())
@@ -460,11 +465,6 @@
transitiveRJars = append(transitiveRJars, staticDep.rJar)
}
}
- for _, sharedDep := range sharedDeps {
- if sharedDep.usedResourceProcessor {
- transitiveRJars = append(transitiveRJars, sharedDep.rJar)
- }
- }
} else {
// When building an app or building a library without ResourceProcessorBusyBox enabled all static
// dependencies are compiled into this module's package-res.apk as overlays.
@@ -554,6 +554,10 @@
transitiveAaptResourcePackagesFile := android.PathForModuleOut(ctx, "transitive-res-packages")
android.WriteFileRule(ctx, transitiveAaptResourcePackagesFile, strings.Join(transitiveAaptResourcePackages, "\n"))
+ // Reverse the list of R.jar files so that the current module comes first, and direct dependencies come before
+ // transitive dependencies.
+ transitiveRJars = android.ReversePaths(transitiveRJars)
+
a.aaptSrcJar = srcJar
a.transitiveAaptRJars = transitiveRJars
a.transitiveAaptResourcePackagesFile = transitiveAaptResourcePackagesFile