Don't generate aapt2 srcjars when using resource processor
When using resource processor the R.class files are generated
directly, and the R.java files generated by aapt2 are unused. These
files can huge, reaching 500 MB for some modules and 76 GB across
all modules for a checkbuild on internal main. They will be deleted
after zipping into srcjars after Ie5143e1e4b36ca1f4e45b001d79aca5379063517,
but we can skip generating them completely for modules where resource
processor is used.
Bug: 284023594
Bug: 294285775
Test: m checkbuild
Change-Id: If5e3fd1d25c6c7860898776ecdd392be8850c17c
diff --git a/java/aar.go b/java/aar.go
index 180e1d7..d1a7ed7 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -376,13 +376,12 @@
}
packageRes := android.PathForModuleOut(ctx, "package-res.apk")
- // the subdir "android" is required to be filtered by package names
- srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
rTxt := android.PathForModuleOut(ctx, "R.txt")
// This file isn't used by Soong, but is generated for exporting
extraPackages := android.PathForModuleOut(ctx, "extra_packages")
var transitiveRJars android.Paths
+ var srcJar android.WritablePath
var compiledResDirs []android.Paths
for _, dir := range resDirs {
@@ -459,15 +458,19 @@
})
}
+ if !a.useResourceProcessorBusyBox() {
+ // the subdir "android" is required to be filtered by package names
+ srcJar = android.PathForModuleGen(ctx, "android", "R.srcjar")
+ }
+
// No need to specify assets from dependencies to aapt2Link for libraries, all transitive assets will be
// provided to the final app aapt2Link step.
var transitiveAssets android.Paths
if !a.isLibrary {
transitiveAssets = android.ReverseSliceInPlace(staticDeps.assets())
}
- aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, extraPackages,
+ aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt,
linkFlags, linkDeps, compiledRes, compiledOverlay, transitiveAssets, splitPackages)
-
// Extract assets from the resource package output so that they can be used later in aapt2link
// for modules that depend on this one.
if android.PrefixInList(linkFlags, "-A ") {
@@ -484,8 +487,11 @@
if a.useResourceProcessorBusyBox() {
rJar := android.PathForModuleOut(ctx, "busybox/R.jar")
resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary)
+ aapt2ExtractExtraPackages(ctx, extraPackages, rJar)
transitiveRJars = append(transitiveRJars, rJar)
a.rJar = rJar
+ } else {
+ aapt2ExtractExtraPackages(ctx, extraPackages, srcJar)
}
a.aaptSrcJar = srcJar
@@ -731,9 +737,10 @@
ctx.CheckbuildFile(a.aapt.proguardOptionsFile)
ctx.CheckbuildFile(a.aapt.exportPackage)
- ctx.CheckbuildFile(a.aapt.aaptSrcJar)
if a.useResourceProcessorBusyBox() {
ctx.CheckbuildFile(a.aapt.rJar)
+ } else {
+ ctx.CheckbuildFile(a.aapt.aaptSrcJar)
}
// apps manifests are handled by aapt, don't let Module see them
@@ -1063,8 +1070,6 @@
aapt2CompileZip(ctx, flata, a.aarPath, "res", compileFlags)
a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk")
- // the subdir "android" is required to be filtered by package names
- srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
a.rTxt = android.PathForModuleOut(ctx, "R.txt")
a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages")
@@ -1100,12 +1105,14 @@
}
transitiveAssets := android.ReverseSliceInPlace(staticDeps.assets())
- aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, a.rTxt, a.extraAaptPackagesFile,
+ aapt2Link(ctx, a.exportPackage, nil, proguardOptionsFile, a.rTxt,
linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil)
a.rJar = android.PathForModuleOut(ctx, "busybox/R.jar")
resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true)
+ aapt2ExtractExtraPackages(ctx, a.extraAaptPackagesFile, a.rJar)
+
resourcesNodesDepSetBuilder := android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL)
resourcesNodesDepSetBuilder.Direct(&resourcesNode{
resPackage: a.exportPackage,