diff --git a/apex/apex.go b/apex/apex.go index 4247db47a..6afbd4a7c 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -2740,11 +2740,6 @@ func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string { return "" } - archMinApiLevel := cc.MinApiForArch(ctx, a.MultiTargets()[0].Arch.ArchType) - if !archMinApiLevel.IsNone() && archMinApiLevel.CompareTo(minApiLevel) > 0 { - minApiLevel = archMinApiLevel - } - overrideMinSdkValue := ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride() overrideApiLevel := minSdkVersionFromValue(ctx, overrideMinSdkValue) if !overrideApiLevel.IsNone() && overrideApiLevel.CompareTo(minApiLevel) > 0 { diff --git a/apex/apex_test.go b/apex/apex_test.go index e130fccc8..647a575d6 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -2191,6 +2191,38 @@ func TestApexMinSdkVersion_Okay(t *testing.T) { `) } +func TestApexMinSdkVersion_MinApiForArch(t *testing.T) { + // Tests that an apex dependency with min_sdk_version higher than the + // min_sdk_version of the apex is allowed as long as the dependency's + // min_sdk_version is less than or equal to the api level that the + // architecture was introduced in. In this case, arm64 didn't exist + // until api level 21, so the arm64 code will never need to run on + // an api level 20 device, even if other architectures of the apex + // will. + testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + native_shared_libs: ["libfoo"], + min_sdk_version: "20", + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + cc_library { + name: "libfoo", + srcs: ["mylib.cpp"], + apex_available: ["myapex"], + min_sdk_version: "21", + stl: "none", + } + `) +} + func TestJavaStableSdkVersion(t *testing.T) { testCases := []struct { name string diff --git a/cc/api_level.go b/cc/api_level.go index 8f9e1f6bc..fdff5cbcf 100644 --- a/cc/api_level.go +++ b/cc/api_level.go @@ -20,7 +20,7 @@ import ( "android/soong/android" ) -func MinApiForArch(ctx android.EarlyModuleContext, +func minApiForArch(ctx android.EarlyModuleContext, arch android.ArchType) android.ApiLevel { switch arch { @@ -38,7 +38,7 @@ func MinApiForArch(ctx android.EarlyModuleContext, func nativeApiLevelFromUser(ctx android.BaseModuleContext, raw string) (android.ApiLevel, error) { - min := MinApiForArch(ctx, ctx.Arch().ArchType) + min := minApiForArch(ctx, ctx.Arch().ArchType) if raw == "minimum" { return min, nil } diff --git a/cc/cc.go b/cc/cc.go index d0362fcde..eb7c639b3 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -3626,6 +3626,16 @@ func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, return err } + // A dependency only needs to support a min_sdk_version at least + // as high as the api level that the architecture was introduced in. + // This allows introducing new architectures in the platform that + // need to be included in apexes that normally require an older + // min_sdk_version. + minApiForArch := minApiForArch(ctx, c.Target().Arch.ArchType) + if sdkVersion.LessThan(minApiForArch) { + sdkVersion = minApiForArch + } + if ver.GreaterThan(sdkVersion) { return fmt.Errorf("newer SDK(%v)", ver) }