Set targetSdkVersion to 10000 iff a module is targeting an unreleased
sdk Previously in aosp/1907152, targetSdkVersion for all modules would be 10000 in release builds. This would cause sdk compatibility errors like b/209301265#3 for modules that were targeting a released SDK This CL adds an additional check to set targetSdkVersion to 10000 only if a module's apilevel is in preview (i.e. unreleased SDK) Bug: 209301265 Test: Built various apk combinations locally, and used aapt2 to check targetSdkVersion Test: TARGET_BUILD_APPS=xyz m CaptivePortalLoginTests # targetSdkVersion: 30 Test: m CaptivePortalLoginTests #targetSdkVersion: 30 Test: (internal) TARGET_BUILD_APPS=xyz m MediaProviderGoogle # targetSdkVersion: 10000 Test: (internal) m MediaProviderGoogle #targetSdkVersion: Tiramisu Change-Id: Id2901f23d4e1b436f8906940e47edd606a93657d
This commit is contained in:
@@ -16,6 +16,7 @@ package java
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
@@ -42,6 +43,21 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
|
||||
},
|
||||
"args", "libs")
|
||||
|
||||
// targetSdkVersion for manifest_fixer
|
||||
// When TARGET_BUILD_APPS is not empty, this method returns 10000 for modules targeting an unreleased SDK
|
||||
// This enables release builds (that run with TARGET_BUILD_APPS=[val...]) to target APIs that have not yet been finalized as part of an SDK
|
||||
func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext android.SdkContext) string {
|
||||
targetSdkVersionSpec := sdkContext.TargetSdkVersion(ctx)
|
||||
if ctx.Config().UnbundledBuildApps() && targetSdkVersionSpec.ApiLevel.IsPreview() {
|
||||
return strconv.Itoa(android.FutureApiLevel.FinalOrFutureInt())
|
||||
}
|
||||
targetSdkVersion, err := targetSdkVersionSpec.EffectiveVersionString(ctx)
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf("invalid targetSdkVersion: %s", err)
|
||||
}
|
||||
return targetSdkVersion
|
||||
}
|
||||
|
||||
// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
|
||||
func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext android.SdkContext,
|
||||
classLoaderContexts dexpreopt.ClassLoaderContextMap, isLibrary, useEmbeddedNativeLibs, usesNonSdkApis,
|
||||
@@ -89,10 +105,8 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
|
||||
args = append(args, "--logging-parent", loggingParent)
|
||||
}
|
||||
var deps android.Paths
|
||||
targetSdkVersion, err := sdkContext.TargetSdkVersion(ctx).EffectiveVersionString(ctx)
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf("invalid targetSdkVersion: %s", err)
|
||||
}
|
||||
targetSdkVersion := targetSdkVersionForManifestFixer(ctx, sdkContext)
|
||||
|
||||
if UseApiFingerprint(ctx) && ctx.ModuleName() != "framework-res" {
|
||||
targetSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", ApiFingerprintPath(ctx).String())
|
||||
deps = append(deps, ApiFingerprintPath(ctx))
|
||||
|
Reference in New Issue
Block a user