Apktool: [INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2] after Compile
Information
- Apktool Version (
apktool -version
) - 2.3.0 - Operating System (Mac, Linux, Windows) - Windows
- 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
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
- Have you tried
apktool d
,apktool b
without changing anything? yes - If you are trying to install a modified apk, did you resign it? yes
- 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
- Modder: remove extractNativeLib options from manifest to fix error after recompiled https://github.com/iBotPeaches/Apktool/issues/1626 — committed to KuhakuPixel/AceTheGame by KuhakuPixel 10 months ago
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 withapksigner
and should work now.With the current version of the Android build environment the manifest attribute
/manifest/application[@android:extractNativeLibs]
is always set tofalse
. 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 totrue
(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
totrue
. WithextractNativeLibs
false
I getINSTALL_FAILED_INVALID_APK
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 apkThink this is triggered by setting
extractNativeLibs
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.htmlI’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.
AAPT already has it set to
0x0
orfalse
.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.