解决OPPO手机在Android studio 环境下安装失败问题

崩溃日志重现:
Process: XXX.XXX.XXXX, PID: 24345
        java.lang.RuntimeException: Unable to instantiate application XXX.XXX.XXXX.MyApplication: java.lang.ClassNotFoundException: Didn't find class "XXX.XXX.XXXX.MyApplication" on path: DexPathList[[zip file "/data/app/XXX.XXX.XXXX-2/base.apk"],nativeLibraryDirectories=[/data/app/XXX.XXX.XXXX-2/lib/arm, /data/app/XXX.XXX.XXXX-2/base.apk!/lib/armeabi, /system/lib, /vendor/lib]]
        at android.app.LoadedApk.makeApplication(LoadedApk.java:853)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5748)
        at android.app.ActivityThread.-wrap2(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1716)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:185)
        at android.app.ActivityThread.main(ActivityThread.java:6615)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:916)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:806)
        Caused by: java.lang.ClassNotFoundException: Didn't find class "XXX.XXX.XXXX.MyApplication" on path: DexPathList[[zip file "/data/app/XXX.XXX.XXXX-2/base.apk"],nativeLibraryDirectories=[/data/app/XXX.XXX.XXXX-2/lib/arm, /data/app/XXX.XXX.XXXX-2/base.apk!/lib/armeabi, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.Instrumentation.newApplication(Instrumentation.java:993)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:847)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5748)
        at android.app.ActivityThread.-wrap2(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1716)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:185)
        at android.app.ActivityThread.main(ActivityThread.java:6615)

在Android studio环境下,使用的华为真机进行安装,安装正常.近期需要适配OPPO机型,一直安装失败,崩溃日志如上.但是打包安装,正常!!
虽然打包可以安装成功,但是很鸡肋!!调式多麻烦~~~

解决方式:
  • File --> Settings ------ Build,Execution,Deploymen ------ Instant Run
  • 将选项 Enable Instant Run to hot swap code/resource changes on deploy(deffault enabled) 设置为未选中状态
instant Run

Android studio 升级到2.0之后,出现了"instant Run"新功能.该功能可以热替换apk中的部分代码,提高安装效率:尽可能多的剔除不必要的步骤,然后提升必要步骤的速度。 四大属性:

  • Enable Instant Run to hot swap code/resource changes on deploy (default enabled) 默认处于开启状态,可能会导致
    Error:Execution failed for task ‘:app:transformClassesWithDexForDebug’ 异常
    参考instant Run 部署流程 <修改资源文件,热部署,温部署,冷部署>

  • Restart activity on code changes
    代码变动时重启 activity

  • Show toasts in the running app when changes are applied
    应用运行发生改变,在运行的应用程序中显示toasts

  • show Instant Run status notifications
    在notification里显示instant Run 的状态 应用可能会出现短暂空白界面

Instant Run编译和部署流程及原理参考博文:

https://www.jianshu.com/p/780eb85260b3
https://www.jianshu.com/p/2e23ba9ff14b

你可能感兴趣的:(解决OPPO手机在Android studio 环境下安装失败问题)