From d237ad6d71d2bd5fe1ac4148fe7b69541b2708ab Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Mon, 11 Nov 2019 10:14:32 +0900 Subject: [PATCH] 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: Icf490d2701a7ede8bcad7e671fc72be9c8d7c01e --- apex/apex.go | 4 +++- apex/apex_test.go | 12 +++++++++++- java/androidmk.go | 5 +++++ java/app.go | 11 +++++++---- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 477f917e6..1216d3334 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1216,7 +1216,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { if am, ok := child.(android.ApexModule); ok { // We cannot use a switch statement on `depTag` here as the checked // 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 android.InList(cc.Name(), providedNativeSharedLibs) { // If we're using a shared library which is provided from other APEX, @@ -1253,6 +1253,8 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil}) 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() { ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName) } diff --git a/apex/apex_test.go b/apex/apex_test.go index 614164deb..330dc3cdd 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -2538,7 +2538,17 @@ func TestApexWithApps(t *testing.T) { ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.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) { diff --git a/java/androidmk.go b/java/androidmk.go index 05106806a..c97373926 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -262,6 +262,11 @@ func (binary *Binary) AndroidMkEntries() android.AndroidMkEntries { } func (app *AndroidApp) AndroidMkEntries() android.AndroidMkEntries { + if !app.IsForPlatform() { + return android.AndroidMkEntries{ + Disabled: true, + } + } return android.AndroidMkEntries{ Class: "APPS", OutputFile: android.OptionalPathForPath(app.outputFile), diff --git a/java/app.go b/java/app.go index de12b73ea..6dd6d83c6 100644 --- a/java/app.go +++ b/java/app.go @@ -78,8 +78,9 @@ type appProperties struct { // 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 - // sdk_version or min_sdk_version is set to a version that doesn't support it (<23), defaults to false for other - // module types where the native libraries are generally preinstalled outside the APK. + // sdk_version or min_sdk_version is set to a version that doesn't support it (<23), defaults to true for + // 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 // Store dex files uncompressed in the APK and set the android:useEmbeddedDex="true" manifest attribute so that @@ -216,7 +217,8 @@ func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool { 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. @@ -240,7 +242,7 @@ func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool { func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool { 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) { @@ -584,6 +586,7 @@ func AndroidAppFactory() android.Module { android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) android.InitOverridableModule(module, &module.appProperties.Overrides) + android.InitApexModule(module) return module }