Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Targeting SDK Android Q results in Failed to finalize session : INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2

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.

like image 825
user1159819 Avatar asked Mar 14 '19 22:03

user1159819


2 Answers

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>
like image 141
ranjk89 Avatar answered Oct 21 '22 21:10

ranjk89


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
like image 10
Miha_x64 Avatar answered Oct 21 '22 20:10

Miha_x64