Apktool: [INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2] after Compile

Information

  1. Apktool Version (apktool -version) - 2.3.0
  2. Operating System (Mac, Linux, Windows) - Windows
  3. APK From? (Playstore, ROM, Other) - PlayStore

Stacktrace/Logcat

Include stacktrace here

After recompile apk and signed I have this issue when install recompiled apk…

`Failure [INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2]

Steps to Reproduce

  1. apktool apktool.bat r …apk

Frameworks

If this APK is from an OEM ROM (Samsung, HTC, LG). Please attach framework files (.apks that live in /system/framework or /system/priv-app)

APK

If this APK can be freely shared, please upload/attach a link to it.

http://www17.zippyshare.com/v/cE36EDY0/file.html

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? yes
  2. If you are trying to install a modified apk, did you resign it? yes
  3. Are you using the latest apktool version? yes

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Seems to work with 2.4.2-d3f9d5-SNAPSHOT.

After rebuilding, zipalign it using this command: zipalign -p -f 4 input.apk output.apk Then sign it with apksigner and should work now.

With the current version of the Android build environment the manifest attribute /manifest/application[@android:extractNativeLibs] is always set to false. This means the libraries in the APK are page aligned by the build environment (not to confuse with zipaligning the whole APK) and the loader loads them directly from the APK (presumably storage space considerations). When the ApkTool (version 2.4.0) recompiles such an APK it doesn’t change the manifest settings but due to the recompilation the resulting library file layout in the APK is not page aligned anymore, and that’s the cause the loader fails and the error occures. Removing the attribute or explicitely setting it to true (the default value) prevents the bug to happen.

I can confirm this behavoir with a different apk. It still only works when I set extractNativeLibs to true. With extractNativeLibs false I get INSTALL_FAILED_INVALID_APK

Seems to work with 2.4.2-d3f9d5-SNAPSHOT.

After rebuilding, zipalign it using this command: zipalign -p -f 4 input.apk output.apk Then sign it with apksigner and should work now.

Chiming in to say that the important part for me was that I had to add the -p flag to do alignment of .so files in the apk

Think this is triggered by settingextractNativeLibs to false in the manifest. Have reverted a change to set it and the recompiled APK installs successfully. https://developer.android.com/guide/topics/manifest/application-element.html

I’m having this issue on 2.6.0. Removing the property from the manifest allows it to work.

I can also confirm that this is still an issue in 2.3.4. zipaligning the apk did unfortunately not fix it. The documentation of the extractNativeLibs attribute says: “If set to false, then your native libraries must be page aligned and stored uncompressed in the APK.”

Could the issue be related to apktool compressing the native libs for some reason? From what I can see, .so-files are actually on the doNotCompress list though…

@iBotPeaches If extractNativeLibs=“false”, then .so files should not be ZIP compressed. The system will load .so files directly from APK binary file. It won’t work if .so files are compressed.

For a dirty fix, you should always change this attribute to true. For a proper fix, you should implement new code to not compress .so files if this attribute is set to false, but compress everything else.

Interesting. Apktool should not change values of the Manifest though. I’ll run some tests with that info.

 E: application (line=34)
      A: android:label(0x01010001)=@0x7f0d0032
      A: android:icon(0x01010002)=@0x7f0b0000
      A: android:name(0x01010003)="com.bittorrent.client.BTApp" (Raw: "com.bittorrent.client.BTApp")
      A: android:allowBackup(0x01010280)=(type 0x12)0x0
      A: android:hardwareAccelerated(0x010102d3)=(type 0x12)0xffffffff
      A: android:supportsRtl(0x010103af)=(type 0x12)0x0
      A: android:extractNativeLibs(0x010104ea)=(type 0x12)0x0
      A: android:resizeableActivity(0x010104f6)=(type 0x12)0xffffffff
      A: android:roundIcon(0x0101052c)=@0x7f0b0000

AAPT already has it set to 0x0 or false.

Sorry delayed on this. Was going to look into it, but forgot my dev phone today. Just letting you know I read this and have the application locally and will look into it hopefully tomorrow.