ComponentizationApp icon indicating copy to clipboard operation
ComponentizationApp copied to clipboard

点击JUMP按钮出错,程序崩溃,无法切换到另一个界面

Open want-gone opened this issue 8 years ago • 5 comments

10-24 08:12:40.299 5268-5268/cn.easydone.componentizationapp E/AndroidRuntime: FATAL EXCEPTION: main Process: cn.easydone.componentizationapp, PID: 5268 java.lang.NoClassDefFoundError: Failed resolution of: Lcn/easydone/componentizationlibrary/LibraryActivity; at cn.easydone.componentizationapp.MainActivity$2.onClick(MainActivity.java:35) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.ClassNotFoundException: Didn't find class "cn.easydone.componentizationlibrary.LibraryActivity" on path: DexPathList[[zip file "/data/app/cn.easydone.componentizationapp-1/base.apk"],nativeLibraryDirectories=[/data/app/cn.easydone.componentizationapp-1/lib/x86_64, /vendor/lib64, /system/lib64]] 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 cn.easydone.componentizationapp.MainActivity$2.onClick(MainActivity.java:35)  at android.view.View.performClick(View.java:5198)  at android.view.View$PerformClick.run(View.java:21147)  at android.os.Handler.handleCallback(Handler.java:739)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  Suppressed: java.lang.ClassNotFoundException: cn.easydone.componentizationlibrary.LibraryActivity 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) ... 11 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available 10-24 08:12:40.332 1187-1187/? E/EGL_emulation: tid 1187: eglCreateSyncKHR(1315): error 0x3004 (EGL_BAD_ATTRIBUTE)

want-gone avatar Oct 24 '16 08:10 want-gone

@want-gone 如果 gradle.properties 里的 isDebug 为 true ,每个 module 都是 Application 了,点击跳转的时候,会找不到 cn.easydone.componentizationlibrary.LibraryActivity ,所以会 crash ,这里只是写了个 demo ,保证编译通过,实际项目里要自己去处理的。

只有isDebug 为 false ,子 module 为 Library ,这样在运行期才会找得到 cn.easydone.componentizationlibrary.LibraryActivity

这也是组件化思想的核心,在 debug 的时候,每个 module 都是 Application ,而在 release 的时候,子 module 才是 Library

cxyxlxdm avatar Oct 24 '16 09:10 cxyxlxdm

ok,我改成isDebug=false之后就可以运行了,另外请教一下componentizationlibrary里面的outputs里的文件是配置生成的吗?有什么作用?为什么要这么做?

want-gone avatar Oct 24 '16 13:10 want-gone

@want-gone isDebug = true 的时候,app 和 componentizationlibrary 都是 Application ,都是可以安装的。在 componentizationlibrary 的 build.gradle 里有一段代码,可以生成一个 jar ,在 app 里 provided 了这个 jar ,保证 isDebug = true 时, 编译 app 能通过(但是运行时还是会报类找不到)。这样做只是为了保证正常编译,平时开发的时候要用其他方式去做跳转。

cxyxlxdm avatar Oct 24 '16 13:10 cxyxlxdm

你的意思就是说当isDebug = true的时候可以把各个模块当做不同的Application来调试,再正式发布的时候把isDebug设置为false后其他模块就可以像library一样依赖在一起对吗?

want-gone avatar Oct 24 '16 13:10 want-gone

是的。

cxyxlxdm avatar Oct 24 '16 16:10 cxyxlxdm