diff --git a/java/aar.go b/java/aar.go index 2ad8fdff4..eb07e0fb2 100644 --- a/java/aar.go +++ b/java/aar.go @@ -544,7 +544,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio if a.useResourceProcessorBusyBox() { rJar := android.PathForModuleOut(ctx, "busybox/R.jar") - resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary) + resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary, a.aaptProperties.Aaptflags) aapt2ExtractExtraPackages(ctx, extraPackages, rJar) transitiveRJars = append(transitiveRJars, rJar) a.rJar = rJar @@ -604,7 +604,7 @@ var resourceProcessorBusyBox = pctx.AndroidStaticRule("resourceProcessorBusyBox" // using Bazel's ResourceProcessorBusyBox tool, which is faster than compiling the R.java files and // supports producing classes for static dependencies that only include resources from that dependency. func resourceProcessorBusyBoxGenerateBinaryR(ctx android.ModuleContext, rTxt, manifest android.Path, - rJar android.WritablePath, transitiveDeps transitiveAarDeps, isLibrary bool) { + rJar android.WritablePath, transitiveDeps transitiveAarDeps, isLibrary bool, aaptFlags []string) { var args []string var deps android.Paths @@ -621,6 +621,17 @@ func resourceProcessorBusyBoxGenerateBinaryR(ctx android.ModuleContext, rTxt, ma args = append(args, "--finalFields=false") } + for i, arg := range aaptFlags { + const AAPT_CUSTOM_PACKAGE = "--custom-package" + if strings.HasPrefix(arg, AAPT_CUSTOM_PACKAGE) { + pkg := strings.TrimSpace(strings.TrimPrefix(arg, AAPT_CUSTOM_PACKAGE)) + if pkg == "" && i+1 < len(aaptFlags) { + pkg = aaptFlags[i+1] + } + args = append(args, "--packageForR "+pkg) + } + } + deps = append(deps, rTxt, manifest) ctx.Build(pctx, android.BuildParams{ @@ -1194,7 +1205,7 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil, nil) a.rJar = android.PathForModuleOut(ctx, "busybox/R.jar") - resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true) + resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true, nil) aapt2ExtractExtraPackages(ctx, a.extraAaptPackagesFile, a.rJar)