copy JNI from AAR files to android_app APK

JNI libs present in AAR files are ignored in the build. If those
libraries are necessary, they must be manually extracted and a
prebuilt_cc_library module must be created for them. Instead, we can
extract these libraries and copy them to an output APK as part of the build.

Bug: 228848794
Test: created android_app that depends on an android_library_import with
  JNI embedded, and verified that .so libs are present in APK
Test: created android_app that depends on an android_library which
  depends on android_library_import with JNI embedded, and verified
  that .so libs are present in APK
Test: verified that multiple .so's from a single architecture are copied
  to APK
Test: verified that the absence of a jni/<arch> folder or files in the
  folder will cause the Ninja action to error
Change-Id: I242a862d7bd881f7a4a8c23493924d8fe441ea25
This commit is contained in:
Sam Delmerico
2022-06-10 17:05:42 +00:00
parent 28ee99f3c3
commit 82602492fc
8 changed files with 271 additions and 19 deletions

View File

@@ -218,8 +218,14 @@ func BuildBundleModule(ctx android.ModuleContext, outputFile android.WritablePat
})
}
func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.WritablePath,
jniLibs []jniLib, uncompressJNI bool) {
const jniJarOutputPathString = "jniJarOutput.zip"
func TransformJniLibsToJar(
ctx android.ModuleContext,
outputFile android.WritablePath,
jniLibs []jniLib,
prebuiltJniPackages android.Paths,
uncompressJNI bool) {
var deps android.Paths
jarArgs := []string{
@@ -245,13 +251,20 @@ func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.Writabl
rule = zipRE
args["implicits"] = strings.Join(deps.Strings(), ",")
}
jniJarPath := android.PathForModuleOut(ctx, jniJarOutputPathString)
ctx.Build(pctx, android.BuildParams{
Rule: rule,
Description: "zip jni libs",
Output: outputFile,
Output: jniJarPath,
Implicits: deps,
Args: args,
})
ctx.Build(pctx, android.BuildParams{
Rule: mergeAssetsRule,
Description: "merge prebuilt JNI packages",
Inputs: append(prebuiltJniPackages, jniJarPath),
Output: outputFile,
})
}
func targetToJniDir(target android.Target) string {