Set targetSdkVersion in manifest_fixer
If targetSdkVersion is not set in the manifest, set it to the
value it was implicitly using before changing minSdkVersion.
Requires passing --library to manifest_fixer.py to distinguish
between apps, where the implicit value was set by aapt2 to
current, or libraries where the implicit value was 1.
Fixes cases where the manifest does not specify targetSdkVersion
and was inheriting the minSdkVersion value until manifest merger
started merging a lower targetSdkVersion value from a library.
Bug: 111347801
Test: manifest_fixer_test.py
Change-Id: I8fcf0c5f452707565ba1808f6fe552ffed055c47
diff --git a/java/android_manifest.go b/java/android_manifest.go
index 8fcdcba..77b6214 100644
--- a/java/android_manifest.go
+++ b/java/android_manifest.go
@@ -16,6 +16,7 @@
import (
"android/soong/java/config"
+ "strings"
"github.com/google/blueprint"
@@ -24,10 +25,10 @@
var manifestFixerRule = pctx.AndroidStaticRule("manifestFixer",
blueprint.RuleParams{
- Command: `${config.ManifestFixerCmd} --minSdkVersion ${minSdkVersion} $usesLibraries $in $out`,
+ Command: `${config.ManifestFixerCmd} --minSdkVersion ${minSdkVersion} $args $in $out`,
CommandDeps: []string{"${config.ManifestFixerCmd}"},
},
- "minSdkVersion", "usesLibraries")
+ "minSdkVersion", "args")
var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
blueprint.RuleParams{
@@ -38,7 +39,12 @@
"libs")
func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
- staticLibManifests android.Paths) android.Path {
+ staticLibManifests android.Paths, isLibrary bool) android.Path {
+
+ var args []string
+ if isLibrary {
+ args = append(args, "--library")
+ }
// Inject minSdkVersion into the manifest
fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml")
@@ -48,6 +54,7 @@
Output: fixedManifest,
Args: map[string]string{
"minSdkVersion": sdkVersionOrDefault(ctx, sdkContext.minSdkVersion()),
+ "args": strings.Join(args, " "),
},
})
manifest = fixedManifest