NoClassDefFoundError 报错找不到资源

错误日志: E/CrashReport: java.lang.NoClassDefFoundError: Failed resolution of: Lio/rong/imkit/R$string; at io.rong.imkit.RongMessageItemLongClickActionManager.initCommonMessageItemLongClickActions(RongMessageItemLongClickActionManager.java:91) at io.rong.imkit.RongMessageItemLongClickActionManager.init(RongMessageItemLongClickActionManager.java:50) at io.rong.imkit.RongIM.initSDK(RongIM.java:140) at io.rong.imkit.RongIM.init(RongIM.java:209) at com.leoao.im.utils.LefitChatAppcontext.init(LefitChatAppcontext.java:73) at com.leoao.fitness.app.FitnessApplication.onCreate(FitnessApplication.java:88) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707) at android.app.ActivityThread.-wrap1(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) at android.os.Handler.dispatchMessage(Handler.java:102) 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 "io.rong.imkit.R$string" on path: DexPathList[[zip file "/data/app/com.leoao.fitness-1/base.apk"],nativeLibraryDirectories=[/data/app/com.leoao.fitness-1/lib/arm, /data/app/com.leoao.fitness-1/base.apk!/lib/armeabi, /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 io.rong.imkit.RongMessageItemLongClickActionManager.initCommonMessageItemLongClickActions(RongMessageItemLongClickActionManager.java:91) at io.rong.imkit.RongMessageItemLongClickActionManager.init(RongMessageItemLongClickActionManager.java:50) at io.rong.imkit.RongIM.initSDK(RongIM.java:140) at io.rong.imkit.RongIM.init(RongIM.java:209) at com.leoao.im.utils.LefitChatAppcontext.init(LefitChatAppcontext.java:73) at com.leoao.fitness.app.FitnessApplication.onCreate(FitnessApplication.java:88) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707) at android.app.ActivityThread.-wrap1(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) at android.os.Handler.dispatchMessage(Handler.java:102) 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: io.rong.imkit.R$string 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)
发布时间: 2018-03-09 10:52

回答:

问题原因:

用户没有把IMKit和IMLib作为module导入工程中,而是把IMKit和IMLib的代码直接拷贝到了app module中。SDK中对资源的引用是有包名的,所以这种方式会导致找不到资源,报NoClassDefFoundError。


解决方案:

将IMKit 和 IMLib 作为module 导入到工程中。

关于SDK的导入,可参考这里:

http://www.rongcloud.cn/docs/android.html#integration_import


我对此仍有疑问!继续追问