现象:部分手机(系统5.0 11 机型系统版本不定)apk安装失败,运行代码如下:
Installation did not succeed.
The application could not be installed: INSTALL_FAILED_DEXOPT( dex优化验证失败)
List of apks:
[0] 'D:\workspace\WalletHelper\app\build\outputs\apk\debug\app-debug.apk'
The device might have stale dexed jars that don't match the current version (dexopt error).
先说解决方法:
在AndroidManifest.xml中把<application>的android:vmSafeMode属性设置true
由于设置了:minSdkVersion 21,Android 5.0(API 级别 21)及更高版本使用名为 ART 的运行时,它本身支持从 APK 文件加载多个 DEX 文件。ART 在应用安装时执行预编译,这会扫描查找 classesN.dex
文件,并将它们编译成单个 .oat
文件,以供 Android 设备执行。因此,如果您的 minSdkVersion
为 21 或更高版本,系统会默认启用 MultiDex,并且您不需要 MultiDex 库。