[kotlin集成uikit] - 编译通过, 但是真机运行报错, 提示java.lang.ClassNotFoundException: cn.wildfirechat.moment.MomentClient

gaocunbin 2021-5-3 839

项目是kotlin的app, 集成uikit后, 原来的App类添加如下uikit初始化代码(init报错)

class App : MultiDexApplication() {     override fun onCreate() {

        ...

        override fun onCreate() {

        //IM relate        // 只在主进程初始化,否则会导致重复收到消息        if (getCurProcessName(this) == BuildConfig._APPLICATIONID) {             // 如果uikit是以aar的方式引入 ,那么需要在此对Config里面的属性进行配置,如:            // Config.IM_SERVER_HOST = "im.example.com"; 

          val wfcUIKit = WfcUIKit.getWfcUIKit()           wfcUIKit.init(this)           wfcUIKit.appServiceProvider = AppService.Instance()          //PushService.init(this, BuildConfig.APPLICATION_ID)           MessageViewHolderManager.getInstance().registerMessageViewHolder(            LocationMessageContentViewHolder::class.java,            R.layout._conversation_item_locationsend,            R.layout._conversation_item_locationsend )            setupWFCDirs() }

    }

运行报错详情

W/System.err: java.lang.ClassNotFoundException: cn.wildfirechat.moment.MomentClient W/System.err:     at java.lang.Class.classForName(Native Method)        at java.lang.Class.forName(Class.java:454)        at java.lang.Class.forName(Class.java:379)        at cn.wildfire.chat.kit.WfcUIKit.initMomentClient(WfcUIKit.java:159)        at cn.wildfire.chat.kit.WfcUIKit.init(WfcUIKit.java:86)        at com.cosmo.cosmooa.App.onCreate(App.kt:136)        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1208)        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6986)        at android.app.ActivityThread.access$1700(ActivityThread.java:274) W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2093)        at android.os.Handler.dispatchMessage(Handler.java:106)        at android.os.Looper.loop(Looper.java:233)        at android.app.ActivityThread.main(ActivityThread.java:8010)        at java.lang.reflect.Method.invoke(Native Method)        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)    Caused by: java.lang.ClassNotFoundException: Didn't find class "cn.wildfirechat.moment.MomentClient" on path: DexPathList[[zip file "/data/app/u245J9MIauD24L7fPmO54w==/com.cosmo.cosmooa-a-_BNfYAB4-I_z3Dc06n6g==/base.apk"],nativeLibraryDirectories=[/data/app/u245J9MIauD24L7fPmO54w==/com.cosmo.cosmooa-a-_BNfYAB4-I_z3Dc06n6g==/lib/arm, /data/app/~~u245J9MIauD24L7fPmO54w==/com.cosmo.cosmooa-a-_BNfYAB4-I_z3Dc06n6g==/base.apk!/lib/armeabi-v7a, /system/lib, /system/system_ext/lib]]        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)        at java.lang.ClassLoader.loadClass(ClassLoader.java:379) W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:312)     ... 16 more W/m.cosmo.cosmoo: Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setUseSessionTickets(Z)V (greylist-max-q,core-platform-api, reflection, allowed)    Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setHostname(Ljava/lang/String;)V (greylist-max-q,core-platform-api, reflection, allowed)    Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->getAlpnSelectedProtocol()[B (greylist-max-q,core-platform-api, reflection, allowed)    Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (greylist-max-q,core-platform-api, reflection, allowed) W/m.cosmo.cosmoo: Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (greylist,core-platform-api, reflection, allowed)    Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (greylist,core-platform-api, reflection, allowed)    Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (greylist,core-platform-api, reflection, allowed) D/WfcUIKit: init end

最新回复 (2)
  • x86 2021-5-3
    引用 2
    java.lang.ClassNotFoundException: cn.wildfirechat.moment.MomentClient

    这个错误不影响,应当是其他问题导致的,请看看还有没有其他错误日志。

    最好通过adb logcat 抓取日志,这样更完整。
  • gaocunbin 2021-5-4
    引用 3
    已经找到了, 是因为集成自 WfcBaseActivity 的 Activity,布局里面一定要包含toolbar, 没有的话, 会报下面的错误, 导致加载失败
         Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context androidx.appcompat.widget.Toolbar.getContext()' on a null object reference
            at cn.wildfire.chat.kit.WfcBaseActivity.onCreate(WfcBaseActivity.java:48)
返回