Use 'stem' to override APK name

When android_app.stem is set, use it as the APK name like other module
types.

Bug: 193504286
Test: m (soong test)
Change-Id: I4c95b77be382cff3cfecaf6ce38f99aed9f3238f
This commit is contained in:
Jooyung Han 2022-01-08 12:13:59 +09:00
parent 6609484961
commit 29e2f6d2c4
3 changed files with 23 additions and 4 deletions

View file

@ -433,8 +433,10 @@ func (a *AndroidApp) getOverriddenPackages() []string {
if len(a.appProperties.Overrides) > 0 {
overridden = append(overridden, a.appProperties.Overrides...)
}
if a.Name() != a.installApkName {
overridden = append(overridden, a.Name())
// When APK name is overridden via PRODUCT_PACKAGE_NAME_OVERRIDES
// ensure that the original name is overridden.
if a.Stem() != a.installApkName {
overridden = append(overridden, a.Stem())
}
return overridden
}

View file

@ -621,7 +621,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
a.aapt.useEmbeddedDex = Bool(a.appProperties.Use_embedded_dex)
// Check if the install APK name needs to be overridden.
a.installApkName = ctx.DeviceConfig().OverridePackageNameFor(a.Name())
a.installApkName = ctx.DeviceConfig().OverridePackageNameFor(a.Stem())
if ctx.ModuleName() == "framework-res" {
// framework-res.apk is installed as system/framework/framework-res.apk
@ -1006,6 +1006,7 @@ func (a *AndroidTest) FixTestConfig(ctx android.ModuleContext, testConfig androi
command := rule.Command().BuiltTool("test_config_fixer").Input(testConfig).Output(fixedConfig)
fixNeeded := false
// Auto-generated test config uses `ModuleName` as the APK name. So fix it if it is not the case.
if ctx.ModuleName() != a.installApkName {
fixNeeded = true
command.FlagWithArg("--test-file-name ", a.installApkName+".apk")

View file

@ -1707,7 +1707,7 @@ func TestPackageNameOverride(t *testing.T) {
},
},
{
name: "overridden",
name: "overridden via PRODUCT_PACKAGE_NAME_OVERRIDES",
bp: `
android_app {
name: "foo",
@ -1722,6 +1722,22 @@ func TestPackageNameOverride(t *testing.T) {
"out/soong/target/product/test_device/system/app/bar/bar.apk",
},
},
{
name: "overridden via stem",
bp: `
android_app {
name: "foo",
srcs: ["a.java"],
sdk_version: "current",
stem: "bar",
}
`,
packageNameOverride: "",
expected: []string{
"out/soong/.intermediates/foo/android_common/bar.apk",
"out/soong/target/product/test_device/system/app/bar/bar.apk",
},
},
}
for _, test := range testCases {