Reland: JNI lib is always embedded for APKs in APEX

If a JNI lib is depended on by an APK that is included in an APEX, the
lib is embedded inside the APK.

This change also fixes a bug that APKs are not mutated for APEXes.

Bug: 144135069
Test: m (apex_test.go amended)
Change-Id: I21ac24412b30c05afc03385655c6b196130dffe3
This commit is contained in:
Jiyong Park
2019-11-11 10:14:32 +09:00
parent f9e10f9443
commit 52cd06fc73
4 changed files with 26 additions and 6 deletions

View File

@@ -1217,7 +1217,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if am, ok := child.(android.ApexModule); ok { if am, ok := child.(android.ApexModule); ok {
// We cannot use a switch statement on `depTag` here as the checked // We cannot use a switch statement on `depTag` here as the checked
// tags used below are private (e.g. `cc.sharedDepTag`). // tags used below are private (e.g. `cc.sharedDepTag`).
if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) || java.IsJniDepTag(depTag) { if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
if cc, ok := child.(*cc.Module); ok { if cc, ok := child.(*cc.Module); ok {
if android.InList(cc.Name(), providedNativeSharedLibs) { if android.InList(cc.Name(), providedNativeSharedLibs) {
// If we're using a shared library which is provided from other APEX, // If we're using a shared library which is provided from other APEX,
@@ -1254,6 +1254,8 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil}) filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
return true return true
} }
} else if java.IsJniDepTag(depTag) {
// Do nothing for JNI dep. JNI libraries are always embedded in APK-in-APEX.
} else if am.CanHaveApexVariants() && am.IsInstallableToApex() { } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName) ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
} }

View File

@@ -2538,7 +2538,17 @@ func TestApexWithApps(t *testing.T) {
ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
ensureContains(t, copyCmds, "image.apex/lib64/libjni.so")
// JNI libraries are embedded inside APK
appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Rule("zip")
libjniOutput := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_core_shared_myapex").Module().(*cc.Module).OutputFile()
ensureListContains(t, appZipRule.Implicits.Strings(), libjniOutput.String())
// ... uncompressed
if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
t.Errorf("jni lib is not uncompressed for AppFoo")
}
// ... and not directly inside the APEX
ensureNotContains(t, copyCmds, "image.apex/lib64/libjni.so")
} }
func TestApexWithAppImports(t *testing.T) { func TestApexWithAppImports(t *testing.T) {

View File

@@ -262,6 +262,11 @@ func (binary *Binary) AndroidMkEntries() android.AndroidMkEntries {
} }
func (app *AndroidApp) AndroidMkEntries() android.AndroidMkEntries { func (app *AndroidApp) AndroidMkEntries() android.AndroidMkEntries {
if !app.IsForPlatform() {
return android.AndroidMkEntries{
Disabled: true,
}
}
return android.AndroidMkEntries{ return android.AndroidMkEntries{
Class: "APPS", Class: "APPS",
OutputFile: android.OptionalPathForPath(app.outputFile), OutputFile: android.OptionalPathForPath(app.outputFile),

View File

@@ -78,8 +78,9 @@ type appProperties struct {
// Store native libraries uncompressed in the APK and set the android:extractNativeLibs="false" manifest // Store native libraries uncompressed in the APK and set the android:extractNativeLibs="false" manifest
// flag so that they are used from inside the APK at runtime. Defaults to true for android_test modules unless // flag so that they are used from inside the APK at runtime. Defaults to true for android_test modules unless
// sdk_version or min_sdk_version is set to a version that doesn't support it (<23), defaults to false for other // sdk_version or min_sdk_version is set to a version that doesn't support it (<23), defaults to true for
// module types where the native libraries are generally preinstalled outside the APK. // android_app modules that are embedded to APEXes, defaults to false for other module types where the native
// libraries are generally preinstalled outside the APK.
Use_embedded_native_libs *bool Use_embedded_native_libs *bool
// Store dex files uncompressed in the APK and set the android:useEmbeddedDex="true" manifest attribute so that // Store dex files uncompressed in the APK and set the android:useEmbeddedDex="true" manifest attribute so that
@@ -217,7 +218,8 @@ func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool {
ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err) ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err)
} }
return minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs) return (minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) ||
!a.IsForPlatform()
} }
// Returns whether this module should have the dex file stored uncompressed in the APK. // Returns whether this module should have the dex file stored uncompressed in the APK.
@@ -241,7 +243,7 @@ func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool {
func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool { func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool {
return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) || return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) ||
a.appProperties.AlwaysPackageNativeLibs !a.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs
} }
func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
@@ -585,6 +587,7 @@ func AndroidAppFactory() android.Module {
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
android.InitDefaultableModule(module) android.InitDefaultableModule(module)
android.InitOverridableModule(module, &module.appProperties.Overrides) android.InitOverridableModule(module, &module.appProperties.Overrides)
android.InitApexModule(module)
return module return module
} }