使用AS run的时候都可以正常运行,但是将build下的apk直接进行安装则报错:
10-25 20:43:22.174 16451-16451/cn.coderyu.test E/AndroidRuntime: FATAL EXCEPTION: main
Process: cn.coderyu.test, PID: 16451
java.lang.RuntimeException: Unable to instantiate application cn.coderyu.test.app.MyApplication: java.lang.ClassNotFoundException: Didn't find class "cn.coderyu.test.app.MyApplication" on path: DexPathList[[zip file "/data/app/cn.coderyu.test-1/base.apk"],nativeLibraryDirectories=[/data/app/cn.coderyu.test-1/lib/arm, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:589)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5044)
at android.app.ActivityThread.access$1600(ActivityThread.java:187)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1645)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5869)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1019)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:814)
Caused by: java.lang.ClassNotFoundException: Didn't find class "cn.coderyu.test.app.MyApplication" on path: DexPathList[[zip file "/data/app/cn.coderyu.test-1/base.apk"],nativeLibraryDirectories=[/data/app/cn.coderyu.test-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newApplication(Instrumentation.java:992)
at android.app.LoadedApk.makeApplication(LoadedApk.java:584)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5044)
at android.app.ActivityThread.access$1600(ActivityThread.java:187)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1645)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5869)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1019)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:814)
Suppressed: java.lang.ClassNotFoundException: cn.coderyu.test.app.MyApplication
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
说是找不到入口Application类,于是怀疑这个包有问题,看了一下果然比正常的release包要小很多,因此怀疑是instant run的问题,于是关闭instant run,删除build目录下原来的apk,重新run一遍,可以正常运行,使用build目录下的apk直接安装,也可以正常运行,并且包的大小也正常了~