Fix aapt2 --min-sdk-version after finalized SDK
aapt2 --min-sdk-version was using AppsDefaultVersionName(), which is OMR1 for a non-finalized SDK, but 8.1.0 after finalization. Add PlatformSdkCodename() for non-finalized SDKs, use it for DefaultAppTargetSdk(), and pass it for aapt2 --min-sdk-version. Bug: 78224641 Test: TestAppSdkVersion in app_test.go Change-Id: I622eaf92f8a940f79007c2a579536da325700b06
This commit is contained in:
parent
a140bb05f1
commit
d09b0b653b
4 changed files with 109 additions and 1 deletions
|
@ -476,6 +476,10 @@ func (c *config) PlatformSdkVersion() string {
|
|||
return strconv.Itoa(c.PlatformSdkVersionInt())
|
||||
}
|
||||
|
||||
func (c *config) PlatformSdkCodename() string {
|
||||
return String(c.productVariables.Platform_sdk_codename)
|
||||
}
|
||||
|
||||
func (c *config) MinSupportedSdkVersion() int {
|
||||
return 14
|
||||
}
|
||||
|
@ -488,6 +492,14 @@ func (c *config) DefaultAppTargetSdkInt() int {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *config) DefaultAppTargetSdk() string {
|
||||
if Bool(c.productVariables.Platform_sdk_final) {
|
||||
return c.PlatformSdkVersion()
|
||||
} else {
|
||||
return c.PlatformSdkCodename()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *config) AppsDefaultVersionName() string {
|
||||
return String(c.productVariables.AppsDefaultVersionName)
|
||||
}
|
||||
|
|
|
@ -110,6 +110,7 @@ type productVariables struct {
|
|||
DateFromFile *string `json:",omitempty"`
|
||||
|
||||
Platform_sdk_version *int `json:",omitempty"`
|
||||
Platform_sdk_codename *string `json:",omitempty"`
|
||||
Platform_sdk_final *bool `json:",omitempty"`
|
||||
Platform_version_active_codenames []string `json:",omitempty"`
|
||||
Platform_version_future_codenames []string `json:",omitempty"`
|
||||
|
|
|
@ -134,7 +134,7 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkVersion string) (flags [
|
|||
// SDK version flags
|
||||
switch sdkVersion {
|
||||
case "", "current", "system_current", "test_current":
|
||||
sdkVersion = proptools.NinjaEscape([]string{ctx.Config().AppsDefaultVersionName()})[0]
|
||||
sdkVersion = proptools.NinjaEscape([]string{ctx.Config().DefaultAppTargetSdk()})[0]
|
||||
}
|
||||
|
||||
linkFlags = append(linkFlags, "--min-sdk-version "+sdkVersion)
|
||||
|
|
|
@ -16,8 +16,10 @@ package java
|
|||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -240,3 +242,96 @@ func TestEnforceRRO(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppSdkVersion(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
sdkVersion string
|
||||
platformSdkInt int
|
||||
platformSdkCodename string
|
||||
platformSdkFinal bool
|
||||
expectedMinSdkVersion string
|
||||
}{
|
||||
{
|
||||
name: "current final SDK",
|
||||
sdkVersion: "current",
|
||||
platformSdkInt: 27,
|
||||
platformSdkCodename: "REL",
|
||||
platformSdkFinal: true,
|
||||
expectedMinSdkVersion: "27",
|
||||
},
|
||||
{
|
||||
name: "current non-final SDK",
|
||||
sdkVersion: "current",
|
||||
platformSdkInt: 27,
|
||||
platformSdkCodename: "OMR1",
|
||||
platformSdkFinal: false,
|
||||
expectedMinSdkVersion: "OMR1",
|
||||
},
|
||||
{
|
||||
name: "default final SDK",
|
||||
sdkVersion: "",
|
||||
platformSdkInt: 27,
|
||||
platformSdkCodename: "REL",
|
||||
platformSdkFinal: true,
|
||||
expectedMinSdkVersion: "27",
|
||||
},
|
||||
{
|
||||
name: "default non-final SDK",
|
||||
sdkVersion: "",
|
||||
platformSdkInt: 27,
|
||||
platformSdkCodename: "OMR1",
|
||||
platformSdkFinal: false,
|
||||
expectedMinSdkVersion: "OMR1",
|
||||
},
|
||||
{
|
||||
name: "14",
|
||||
sdkVersion: "14",
|
||||
expectedMinSdkVersion: "14",
|
||||
},
|
||||
}
|
||||
|
||||
for _, moduleType := range []string{"android_app", "android_library"} {
|
||||
for _, test := range testCases {
|
||||
t.Run(moduleType+" "+test.name, func(t *testing.T) {
|
||||
bp := fmt.Sprintf(`%s {
|
||||
name: "foo",
|
||||
srcs: ["a.java"],
|
||||
sdk_version: "%s",
|
||||
}`, moduleType, test.sdkVersion)
|
||||
|
||||
config := testConfig(nil)
|
||||
config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt
|
||||
config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename
|
||||
config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal
|
||||
|
||||
ctx := testAppContext(config, bp, nil)
|
||||
|
||||
run(t, ctx, config)
|
||||
|
||||
foo := ctx.ModuleForTests("foo", "android_common")
|
||||
link := foo.Output("package-res.apk")
|
||||
linkFlags := strings.Split(link.Args["flags"], " ")
|
||||
min := android.IndexList("--min-sdk-version", linkFlags)
|
||||
target := android.IndexList("--target-sdk-version", linkFlags)
|
||||
|
||||
if min == -1 || target == -1 || min == len(linkFlags)-1 || target == len(linkFlags)-1 {
|
||||
t.Fatalf("missing --min-sdk-version or --target-sdk-version in link flags: %q", linkFlags)
|
||||
}
|
||||
|
||||
gotMinSdkVersion := linkFlags[min+1]
|
||||
gotTargetSdkVersion := linkFlags[target+1]
|
||||
|
||||
if gotMinSdkVersion != test.expectedMinSdkVersion {
|
||||
t.Errorf("incorrect --min-sdk-version, expected %q got %q",
|
||||
test.expectedMinSdkVersion, gotMinSdkVersion)
|
||||
}
|
||||
|
||||
if gotTargetSdkVersion != test.expectedMinSdkVersion {
|
||||
t.Errorf("incorrect --target-sdk-version, expected %q got %q",
|
||||
test.expectedMinSdkVersion, gotTargetSdkVersion)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue