一:问题
今天在 OPPO R15 上调试代码,安装后发现无法启动。报错如下
8/com.banger.xxxxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.banger.xxxxxx, PID: 9358
java.lang.RuntimeException: Unable to instantiate application com.banger.xxxxx.ui.BaseApplication: java.lang.ClassNotFoundException: Didn't find class "com.banger.xxxx.ui.BaseApplication" on path: DexPathList[[zip file "/data/app/com.banger.xxxx-YINxedP-pIswZbzon0qenQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.banger.xiaowei-YINxedP-pIswZbzon0qenQ==/lib/arm64, /system/fake-libs64, /data/app/com.banger.xxxxx-YINxedP-pIswZbzon0qenQ==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1053)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6138)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:183)
at android.app.ActivityThread.main(ActivityThread.java:7014)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:514)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.banger.xiaowei.ui.BaseApplication" on path: DexPathList[[zip file "/data/app/com.banger.xxxxx-YINxedP-pIswZbzon0qenQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.banger.xiaowei-YINxedP-pIswZbzon0qenQ==/lib/arm64, /system/fake-libs64, /data/app/com.banger.xxxxxx-YINxedP-pIswZbzon0qenQ==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newApplication(Instrumentation.java:1087)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1047)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6138)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:183)
at android.app.ActivityThread.main(ActivityThread.java:7014)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:514)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)
报错的重点在 这里Caused by: java.lang.ClassNotFoundException: Didn't find class "com.banger.xiaowei.ui.BaseApplication"
就是找不到类。
二:解决问题
这是Android studio
的 instant run
给我们留下的坑。需要在Android studio
中设置下
-
Perferences
- Build,Execution, Deployment
- instant run
-
Enable instant run to hot swap code/resouce changes on deploy(default enabled) ,默认这个是勾选的,关闭这个功能,即可正常运行调试 app 。