From 20df11ef2b7a9bd5fd1c62eee5f7dffb9d560df4 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Wed, 8 May 2024 09:54:22 +0000 Subject: [PATCH 1/4] Revert^2 "Always embed jni libs and store uncompressed" a71b90cf810cfdd2bc74e7fcf7a2741fce14ff4f Change-Id: I1c071c5449fa04adb14d17774f882e6adbff196b --- java/androidmk.go | 18 ---- java/androidmk_test.go | 149 --------------------------------- java/app.go | 36 ++++---- java/app_test.go | 9 +- scripts/manifest_fixer.py | 15 +++- scripts/manifest_fixer_test.py | 4 +- 6 files changed, 36 insertions(+), 195 deletions(-) diff --git a/java/androidmk.go b/java/androidmk.go index 9cd0bafea..b2ee8b918 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -17,7 +17,6 @@ package java import ( "fmt" "io" - "strings" "android/soong/android" @@ -415,23 +414,6 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries { if app.embeddedJniLibs { jniSymbols := app.JNISymbolsInstalls(app.installPathForJNISymbols.String()) entries.SetString("LOCAL_SOONG_JNI_LIBS_SYMBOLS", jniSymbols.String()) - } else { - for _, jniLib := range app.jniLibs { - entries.AddStrings("LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), jniLib.name) - var partitionTag string - - // Mimic the creation of partition_tag in build/make, - // which defaults to an empty string when the partition is system. - // Otherwise, capitalize with a leading _ - if jniLib.partition == "system" { - partitionTag = "" - } else { - split := strings.Split(jniLib.partition, "/") - partitionTag = "_" + strings.ToUpper(split[len(split)-1]) - } - entries.AddStrings("LOCAL_SOONG_JNI_LIBS_PARTITION_"+jniLib.target.Arch.ArchType.String(), - jniLib.name+":"+partitionTag) - } } if len(app.jniCoverageOutputs) > 0 { diff --git a/java/androidmk_test.go b/java/androidmk_test.go index 2978a40aa..875e06f11 100644 --- a/java/androidmk_test.go +++ b/java/androidmk_test.go @@ -19,9 +19,6 @@ import ( "testing" "android/soong/android" - "android/soong/cc" - - "github.com/google/blueprint/proptools" ) func TestRequired(t *testing.T) { @@ -255,149 +252,3 @@ func TestGetOverriddenPackages(t *testing.T) { android.AssertDeepEquals(t, "overrides property", expected.overrides, actual) } } - -func TestJniPartition(t *testing.T) { - bp := ` - cc_library { - name: "libjni_system", - system_shared_libs: [], - sdk_version: "current", - stl: "none", - } - - cc_library { - name: "libjni_system_ext", - system_shared_libs: [], - sdk_version: "current", - stl: "none", - system_ext_specific: true, - } - - cc_library { - name: "libjni_odm", - system_shared_libs: [], - sdk_version: "current", - stl: "none", - device_specific: true, - } - - cc_library { - name: "libjni_product", - system_shared_libs: [], - sdk_version: "current", - stl: "none", - product_specific: true, - } - - cc_library { - name: "libjni_vendor", - system_shared_libs: [], - sdk_version: "current", - stl: "none", - soc_specific: true, - } - - android_app { - name: "test_app_system_jni_system", - privileged: true, - platform_apis: true, - certificate: "platform", - jni_libs: ["libjni_system"], - } - - android_app { - name: "test_app_system_jni_system_ext", - privileged: true, - platform_apis: true, - certificate: "platform", - jni_libs: ["libjni_system_ext"], - } - - android_app { - name: "test_app_system_ext_jni_system", - privileged: true, - platform_apis: true, - certificate: "platform", - jni_libs: ["libjni_system"], - system_ext_specific: true - } - - android_app { - name: "test_app_system_ext_jni_system_ext", - sdk_version: "core_platform", - jni_libs: ["libjni_system_ext"], - system_ext_specific: true - } - - android_app { - name: "test_app_product_jni_product", - sdk_version: "core_platform", - jni_libs: ["libjni_product"], - product_specific: true - } - - android_app { - name: "test_app_vendor_jni_odm", - sdk_version: "core_platform", - jni_libs: ["libjni_odm"], - soc_specific: true - } - - android_app { - name: "test_app_odm_jni_vendor", - sdk_version: "core_platform", - jni_libs: ["libjni_vendor"], - device_specific: true - } - android_app { - name: "test_app_system_jni_multiple", - privileged: true, - platform_apis: true, - certificate: "platform", - jni_libs: ["libjni_system", "libjni_system_ext"], - } - android_app { - name: "test_app_vendor_jni_multiple", - sdk_version: "core_platform", - jni_libs: ["libjni_odm", "libjni_vendor"], - soc_specific: true - } - ` - arch := "arm64" - ctx := android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, - cc.PrepareForTestWithCcDefaultModules, - android.PrepareForTestWithAndroidMk, - android.FixtureModifyConfig(func(config android.Config) { - config.TestProductVariables.DeviceArch = proptools.StringPtr(arch) - }), - ). - RunTestWithBp(t, bp) - testCases := []struct { - name string - partitionNames []string - partitionTags []string - }{ - {"test_app_system_jni_system", []string{"libjni_system"}, []string{""}}, - {"test_app_system_jni_system_ext", []string{"libjni_system_ext"}, []string{"_SYSTEM_EXT"}}, - {"test_app_system_ext_jni_system", []string{"libjni_system"}, []string{""}}, - {"test_app_system_ext_jni_system_ext", []string{"libjni_system_ext"}, []string{"_SYSTEM_EXT"}}, - {"test_app_product_jni_product", []string{"libjni_product"}, []string{"_PRODUCT"}}, - {"test_app_vendor_jni_odm", []string{"libjni_odm"}, []string{"_ODM"}}, - {"test_app_odm_jni_vendor", []string{"libjni_vendor"}, []string{"_VENDOR"}}, - {"test_app_system_jni_multiple", []string{"libjni_system", "libjni_system_ext"}, []string{"", "_SYSTEM_EXT"}}, - {"test_app_vendor_jni_multiple", []string{"libjni_odm", "libjni_vendor"}, []string{"_ODM", "_VENDOR"}}, - } - - for _, test := range testCases { - t.Run(test.name, func(t *testing.T) { - mod := ctx.ModuleForTests(test.name, "android_common").Module() - entry := android.AndroidMkEntriesForTest(t, ctx.TestContext, mod)[0] - for i := range test.partitionNames { - actual := entry.EntryMap["LOCAL_SOONG_JNI_LIBS_PARTITION_"+arch][i] - expected := test.partitionNames[i] + ":" + test.partitionTags[i] - android.AssertStringEquals(t, "Expected and actual differ", expected, actual) - } - }) - } -} diff --git a/java/app.go b/java/app.go index 50d1a2f43..0170ea186 100644 --- a/java/app.go +++ b/java/app.go @@ -90,20 +90,17 @@ type appProperties struct { Stl *string `android:"arch_variant"` // 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 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. + // flag so that they are used from inside the APK at runtime. This property is respected only for + // APKs built using android_test or android_test_helper_app. For other APKs, this property is ignored + // and native libraries are always embedded compressed. Use_embedded_native_libs *bool // Store dex files uncompressed in the APK and set the android:useEmbeddedDex="true" manifest attribute so that // they are used from inside the APK at runtime. Use_embedded_dex *bool - // Forces native libraries to always be packaged into the APK, - // Use_embedded_native_libs still selects whether they are stored uncompressed and aligned or compressed. - // True for android_test* modules. - AlwaysPackageNativeLibs bool `blueprint:"mutated"` + // Allows compressing of embedded native libs. Only for android_test and android_test_helper_app. + AllowCompressingNativeLibs bool `blueprint:"mutated"` // If set, find and merge all NOTICE files that this module and its dependencies have and store // it in the APK as an asset. @@ -403,14 +400,20 @@ func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVer // Returns true if the native libraries should be stored in the APK uncompressed and the // extractNativeLibs application flag should be set to false in the manifest. func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool { + var useEmbedded bool + if a.appProperties.AllowCompressingNativeLibs { + useEmbedded = BoolDefault(a.appProperties.Use_embedded_native_libs, true) + } else { + useEmbedded = true // always uncompress for non-test apps + } + minSdkVersion, err := a.MinSdkVersion(ctx).EffectiveVersion(ctx) if err != nil { ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.MinSdkVersion(ctx), err) } + supported := minSdkVersion.FinalOrFutureInt() >= 23 - apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) - return (minSdkVersion.FinalOrFutureInt() >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) || - !apexInfo.IsForPlatform() + return useEmbedded && supported } // Returns whether this module should have the dex file stored uncompressed in the APK. @@ -433,9 +436,8 @@ func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool { } func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool { - apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) - return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) || - !apexInfo.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs + // Always! + return true } func generateAaptRenamePackageFlags(packageName string, renameResourcesPackage bool) []string { @@ -1400,8 +1402,7 @@ func AndroidTestFactory() android.Module { module.Module.properties.Instrument = true module.Module.properties.Supports_static_instrumentation = true module.Module.properties.Installable = proptools.BoolPtr(true) - module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) - module.appProperties.AlwaysPackageNativeLibs = true + module.appProperties.AllowCompressingNativeLibs = true module.Module.dexpreopter.isTest = true module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) @@ -1456,8 +1457,7 @@ func AndroidTestHelperAppFactory() android.Module { module.Module.dexProperties.Optimize.EnabledByDefault = true module.Module.properties.Installable = proptools.BoolPtr(true) - module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) - module.appProperties.AlwaysPackageNativeLibs = true + module.appProperties.AllowCompressingNativeLibs = true module.Module.dexpreopter.isTest = true module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) diff --git a/java/app_test.go b/java/app_test.go index a7c48a1ed..92fe2244f 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -2013,8 +2013,8 @@ func TestJNIPackaging(t *testing.T) { packaged bool compressed bool }{ - {"app", false, false}, - {"app_noembed", false, false}, + {"app", true, false}, + {"app_noembed", true, false}, {"app_embed", true, false}, {"test", true, false}, {"test_noembed", true, true}, @@ -3319,8 +3319,7 @@ func TestUsesLibraries(t *testing.T) { // These also include explicit `uses_libs`/`optional_uses_libs` entries, as they may be // propagated from dependencies. actualManifestFixerArgs := app.Output("manifest_fixer/AndroidManifest.xml").Args["args"] - expectManifestFixerArgs := `--extract-native-libs=true ` + - `--uses-library foo ` + + expectManifestFixerArgs := `--uses-library foo ` + `--uses-library com.non.sdk.lib ` + `--uses-library qux ` + `--uses-library quuz ` + @@ -4110,7 +4109,7 @@ func TestAppIncludesJniPackages(t *testing.T) { }, { name: "aary-no-use-embedded", - hasPackage: false, + hasPackage: true, }, } diff --git a/scripts/manifest_fixer.py b/scripts/manifest_fixer.py index 58079aa5d..35d2a1c81 100755 --- a/scripts/manifest_fixer.py +++ b/scripts/manifest_fixer.py @@ -62,8 +62,8 @@ def parse_args(): 'in the manifest.')) parser.add_argument('--extract-native-libs', dest='extract_native_libs', default=None, type=lambda x: (str(x).lower() == 'true'), - help=('specify if the app wants to use embedded native libraries. Must not conflict ' - 'if already declared in the manifest.')) + help=('specify if the app wants to use embedded native libraries. Must not ' + 'be true if manifest says false.')) parser.add_argument('--has-no-code', dest='has_no_code', action='store_true', help=('adds hasCode="false" attribute to application. Ignored if application elem ' 'already has a hasCode attribute.')) @@ -299,7 +299,16 @@ def add_extract_native_libs(doc, extract_native_libs): attr = doc.createAttributeNS(android_ns, 'android:extractNativeLibs') attr.value = value application.setAttributeNode(attr) - elif attr.value != value: + elif attr.value == "false" and value == "true": + # Note that we don't disallow the case of extractNativeLibs="true" in manifest and + # --extract-native-libs="false". This is fine because --extract-native-libs="false" means that + # the build system didn't compress the JNI libs, which is a fine choice for built-in apps. At + # runtime the JNI libs will be extracted to outside of the APK, but everything will still work + # okay. + # + # The opposite (extractNativeLibs="false" && --extract-native-libs="true") should however be + # disallowed because otherwise that would make an ill-formed APK; JNI libs are stored compressed + # but they won't be extracted. There's no way to execute the JNI libs. raise RuntimeError('existing attribute extractNativeLibs="%s" conflicts with --extract-native-libs="%s"' % (attr.value, value)) diff --git a/scripts/manifest_fixer_test.py b/scripts/manifest_fixer_test.py index 0a62b10a4..9fce6b9b8 100755 --- a/scripts/manifest_fixer_test.py +++ b/scripts/manifest_fixer_test.py @@ -479,8 +479,8 @@ class AddExtractNativeLibsTest(unittest.TestCase): self.assert_xml_equal(output, expected) def test_conflict(self): - manifest_input = self.manifest_tmpl % self.extract_native_libs('true') - self.assertRaises(RuntimeError, self.run_test, manifest_input, False) + manifest_input = self.manifest_tmpl % self.extract_native_libs('false') + self.assertRaises(RuntimeError, self.run_test, manifest_input, True) class AddNoCodeApplicationTest(unittest.TestCase): From ef5511ff77305d1e55e191a667706d1115f9486d Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Wed, 8 May 2024 09:54:22 +0000 Subject: [PATCH 2/4] Revert "Revert "Collect transitve deps of jni libs only for bund..." Revert submission 3078746-revert-3075263-MMTOVXSVUO Reason for revert: relanding with forward fix: aosp/3078748 Reverted changes: /q/submissionid:3078746-revert-3075263-MMTOVXSVUO Change-Id: I207f6fd83190e258eba8b22c0d6a6f0feea9f87f --- java/app.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/java/app.go b/java/app.go index 0170ea186..254fbf4fd 100644 --- a/java/app.go +++ b/java/app.go @@ -440,6 +440,21 @@ func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool { return true } +func (a *AndroidApp) shouldCollectRecursiveNativeDeps(ctx android.ModuleContext) bool { + // JNI libs are always embedded, but whether to embed their transitive dependencies as well + // or not is determined here. For most of the apps built here (using the platform build + // system), we don't need to collect the transitive deps because they will anyway be + // available in the partition image where the app will be installed to. + // + // Collecting transitive dependencies is required only for unbundled apps. + apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) + apkInApex := !apexInfo.IsForPlatform() + testApp := a.appProperties.AllowCompressingNativeLibs + unbundledApp := ctx.Config().UnbundledBuild() || apkInApex || testApp + + return a.shouldEmbedJnis(ctx) && unbundledApp +} + func generateAaptRenamePackageFlags(packageName string, renameResourcesPackage bool) []string { aaptFlags := []string{"--rename-manifest-package " + packageName} if renameResourcesPackage { @@ -831,7 +846,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { dexJarFile, packageResources := a.dexBuildActions(ctx) - jniLibs, prebuiltJniPackages, certificates := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis)) + jniLibs, prebuiltJniPackages, certificates := collectAppDeps(ctx, a, a.shouldCollectRecursiveNativeDeps(ctx), !Bool(a.appProperties.Jni_uses_platform_apis)) jniJarFile := a.jniBuildActions(jniLibs, prebuiltJniPackages, ctx) if ctx.Failed() { From 1fb7c3512989311818af83d6aee246f171907a05 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 10 May 2024 11:17:33 +0900 Subject: [PATCH 3/4] Add SkipToTransitiveDepsTag interface for dependency tags Consider this dependency graph: A --> B --> C And let's assume that B is built into A (e.g. static_libs), while B --> C is a runtime dependency (e.g. required). We want to install C (but not B of course) when A gets installed. However, before this change, it was not supported because the dependency A -> B was not tracked in computeInstallDeps. One had to explicitly add a A -> C dependency. This change fixes the problem by introducing the new interface SkipToTransitiveDepsTag. computeInstallDeps uses it to decide whether to take all install files and packaging specs or only those from transitive dependencies. In the above example, if the dependency A --> B implements the new interface and returns true, B's transitive dependencies (i.e. C) are added into A's transitive dependencies. B's outputs are not added. Bug: N/A Test: go test ./... under soong/android Change-Id: I3ca03a21633883f320ecb9e5bc82eb134519cd88 --- android/deptag.go | 15 +++++++++++++ android/module.go | 18 +++++++++++++--- android/packaging_test.go | 45 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/android/deptag.go b/android/deptag.go index c7ba4d36f..77b9d6114 100644 --- a/android/deptag.go +++ b/android/deptag.go @@ -44,6 +44,21 @@ func IsInstallDepNeededTag(tag blueprint.DependencyTag) bool { return false } +// Dependency tags can implement this interface and return true from SkipToTransitiveDeps to +// annotate that this dependency isn't installed, but its transitive dependencies are. This is +// useful when a module is built into another module (ex: static linking) but the module still has +// runtime dependencies. +type SkipToTransitiveDepsTag interface { + SkipToTransitiveDeps() bool +} + +func IsSkipToTransitiveDepsTag(tag blueprint.DependencyTag) bool { + if i, ok := tag.(SkipToTransitiveDepsTag); ok { + return i.SkipToTransitiveDeps() + } + return false +} + type PropagateAconfigValidationDependencyTag interface { PropagateAconfigValidation() bool } diff --git a/android/module.go b/android/module.go index 40a591007..1664f0328 100644 --- a/android/module.go +++ b/android/module.go @@ -1470,15 +1470,27 @@ func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*DepSet[InstallPat var installDeps []*DepSet[InstallPath] var packagingSpecs []*DepSet[PackagingSpec] ctx.VisitDirectDeps(func(dep Module) { - if isInstallDepNeeded(dep, ctx.OtherModuleDependencyTag(dep)) { + depTag := ctx.OtherModuleDependencyTag(dep) + // If this is true, the direct outputs from the module is not gathered, but its + // transitive deps are still gathered. + skipToTransitive := IsSkipToTransitiveDepsTag(depTag) + if isInstallDepNeeded(dep, depTag) || skipToTransitive { // Installation is still handled by Make, so anything hidden from Make is not // installable. if !dep.IsHideFromMake() && !dep.IsSkipInstall() { - installDeps = append(installDeps, dep.base().installFilesDepSet) + if skipToTransitive { + installDeps = append(installDeps, dep.base().installFilesDepSet.transitive...) + } else { + installDeps = append(installDeps, dep.base().installFilesDepSet) + } } // Add packaging deps even when the dependency is not installed so that uninstallable // modules can still be packaged. Often the package will be installed instead. - packagingSpecs = append(packagingSpecs, dep.base().packagingSpecsDepSet) + if skipToTransitive { + packagingSpecs = append(packagingSpecs, dep.base().packagingSpecsDepSet.transitive...) + } else { + packagingSpecs = append(packagingSpecs, dep.base().packagingSpecsDepSet) + } } }) diff --git a/android/packaging_test.go b/android/packaging_test.go index 383343723..4b72c24f9 100644 --- a/android/packaging_test.go +++ b/android/packaging_test.go @@ -25,8 +25,9 @@ import ( type componentTestModule struct { ModuleBase props struct { - Deps []string - Skip_install *bool + Deps []string + Build_only_deps []string + Skip_install *bool } } @@ -36,6 +37,18 @@ type installDepTag struct { InstallAlwaysNeededDependencyTag } +// dep tag for build_only_deps +type buildOnlyDepTag struct { + blueprint.BaseDependencyTag + InstallAlwaysNeededDependencyTag +} + +var _ SkipToTransitiveDepsTag = (*buildOnlyDepTag)(nil) + +func (tag buildOnlyDepTag) SkipToTransitiveDeps() bool { + return true +} + func componentTestModuleFactory() Module { m := &componentTestModule{} m.AddProperties(&m.props) @@ -45,6 +58,7 @@ func componentTestModuleFactory() Module { func (m *componentTestModule) DepsMutator(ctx BottomUpMutatorContext) { ctx.AddDependency(ctx.Module(), installDepTag{}, m.props.Deps...) + ctx.AddDependency(ctx.Module(), buildOnlyDepTag{}, m.props.Build_only_deps...) } func (m *componentTestModule) GenerateAndroidBuildActions(ctx ModuleContext) { @@ -398,3 +412,30 @@ func TestPackagingWithSkipInstallDeps(t *testing.T) { } `, []string{"lib64/foo", "lib64/bar", "lib64/baz"}) } + +func TestPackagingWithSkipToTransitvDeps(t *testing.T) { + // packag -[deps]-> foo -[build_only_deps]-> bar -[deps]-> baz + // bar isn't installed, but it brings baz to its parent. + multiTarget := false + runPackagingTest(t, multiTarget, + ` + component { + name: "foo", + build_only_deps: ["bar"], + } + + component { + name: "bar", + deps: ["baz"], + } + + component { + name: "baz", + } + + package_module { + name: "package", + deps: ["foo"], + } + `, []string{"lib64/foo", "lib64/baz"}) +} From e7168070832a9a849007c9e63cd3cd827d1904e4 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Thu, 9 May 2024 10:57:07 +0900 Subject: [PATCH 4/4] Install transitive deps of jni libs, but not the jni libs themselves Consider this case: app --(jni_libs)--> libfoo --(shared_libs)--> libprivate Only libfoo is embedded into the app. libprivate is not embedded because libprivate is very likely to be depended on by other components in the platform, in which case it will anyway be installed to /system/lib. Embedding libprivate into the app will increase the storage usage as a whole. Furthermore, if libprivate is not a shared lib but a config file (of type prebuilt_etc), it can't be embedded and therefore must be installed outside of the app. However, a problem occurs when libprivate is not depended on by anyone else. Then libprivate is not installed to the system partition, causing an error at runtime. This CL fixes that by making the jni_libs dependency to implement the new SKipToTransitiveDepsTag interface. Now, jni_libs themselves are not installed, but their transitive deps are depended on by the app containing the jni libs. Bug: 330276359 Test: m NfcNci and check if libnfc-nci.config is installed. Test: m CarService and check android.hardware.automotive.evs-V2-ndk.so is installed as well. Test: go test ./... under soong/java Change-Id: I04cc92b7fad768a20ec60a02b3e7534641b1e74d --- java/app_test.go | 38 ++++++++++++++++++++++++++++++++++++++ java/java.go | 11 +++++++++++ 2 files changed, 49 insertions(+) diff --git a/java/app_test.go b/java/app_test.go index 92fe2244f..d6ba0f1dd 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -2043,6 +2043,44 @@ func TestJNIPackaging(t *testing.T) { } } +func TestJNITranstiveDepsInstallation(t *testing.T) { + ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` + android_app { + name: "app", + jni_libs: ["libjni"], + platform_apis: true, + } + + cc_library { + name: "libjni", + shared_libs: ["libplatform"], + system_shared_libs: [], + stl: "none", + required: ["librequired"], + } + + cc_library { + name: "libplatform", + system_shared_libs: [], + stl: "none", + } + + cc_library { + name: "librequired", + system_shared_libs: [], + stl: "none", + } + + `) + + app := ctx.ModuleForTests("app", "android_common") + jniLibZip := app.Output("jnilibs.zip") + android.AssertPathsEndWith(t, "embedd jni lib mismatch", []string{"libjni.so"}, jniLibZip.Implicits) + + install := app.Rule("Cp") + android.AssertPathsEndWith(t, "install dep mismatch", []string{"libplatform.so", "librequired.so"}, install.OrderOnly) +} + func TestJNISDK(t *testing.T) { ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` cc_library { diff --git a/java/java.go b/java/java.go index 0df96a3a5..fc7e5c5a3 100644 --- a/java/java.go +++ b/java/java.go @@ -368,6 +368,17 @@ type dependencyTag struct { static bool } +var _ android.SkipToTransitiveDepsTag = (*dependencyTag)(nil) + +func (depTag dependencyTag) SkipToTransitiveDeps() bool { + // jni_libs are not installed because they are always embedded into the app. However, + // transitive deps of jni_libs themselves should be installed along with the app. + if IsJniDepTag(depTag) { + return true + } + return false +} + // installDependencyTag is a dependency tag that is annotated to cause the installed files of the // dependency to be installed when the parent module is installed. type installDependencyTag struct {