今天在使用低版本android手机测试应用兼容性的时候,出现了Crash的情形,Android Studio版本为3.0,测试版本为API 16(Lollipop之前均存在此情况,高于5.0的版本运行正常),下面是IDE打印的错误日志:
java.lang.ExceptionInInitializerError
at android.support.multidex.MultiDexApplication.<init>(MultiDexApplication.java:35)
at com.gome.common.base.GApplication.<init>(GApplication.kt:19)
at com.gome.retail.AppGlobal.<init>(AppGlobal.kt:20)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newApplication(Instrumentation.java:982)
at android.app.Instrumentation.newApplication(Instrumentation.java:967)
at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4156)
at android.app.ActivityThread.access$1300(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4777)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:764)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:531)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1306]: 116 cannot locate '__isnanf'...
根据经验,定位为multidex的版本兼容问题,google搜索了一番,有网友出现了类似的情况 https://stackoverflow.com/questions/47290086/android-multidex-app-crashing-on-low-apis-on-android-studio-3-0
原因在于Android Studio 3.0引入了一项新功能: 高级分析器功能,因为正式版发布时间不长,存在一些稳定性问题,只需关闭此功能即可:
- 打开Edit Configurations:
- 在Adnroid App下选中当前app,并选择Profiling一栏,取消勾选“Enable advanced profiling”