问题
最近碰到个问题,在Android手机上安装apk安装不上,使用adb命令安装后出现以下报错
➜ ~ adb install test.apk
Failed to install test.apk: Failure [INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2]
分析
从控制台的报错信息来看,这个错误是安装时,提取so失败。你想该apk ,发现该AndroidManifest.xml中
<application android:theme="@style/PortalTheme" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:name="com.xxx.XXXApplication" android:allowBackup="true" android:hardwareAccelerated="true" android:largeHeap="true" android:supportsRtl="true" android:extractNativeLibs="false" android:resizeableActivity="true" android:networkSecurityConfig="@xml/network_security_config" android:roundIcon="@mipmap/ic_launcher" android:appComponentFactory="androidx.core.app.CoreComponentFactory">
有包含属性android:extractNativeLibs="false"
该属性告诉系统,不要把 so 文件从 apk 中解压出来。
解决方法
方法1:
删除属性 android:extractNativeLibs="false";
方法2:
修改属性 android:extractNativeLibs="true";