From 3bbd1bebed0c15860c18779f9abb56a1d95536f6 Mon Sep 17 00:00:00 2001 From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com> Date: Wed, 15 Jan 2025 01:46:35 -0800 Subject: [PATCH] feat: use `extractNativeLibs` to reduce installed app size While this increases the APK size, it also reduces the installed size due to libs not having to be extracted. --- app/src/main/AndroidManifest.xml | 1 + .../patcher/steps/install/AlignmentStep.kt | 31 ++++++++++++++----- .../manager/patcher/util/ManifestPatcher.kt | 16 +++++++++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7fe1b13..d938db2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,6 +22,7 @@ ().patchedApk - if (Build.VERSION.SDK_INT < 29) { - state = StepState.Skipped - return - } - var resourcesArscBytes: ByteArray? = null + var nativeLibPaths: List? = null var dexCount: Int = -1 // Align resources.arsc due to targeting API 30 for silent install @@ -54,6 +49,18 @@ class AlignmentStep : Step(), KoinComponent { } } + // Align native libs due to using extractNativeLibs + nativeLibPaths = ZipReader(apk).use { zip -> + val libPaths = zip.entryNames.filter { it.endsWith(".so") } + for ((idx, path) in libPaths.withIndex()) { + // Index is just used as a placeholder id to cache on disk + val bytes = zip.openEntry(path)!!.read() + val file = paths.patchingWorkingDir().resolve("$idx.so") + file.writeBytes(bytes) + } + libPaths + } + ZipWriter(apk, /* append = */ true).use { zip -> // Delete all the unaligned files from APK if (resourcesArscBytes != null) @@ -62,6 +69,9 @@ class AlignmentStep : Step(), KoinComponent { for (i in 0..