Skip to content

Commit f2ee8d4

Browse files
authored
Merge pull request #106328 from m4gr3d/cherry_pick_zipalign_fix
[4.4] Update the `zipalign` implementation to properly align APKs with uncompressed `.so` libraries
2 parents 07e4185 + 9622b4b commit f2ee8d4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

platform/android/export/export_plugin.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3818,6 +3818,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
38183818

38193819
// Let's zip-align (must be done before signing)
38203820

3821+
static const int PAGE_SIZE_KB = 16 * 1024;
38213822
static const int ZIP_ALIGNMENT = 4;
38223823

38233824
// If we're not signing the apk, then the next step should be the last.
@@ -3870,6 +3871,12 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
38703871
// Uncompressed file => Align
38713872
long new_offset = file_offset + bias;
38723873
padding = (ZIP_ALIGNMENT - (new_offset % ZIP_ALIGNMENT)) % ZIP_ALIGNMENT;
3874+
const char *ext = strrchr(fname, '.');
3875+
if (ext && strcmp(ext, ".so") == 0) {
3876+
padding = (PAGE_SIZE_KB - (new_offset % PAGE_SIZE_KB)) % PAGE_SIZE_KB;
3877+
} else {
3878+
padding = (ZIP_ALIGNMENT - (new_offset % ZIP_ALIGNMENT)) % ZIP_ALIGNMENT;
3879+
}
38733880
}
38743881

38753882
memset(extra + info.size_file_extra, 0, padding);

0 commit comments

Comments
 (0)