Provide min sdk version as ApiLevel instead of string.
Bug: 377723687
Test: Unit tests and compare the ninja and mk files generated.
Change-Id: I8c7b3b493877a9857ca433b015e6e49ad8387f91
diff --git a/android/module.go b/android/module.go
index 3295e93..87ff273 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1898,7 +1898,7 @@
SkipAndroidMkProcessing bool
BaseModuleName string
CanHaveApexVariants bool
- MinSdkVersion string
+ MinSdkVersion ApiLevelOrPlatform
SdkVersion string
NotAvailableForPlatform bool
// There some subtle differences between this one and the one above.
@@ -1914,6 +1914,11 @@
Host bool
}
+type ApiLevelOrPlatform struct {
+ ApiLevel *ApiLevel
+ IsPlatform bool
+}
+
var CommonModuleInfoKey = blueprint.NewProvider[CommonModuleInfo]()
type PrebuiltModuleInfo struct {
@@ -2255,11 +2260,16 @@
MinSdkVersion(ctx EarlyModuleContext) ApiLevel
}); ok {
ver := mm.MinSdkVersion(ctx)
- if !ver.IsNone() {
- commonData.MinSdkVersion = ver.String()
- }
+ commonData.MinSdkVersion.ApiLevel = &ver
} else if mm, ok := m.module.(interface{ MinSdkVersion() string }); ok {
- commonData.MinSdkVersion = mm.MinSdkVersion()
+ ver := mm.MinSdkVersion()
+ // Compile against the current platform
+ if ver == "" {
+ commonData.MinSdkVersion.IsPlatform = true
+ } else {
+ api := ApiLevelFrom(ctx, ver)
+ commonData.MinSdkVersion.ApiLevel = &api
+ }
}
if mm, ok := m.module.(interface {
diff --git a/apex/builder.go b/apex/builder.go
index 03a0bb9..8427719 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -1132,10 +1132,9 @@
depInfos[to.Name()] = info
} else {
toMinSdkVersion := "(no version)"
- if info, ok := android.OtherModuleProvider(ctx, to, android.CommonModuleInfoKey); ok {
- if v := info.MinSdkVersion; v != "" {
- toMinSdkVersion = v
- }
+ if info, ok := android.OtherModuleProvider(ctx, to, android.CommonModuleInfoKey); ok &&
+ !info.MinSdkVersion.IsPlatform && info.MinSdkVersion.ApiLevel != nil {
+ toMinSdkVersion = info.MinSdkVersion.ApiLevel.String()
}
depInfos[to.Name()] = android.ApexModuleDepInfo{
To: to.Name(),
diff --git a/java/app.go b/java/app.go
index abbf034..9895f47 100644
--- a/java/app.go
+++ b/java/app.go
@@ -512,10 +512,14 @@
// The domain of cc.sdk_version is "current" and <number>
// We can rely on android.SdkSpec to convert it to <number> so that "current" is
// handled properly regardless of sdk finalization.
- jniSdkVersion, err := android.SdkSpecFrom(ctx, commonInfo.MinSdkVersion).EffectiveVersion(ctx)
+ ver := ""
+ if !commonInfo.MinSdkVersion.IsPlatform {
+ ver = commonInfo.MinSdkVersion.ApiLevel.String()
+ }
+ jniSdkVersion, err := android.SdkSpecFrom(ctx, ver).EffectiveVersion(ctx)
if err != nil || minSdkVersion.LessThan(jniSdkVersion) {
ctx.OtherModuleErrorf(m, "min_sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)",
- commonInfo.MinSdkVersion, minSdkVersion, ctx.ModuleName())
+ ver, minSdkVersion, ctx.ModuleName())
return
}