Skip to content

Commit a8c542b

Browse files
committed
feat: strip native libs of other archs to shrink APK size
Fixes #76
1 parent f938982 commit a8c542b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

app/src/main/kotlin/com/aliucord/manager/patcher/steps/install/AlignmentStep.kt

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AlignmentStep : Step(), KoinComponent {
2121
override val localizedName = R.string.patch_step_alignment
2222

2323
override suspend fun execute(container: StepRunner) {
24+
val currentDeviceArch = Build.SUPPORTED_ABIS.first()
2425
val apk = container.getStep<CopyDependenciesStep>().patchedApk
2526

2627
var resourcesArscBytes: ByteArray? = null
@@ -52,12 +53,19 @@ class AlignmentStep : Step(), KoinComponent {
5253
// Align native libs due to using extractNativeLibs
5354
nativeLibPaths = ZipReader(apk).use { zip ->
5455
val libPaths = zip.entryNames.filter { it.endsWith(".so") }
56+
57+
// Extract to disk temporarily
5558
for ((idx, path) in libPaths.withIndex()) {
59+
// Ignore lib architectures that don't match this device
60+
if (!path.startsWith("lib/$currentDeviceArch"))
61+
continue
62+
5663
// Index is just used as a placeholder id to cache on disk
5764
val bytes = zip.openEntry(path)!!.read()
5865
val file = paths.patchingWorkingDir().resolve("$idx.so")
5966
file.writeBytes(bytes)
6067
}
68+
6169
libPaths
6270
}
6371

@@ -84,6 +92,10 @@ class AlignmentStep : Step(), KoinComponent {
8492

8593
// Write back native libraries aligned to 16KiB page boundary
8694
for ((idx, path) in nativeLibPaths.withIndex()) {
95+
// Ignore lib architectures that don't match this device
96+
if (!path.startsWith("lib/$currentDeviceArch"))
97+
continue
98+
8799
val file = paths.patchingWorkingDir().resolve("$idx.so")
88100
val bytes = file.readBytes()
89101
zip.writeEntry(path, bytes, ZipCompression.NONE, 16384)

0 commit comments

Comments
 (0)