I *Export*ed from Aurora Store Firefox Android `{config.{arm64_v8a,xxhdpi},base}.apk`. I decompressed `config.arm64_v8a.apk` with `apktool d`, modified a file, recompressed with `apktool b` and aligned with `zipalign -v 4` signed it with `apksigner` with my own key (not initial Firefox Android one). When I try to install on Fairphone 4 LineageOS 23.2 my modified `config.arm64_v8a.apk` I face:

```bash
adb install-multiple base.apk config.arm64_v8a/dist/config.arm64_v8a_aligned.apk config.xxhdpi.apk
```
```
Performing Incremental Install
Serving...
Failure [INSTALL_FAILED_INTERNAL_ERROR: INSTALL_FAILED_INTERNAL_ERROR: Failed to extract native libraries, res=-110]
adb: failed to finalize session
Failure [INSTALL_FAILED_INVALID_APK: INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2]
```

```bash
adb logcat
```

Output excerpt:

```
06-07 16:57:07.247 1505 12093 W libbinder.Binder: Binder transaction to android.content.pm.IPackageManager code 1598246212 took 7573ms. Data bytes: 296 Reply bytes: 4 Flags: 16
06-07 16:57:07.250 11651 11651 I abb : StartCommandInProcess(7061636b61676500696e7374616c6c2d package.install- [truncated])
06-07 16:57:07.278 11651 11651 I abb : StartCommandInProcess(7061636b61676500696e7374616c6c2d package.install- [truncated])
06-07 16:57:07.956 1505 27482 E NativeLibraryHelper: extractNativeLibs=false library 'libmegazord.so' is not PAGE(4096)-aligned within apk (APK alignment, not ELF alignment) -will not be able to open it directly from apk.
06-07 16:57:07.956 1505 27482 W NativeHelper: Failure copying native libraries [errorCode=-2]
06-07 16:57:07.957 1505 27482 D PackageInstallerSession: Marking session 991097439 as failed: INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2
06-07 16:57:07.957 1505 27482 I PackageInstallerSession: Session [991097439] was destroyed because of [Session marked as failed: INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2]
06-07 16:57:08.005 1505 27482 E PackageInstallerSession: Failed to verify session 991097439
```
Jun 7, 3:00pm

The error you're encountering, INSTALL_FAILED_INTERNAL_ERROR: Failed to extract native libraries, res=-110 and INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2, is directly related to the alignment and structure of your modified config.arm64_v8a.apk. The key log line is:

text
E NativeLibraryHelper: extractNativeLibs=false library 'libmegazord.so' is not PAGE(4096)-aligned within apk (APK alignment, not ELF alignment) - will not be able to open it directly from apk.

Root Cause

1. APK Alignment Issue

  • Android requires all APKs (including split APKs like config.arm64_v8a.apk) to be 4KB (4096-byte) aligned for native libraries (.so files) to be extracted and loaded correctly.
  • Your zipalign -v 4 command aligns the APK, but if the native libraries inside the APK are not properly aligned or the APK itself is not correctly structured after modification, this error occurs.
  • The log explicitly states that libmegazord.so is not page-aligned within the APK.

2. Split APK Structure

  • When using install-multiple, all split APKs must be properly aligned and signed with the same key.
  • If the base.apk and config.arm64_v8a.apk are not signed with the same key, or if the alignment is broken, the installer will fail.

3. Modification Impact

  • Modifying files in config.arm64_v8a.apk (especially if it affects the lib/ directory or the APK's internal structure) can break the alignment or the expected layout.

How to Fix

1. Recheck APK Alignment

  • After rebuilding with apktool b, always run zipalign -v 4 on the output APK.
  • Verify alignment with:
    bash
    zipalign -c -v 4 config.arm64_v8a/dist/config.arm64_v8a_aligned.apk
    If this fails, re-align the APK.

2. Ensure Consistent Signing

  • All split APKs (base.apk, config.arm64_v8a.apk, config.xxhdpi.apk) must be signed with the same key.
  • Use the same keystore and alias for all APKs:
    bash
    apksigner sign --ks mykey.jks --ks-key-alias myalias --out base_signed.apk base.apk
    apksigner sign --ks mykey.jks --ks-key-alias myalias --out config.arm64_v8a_signed.apk config.arm64_v8a/dist/config.arm64_v8a_aligned.apk
    apksigner sign --ks mykey.jks --ks-key-alias myalias --out config.xxhdpi_signed.apk config.xxhdpi.apk
  • Then install with:
    bash
    adb install-multiple base_signed.apk config.arm64_v8a_signed.apk config.xxhdpi_signed.apk

3. Check Native Library Alignment

  • The error mentions libmegazord.so is not page-aligned within the APK.
  • After rebuilding, ensure that the lib/ directory in the APK is correctly structured and that the .so files are not corrupted.
  • You can inspect the APK contents with:
    bash
    unzip -l config.arm64_v8a/dist/config.arm64_v8a_aligned.apk | grep lib/
    If the .so files are missing or misplaced, the rebuild process may have failed.

4. Rebuild with apktool Correctly

  • When rebuilding with apktool b, use the --use-aapt2 flag (if available) for better compatibility:
    bash
    apktool b --use-aapt2 config.arm64_v8a -o config.arm64_v8a_rebuilt.apk
  • Then align and sign as above.

5. Verify APK Structure

  • Use aapt or apktool to dump the APK and check for issues:
    bash
    aapt dump badging config.arm64_v8a/dist/config.arm64_v8a_aligned.apk
    Look for warnings or errors.

6. Test with a Clean Rebuild

  • Start fresh: decompress, modify, rebuild, align, and sign all split APKs again.
  • Ensure no files are accidentally deleted or corrupted during modification.

Summary of Commands

bash
# Rebuild
apktool b --use-aapt2 config.arm64_v8a -o config.arm64_v8a_rebuilt.apk

# Align
zipalign -v 4 config.arm64_v8a_rebuilt.apk config.arm64_v8a_aligned.apk

# Sign all split APKs with the same key
apksigner sign --ks mykey.jks --ks-key-alias myalias --out base_signed.apk base.apk
apksigner sign --ks mykey.jks --ks-key-alias myalias --out config.arm64_v8a_signed.apk config.arm64_v8a_aligned.apk
apksigner sign --ks mykey.jks --ks-key-alias myalias --out config.xxhdpi_signed.apk config.xxhdpi.apk

# Install
adb install-multiple base_signed.apk config.arm64_v8a_signed.apk config.xxhdpi_signed.apk

If the Issue Persists

  • The problem might be with the original APK structure or how apktool handles split APKs.
  • Try using bundletool (for Android App Bundles) or manually repack the APKs with zip and signapk for more control.
  • Alternatively, consider modifying the base.apk instead of the split APK, if possible.
Jun 7, 3:00pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more