godotengine / godotengine/godot

Android 14: Export Template with changed minSdk results in pre-align errors

Open
#103,166 6 comments 0 reactions 0 assignees View on GitHub
bug platform:android topic:export
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Reproducible in 4.3.stable and 4.2.2.stable

### System information

Godot v4.3.stable - Linux Mint 21.3 (Virginia) - X11 - GLES3 (Compatibility)

### Issue description

Since Android 14 has an hard requirement for the minSdk version to be 23, I've compiled an export template where I've changed `platform/android/java/app/config.gradle`'s minSdk directly and compiled the export templates as such with both arm32 and arm64.

After trying to export the game **without** `Gradle Build` option, the resulting APK is not installable on my Android 14 device. The export settings are the following:

![Image](https://github.com/user-attachments/assets/e3eca188-5f06-4e32-90c8-caf8bccebed6)

The error on `adb install` can be seen below:
```
Performing Incremental Install
Serving...
Failure [INSTALL_FAILED_INTERNAL_ERROR: INSTALL_FAILED_INTERNAL_ERROR: Failed to extract native libraries, res=-110]
Performing Streamed Install
adb: failed to install test.apk: Failure [INSTALL_FAILED_INVALID_APK: INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2]
```

With the following logcat error:
```
PackageInstallerSession: START COMMIT SESSION: id{112768871}
NativeLibraryHelper: Library 'libgodot_android.so' is not page-aligned - will not be able to open it directly from apk.
NativeHelper: Failure copying native libraries [errorCode=-2]
PackageInstallerSession: Marking session 112768871 as failed: INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2
PackageInstallerSession: Failed to verify session 112768871
PackageInstallerSession: result of session: -2{112768871}, INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2
```

After looking around the issues I found a similar problem reported for Godot 3.2.4 in issue #42792, which took me to the `zipalign` and allowed me to check the resulting APK with `zipalign` and re-align it. This however revokes the signature and you will have to sign it again afterwards.

For now the workaround is to pre-align the libs and re-sign with:
```
# Export APK in Godot
zipalign -p -f 4 test.apk test-aligned.apk
apksigner sign --ks ... --ks-pass ... --ks-key-alias ... test-aligned.apk
```

EDIT:
~~Need to confirm before being sure, but for Android 14, the alignment might be required to be 8 bytes instead of 4 bytes, which would result in the zipalign command being `zipalign -p -f 8 test.apk test-aligned.apk` instead.~~
Seems to not be necessary after all.

### Steps to reproduce

1. Compile an export template for Android with an higher minSdk on `platform/android/java/app/config.gradle` and both arm32 and arm64
2. Export a game for Android **without** Gradle Build, using that compiled export
3. Attempt to install the resulting game in an Android 14 device

### Minimal reproduction project (MRP)

N/A

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.