Put shared library R.jar files in the classpath
When building with use_resource_processor: true R.jar files from
shared andoid_library dependencies need to be added to the classpath
so that the generated R classes can be referenced.
Bug: 294256649
Test: m DocumentsUIPerfTests
Change-Id: I30a6bddc3f378ecf58f142f94049e67ba33a47e3
diff --git a/java/aar.go b/java/aar.go
index e53653a..85a6fbb 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -311,7 +311,7 @@
func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptions) {
- staticResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedDeps, libFlags :=
+ staticResourcesNodesDepSet, sharedResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedExportPackages, libFlags :=
aaptLibs(ctx, opts.sdkContext, opts.classLoaderContexts)
// Exclude any libraries from the supplied list.
@@ -335,6 +335,7 @@
})
staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList())
+ sharedDeps := transitiveAarDeps(sharedResourcesNodesDepSet.ToList())
// Add additional manifest files to transitive manifests.
additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests)
@@ -364,7 +365,7 @@
compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, opts.sdkContext, manifestPath)
linkFlags = append(linkFlags, libFlags...)
- linkDeps = append(linkDeps, sharedDeps...)
+ linkDeps = append(linkDeps, sharedExportPackages...)
linkDeps = append(linkDeps, staticDeps.resPackages()...)
linkFlags = append(linkFlags, opts.extraLinkFlags...)
if a.isLibrary {
@@ -422,6 +423,11 @@
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.
@@ -630,7 +636,7 @@
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, classLoaderContexts dexpreopt.ClassLoaderContextMap) (
- staticResourcesNodes *android.DepSet[*resourcesNode], staticRRODirs *android.DepSet[rroDir],
+ staticResourcesNodes, sharedResourcesNodes *android.DepSet[*resourcesNode], staticRRODirs *android.DepSet[rroDir],
staticManifests *android.DepSet[android.Path], sharedLibs android.Paths, flags []string) {
if classLoaderContexts == nil {
@@ -644,7 +650,8 @@
sharedLibs = append(sharedLibs, sdkDep.jars...)
}
- var resourcesNodeDepSets []*android.DepSet[*resourcesNode]
+ var staticResourcesNodeDepSets []*android.DepSet[*resourcesNode]
+ var sharedResourcesNodeDepSets []*android.DepSet[*resourcesNode]
rroDirsDepSetBuilder := android.NewDepSetBuilder[rroDir](android.TOPOLOGICAL)
manifestsDepSetBuilder := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL)
@@ -662,6 +669,7 @@
// Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2.
case sdkLibTag, libTag:
if exportPackage != nil {
+ sharedResourcesNodeDepSets = append(sharedResourcesNodeDepSets, aarDep.ResourcesNodeDepSet())
sharedLibs = append(sharedLibs, exportPackage)
}
case frameworkResTag:
@@ -670,7 +678,7 @@
}
case staticLibTag:
if exportPackage != nil {
- resourcesNodeDepSets = append(resourcesNodeDepSets, aarDep.ResourcesNodeDepSet())
+ staticResourcesNodeDepSets = append(staticResourcesNodeDepSets, aarDep.ResourcesNodeDepSet())
rroDirsDepSetBuilder.Transitive(aarDep.RRODirsDepSet())
manifestsDepSetBuilder.Transitive(aarDep.ManifestsDepSet())
}
@@ -686,7 +694,9 @@
// dependencies) the highest priority dependency is listed first, but for resources the highest priority
// dependency has to be listed last.
staticResourcesNodes = android.NewDepSet(android.TOPOLOGICAL, nil,
- android.ReverseSliceInPlace(resourcesNodeDepSets))
+ android.ReverseSliceInPlace(staticResourcesNodeDepSets))
+ sharedResourcesNodes = android.NewDepSet(android.TOPOLOGICAL, nil,
+ android.ReverseSliceInPlace(sharedResourcesNodeDepSets))
staticRRODirs = rroDirsDepSetBuilder.Build()
staticManifests = manifestsDepSetBuilder.Build()
@@ -699,7 +709,7 @@
flags = append(flags, "-I "+sharedLib.String())
}
- return staticResourcesNodes, staticRRODirs, staticManifests, sharedLibs, flags
+ return staticResourcesNodes, sharedResourcesNodes, staticRRODirs, staticManifests, sharedLibs, flags
}
type AndroidLibrary struct {
@@ -1095,10 +1105,12 @@
linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
linkDeps = append(linkDeps, a.manifest)
- staticResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedLibs, libFlags :=
+ staticResourcesNodesDepSet, sharedResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedLibs, libFlags :=
aaptLibs(ctx, android.SdkContext(a), nil)
+ _ = sharedResourcesNodesDepSet
_ = staticRRODirsDepSet
+
staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList())
linkDeps = append(linkDeps, sharedLibs...)