致命异常:java.lang.NoClassDefFoundError:kotlin.coroutine.Corouti



在我们最近发布的out应用程序中,我们更频繁地获得Fatal Exception: java.lang.NoClassDefFoundError: kotlinx.coroutines.CoroutineExceptionHandlerImplKt,堆栈跟踪表明它在DexPathList中找不到该类。我们以前使用multidex,但最近我们添加了dex-guard in out应用程序,根据dex-guad文档,multidex由dex-guade处理。但据报道,这里发生了车祸,看起来dex防护装置处理不当。这是完整的堆叠架。如有任何帮助,我们将不胜感激。

Fatal Exception: java.lang.NoClassDefFoundError: kotlinx.coroutines.CoroutineExceptionHandlerImplKt
at kotlinx.coroutines.CoroutineExceptionHandlerImplKt.handleCoroutineExceptionImpl(:27)
at kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(:33)
at kotlinx.coroutines.DispatchedTask.handleFatalException(:146)
at kotlinx.coroutines.DispatchedTask.run(:115)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)


Caused by java.util.ServiceConfigurationError: kotlinx.coroutines.CoroutineExceptionHandler: Provider kotlinx.coroutines.android.AndroidExceptionPreHandler not found
at java.util.ServiceLoader.fail(ServiceLoader.java:233)
at java.util.ServiceLoader.access$100(ServiceLoader.java:183)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:373)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416)
at java.util.ServiceLoader$1.next(ServiceLoader.java:494)
at kotlin.sequences.SequencesKt___SequencesKt.toCollection(:786)
at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(:816)
at kotlin.sequences.SequencesKt___SequencesKt.toList(:807)
at kotlinx.coroutines.CoroutineExceptionHandlerImplKt.<clinit>(:23)
at kotlinx.coroutines.CoroutineExceptionHandlerImplKt.handleCoroutineExceptionImpl(:27)
at kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(:33)
at kotlinx.coroutines.StandaloneCoroutine.handleJobException(:192)
at kotlinx.coroutines.JobSupport.finalizeFinishingState(:229)
at kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath(:906)
at kotlinx.coroutines.JobSupport.tryMakeCompleting(:863)
at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(:828)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(:100)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(:46)
at kotlinx.coroutines.DispatchedTask.run(:106)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

Caused by java.lang.ClassNotFoundException: kotlinx.coroutines.android.AndroidExceptionPreHandler
at java.lang.Class.classForName(Class.java)
at java.lang.Class.forName(Class.java:453)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:371)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416)
at java.util.ServiceLoader$1.next(ServiceLoader.java:494)
at kotlin.sequences.SequencesKt___SequencesKt.toCollection(:786)
at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(:816)
at kotlin.sequences.SequencesKt___SequencesKt.toList(:807)
at kotlinx.coroutines.CoroutineExceptionHandlerImplKt.<clinit>(:23)
at kotlinx.coroutines.CoroutineExceptionHandlerImplKt.handleCoroutineExceptionImpl(:27)
at kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(:33)
at kotlinx.coroutines.StandaloneCoroutine.handleJobException(:192)
at kotlinx.coroutines.JobSupport.finalizeFinishingState(:229)
at kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath(:906)
at kotlinx.coroutines.JobSupport.tryMakeCompleting(:863)
at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(:828)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(:100)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(:46)
at kotlinx.coroutines.DispatchedTask.run(:106)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

Caused by java.lang.ClassNotFoundException: Didn't find class "kotlinx.coroutines.android.AndroidExceptionPreHandler" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.app.appname-dTd-4drfd8YfK38C73N7WQ==/base.apk", zip file "/data/app/com.app.appname-dTd-4drfd8YfK38C73N7WQ==/split_config.armeabi_v7a.apk", zip file "/data/app/com.app.appname-dTd-4drfd8YfK38C73N7WQ==/split_config.xhdpi.apk"],nativeLibraryDirectories=[/data/app/com.app.appname-dTd-4drfd8YfK38C73N7WQ==/lib/arm, /data/app/com.app.appname-dTd-4drfd8YfK38C73N7WQ==/base.apk!/lib/armeabi-v7a, /data/app/com.app.appname-dTd-4drfd8YfK38C73N7WQ==/split_config.armeabi_v7a.apk!/lib/armeabi-v7a, /data/app/com.app.appname-dTd-4drfd8YfK38C73N7WQ==/split_config.xhdpi.apk!/lib/armeabi-v7a, /system/lib, /product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.classForName(Class.java)
at java.lang.Class.forName(Class.java:453)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:371)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416)
at java.util.ServiceLoader$1.next(ServiceLoader.java:494)
at kotlin.sequences.SequencesKt___SequencesKt.toCollection(:786)
at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(:816)
at kotlin.sequences.SequencesKt___SequencesKt.toList(:807)
at kotlinx.coroutines.CoroutineExceptionHandlerImplKt.<clinit>(:23)
at kotlinx.coroutines.CoroutineExceptionHandlerImplKt.handleCoroutineExceptionImpl(:27)
at kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(:33)
at kotlinx.coroutines.StandaloneCoroutine.handleJobException(:192)
at kotlinx.coroutines.JobSupport.finalizeFinishingState(:229)
at kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath(:906)
at kotlinx.coroutines.JobSupport.tryMakeCompleting(:863)
at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(:828)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(:100)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(:46)
at kotlinx.coroutines.DispatchedTask.run(:106)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

希望Jake Wharton的回答会有所帮助。我们需要在proguard中添加这些。

https://github.com/Kotlin/kotlinx.coroutines/issues/214#issuecomment-362264056

vlc:对proguard数据的更多解释

https://code.videolan.org/videolan/vlc-android/-/blob/master/application/app/proguard-rules.pro#L79-87