Merge changes from topic "revert-3094658-revert-3088867-QEHDREAABY-IOPVAUIKWL" into main

* changes:
  Revert^2 "Refactor how jni_libs dependencies are added"
  Revert^2 "Add make java.dependencyTag installable or not"
  Revert "Revert "APK-in-APEX should set use_embedded_native_libs:..."
  Revert^2 "Install jni symlinks in Soong"
This commit is contained in:
Treehugger Robot
2024-05-20 23:00:05 +00:00
committed by Gerrit Code Review
5 changed files with 115 additions and 173 deletions

View File

@@ -274,16 +274,37 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
variation := append(jniTarget.Variations(),
blueprint.Variation{Mutator: "link", Variation: "shared"})
// If the app builds against an Android SDK use the SDK variant of JNI dependencies
// unless jni_uses_platform_apis is set.
// Don't require the SDK variant for apps that are shipped on vendor, etc., as they already
// have stable APIs through the VNDK.
if (usesSDK && !a.RequiresStableAPIs(ctx) &&
!Bool(a.appProperties.Jni_uses_platform_apis)) ||
Bool(a.appProperties.Jni_uses_sdk_apis) {
// Test whether to use the SDK variant or the non-SDK variant of JNI dependencies.
// Many factors are considered here.
// 1. Basically, the selection follows whether the app has sdk_version set or not.
jniUsesSdkVariant := usesSDK
// 2. However, jni_uses_platform_apis and jni_uses_sdk_apis can override it
if Bool(a.appProperties.Jni_uses_sdk_apis) {
jniUsesSdkVariant = true
}
if Bool(a.appProperties.Jni_uses_platform_apis) {
jniUsesSdkVariant = false
}
// 3. Then the use of SDK variant is again prohibited for the following cases:
// 3.1. the app is shipped on unbundled partitions like vendor. Since the entire
// partition (not only the app) is considered unbudled, there's no need to use the
// SDK variant.
// 3.2. the app doesn't support embedding the JNI libs
if a.RequiresStableAPIs(ctx) || !a.shouldEmbedJnis(ctx) {
jniUsesSdkVariant = false
}
if jniUsesSdkVariant {
variation = append(variation, blueprint.Variation{Mutator: "sdk", Variation: "sdk"})
}
ctx.AddFarVariationDependencies(variation, jniLibTag, a.appProperties.Jni_libs...)
// Use the installable dep tag when the JNIs are not embedded
var tag dependencyTag
if a.shouldEmbedJnis(ctx) {
tag = jniLibTag
} else {
tag = jniInstallTag
}
ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
}
for _, aconfig_declaration := range a.aaptProperties.Flags_packages {
ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration)
@@ -334,6 +355,7 @@ func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleCon
func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.checkAppSdkVersions(ctx)
a.checkEmbedJnis(ctx)
a.generateAndroidBuildActions(ctx)
a.generateJavaUsedByApex(ctx)
}
@@ -367,6 +389,17 @@ func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
a.checkSdkVersions(ctx)
}
// Ensures that use_embedded_native_libs are set for apk-in-apex
func (a *AndroidApp) checkEmbedJnis(ctx android.BaseModuleContext) {
apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
apkInApex := !apexInfo.IsForPlatform()
hasJnis := len(a.appProperties.Jni_libs) > 0
if apkInApex && hasJnis && !Bool(a.appProperties.Use_embedded_native_libs) {
ctx.ModuleErrorf("APK in APEX should have use_embedded_native_libs: true")
}
}
// If an updatable APK sets min_sdk_version, min_sdk_vesion of JNI libs should match with it.
// This check is enforced for "updatable" APKs (including APK-in-APEX).
func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVersion android.ApiLevel) {
@@ -422,9 +455,9 @@ 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
Bool(a.appProperties.Updatable) ||
a.appProperties.AlwaysPackageNativeLibs
}
func generateAaptRenamePackageFlags(packageName string, renameResourcesPackage bool) []string {
@@ -818,7 +851,9 @@ 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))
// No need to check the SDK version of the JNI deps unless we embed them
checkNativeSdkVersion := a.shouldEmbedJnis(ctx) && !Bool(a.appProperties.Jni_uses_platform_apis)
jniLibs, prebuiltJniPackages, certificates := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), checkNativeSdkVersion)
jniJarFile := a.jniBuildActions(jniLibs, prebuiltJniPackages, ctx)
if ctx.Failed() {
@@ -900,6 +935,22 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
installed := ctx.InstallFile(a.installDir, extra.Base(), extra)
extraInstalledPaths = append(extraInstalledPaths, installed)
}
// If we don't embed jni libs, make sure that those are installed along with the
// app, and also place symlinks to the installed paths under the lib/<arch>
// directory of the app installation directory. ex:
// /system/app/MyApp/lib/arm64/libfoo.so -> /system/lib64/libfoo.so
if !a.embeddedJniLibs {
for _, jniLib := range jniLibs {
archStr := jniLib.target.Arch.ArchType.String()
symlinkDir := a.installDir.Join(ctx, "lib", archStr)
for _, installedLib := range jniLib.installPaths {
// install the symlink itself
symlinkName := installedLib.Base()
symlinkTarget := android.InstallPathToOnDevicePath(ctx, installedLib)
ctx.InstallAbsoluteSymlink(symlinkDir, symlinkName, symlinkTarget)
}
}
}
ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile, extraInstalledPaths...)
}
@@ -987,6 +1038,7 @@ func collectJniDeps(ctx android.ModuleContext,
coverageFile: dep.CoverageOutputFile(),
unstrippedFile: dep.UnstrippedOutputFile(),
partition: dep.Partition(),
installPaths: dep.FilesToInstall(),
})
} else if ctx.Config().AllowMissingDependencies() {
ctx.AddMissingDependencies([]string{otherName})