Targeting SDK Android Q results in Failed to finalize session : INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2
Solution 1
This happens because of an issue with zipalign, see - https://issuetracker.google.com/issues/37045367. You need to set extractNativeLibs
in your Application Tag on AndroidManifest.xml
<application
android:allowBackup="false"
android:label="@string/app_name"
android:extractNativeLibs="true"
...
>
If you are using adb
to install the apk try adding -t
flag
adb install -t <path-to-apk>
Solution 2
If you want android:extractNativeLibs="false"
, use zipalign with -p
key in order to page align ELFs within ZIP:
zipalign -p 4 app.apk app-aligned.apk
Solution 3
I also got this error in AWS Device Farm. Turns out they have sdk version 21 installed and my minSdkVersion
was set to 24. Lowering my minSdkVersion
to 21 resolved this. This error was getting returned on trying to install apk on the test device. Hope this helps for anyone else setting up device farm on android.
Related videos on Youtube
user1159819
Updated on September 15, 2022Comments
-
user1159819 almost 2 years
Once I switch my target api to 'Q' I cannot install the APK on Android Q Emulator. I get error:
Failed to finalize session : INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2
Android Studio (v3.3.2) recommends I uninstall apk first. I tried uninstalling apk and I still get the same error. App work if I downgrade target api to 28.
-
Francis over 5 yearssame issue on real device (running Q)
-
-
user1159819 over 5 yearsTried it, does not help
-
user1159819 over 5 yearsadb install -t apk-free.apk Performing Streamed Install adb: failed to install apk-free.apk: Failure [INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2]
-
ranjk89 over 5 yearsTry adding the following to defaultConfig in app/build.gradle file ` packagingOptions{ doNotStrip "/armeabi/.so" doNotStrip "/armeabi-v7a/.so" doNotStrip "/x86/.so" } `
-
ranjk89 over 5 yearsAlso make sure any old version of the apk is uninstalled
-
ranjk89 over 5 yearsCan you share relevant extracts from your app/build.gradle and Manifest?
-
ranjk89 over 5 yearsLooks like this might be a zipalign issue, can you try setting
extractNativeLibs
to true instead? - issuetracker.google.com/issues/37045367 -
ranjk89 over 5 yearsIf my answer helped, I'd appreciate if you can accept it as a solution!
-
appapurapu over 4 yearsWith latest gradle version 3.6.0 or greater, android sdk tools 28.0.3 or higher, gradle automatically replacing extractNativeLibs false. So better to use -p option to zipalign commend as like below zipalign -v -p 4 app.apk app-aligned.apk
-
Ivan Caravanio almost 4 yearsIt did help on my side using Xamarin.Android. The issue appeared after manually adding AndroidX components.
-
Gary Klasen over 3 yearsyou deserve a crown! great catch, indeed i am using zipalign and that was the issue.