From 813de60e00dc1b8dbf6ef22503e1e50a694f49ea Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Sat, 29 Jul 2023 11:59:15 +0200 Subject: [PATCH] Ensure extracted JNIs are stored properly in APKs If the android_app has the use_embedded_native_libs flag all its JNIs must be stored with the store compression method. The logic to add JNIs from ARR is as follows: 1) Extract JNI libs from AAR 2) Store JNI libs with deflate 3) Merge deflated JNI libs with APK This process produces a bogus APK that won't be loaded by the framework if the use_embedded_native_libs is set as the resulting APK will have all its merged entries stored as deflate. To solve the problem in case we merge JNIs with an app requiring uncompressed JNI we add an extra step to ensure they're compressed using the store method. Test: m, verify apk using jni_extract has stored libs Change-Id: Ic31d47f15412171b5898dd0e2a554cb6bf93293b --- java/app_builder.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/java/app_builder.go b/java/app_builder.go index e241adb06..d397ff7f5 100644 --- a/java/app_builder.go +++ b/java/app_builder.go @@ -268,12 +268,24 @@ func TransformJniLibsToJar( Args: args, }) if len(prebuiltJniPackages) > 0 { + var mergeJniJarPath android.WritablePath = android.PathForModuleOut(ctx, "mergeJniJarOutput.zip") + if !uncompressJNI { + mergeJniJarPath = outputFile + } ctx.Build(pctx, android.BuildParams{ Rule: mergeAssetsRule, Description: "merge prebuilt JNI packages", Inputs: append(prebuiltJniPackages, jniJarPath), - Output: outputFile, + Output: mergeJniJarPath, }) + + if uncompressJNI { + ctx.Build(pctx, android.BuildParams{ + Rule: uncompressEmbeddedJniLibsRule, + Input: mergeJniJarPath, + Output: outputFile, + }) + } } }