使用旧版 Ktor 的 Android 库会导致 NoClassDefFoundError

Android library using old Ktor version causes NoClassDefFoundError

提问人:Mox4 提问时间:8/2/2023 更新时间:8/2/2023 访问量:60

问:

我正在尝试将 TelemetryDeck 分析添加到使用 Ktor 2.0.0 的 Android 应用程序中,但在启动应用程序时出现错误,因为 TelemetryDeck 的 SDK 使用 Ktor 1.6.7

完整错误:

java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/features/HttpClientFeature;
                    at com.telemetrydeck.sdk.TelemetryClient.<init>(TelemetryClient.kt:18)
                    at com.telemetrydeck.sdk.TelemetryManager.send-gIAlu-s(TelemetryManager.kt:74)
                    at com.telemetrydeck.sdk.TelemetryBroadcastTimer$start$1$1.invokeSuspend(TelemetryBroadcastTimer.kt:48)
                    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
                    at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
                    at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:100)
                    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
                    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
                    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
                    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
                    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@b96a820, Dispatchers.IO]
                 Caused by: java.lang.ClassNotFoundException: Didn't find class "io.ktor.client.features.HttpClientFeature" on path: DexPathList[[dex file "/data/data/com.mmm.example.debug/code_cache/.overlay/base.apk/classes10.dex", zip file "/data/app/~~3WLnofo17mW-pHZeEjjPaA==/com.mmm.example.debug-BXbaTkrc1DYfN-kyN2QXsg==/base.apk"],nativeLibraryDirectories=[/data/app/~~3WLnofo17mW-pHZeEjjPaA==/com.mmm.example.debug-BXbaTkrc1DYfN-kyN2QXsg==/lib/arm64, /data/app/~~3WLnofo17mW-pHZeEjjPaA==/com.mmm.example.debug-BXbaTkrc1DYfN-kyN2QXsg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]]
                    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                    ... 11 more

有没有办法修复它,或者我必须等到他们发布使用 Ktor 2.0.0 的新版本?

Android kotlin noclassdeffounderror ktor ktor-client

评论


答:

0赞 matze8426 8/2/2023 #1

我在将 java 项目从 jdk 12 更新到 17 时遇到了类似的问题。就我而言,我还必须提升相应的库来修复错误。

但通常,当代码依赖于一个类文件并且它在编译时存在但在运行时找不到时,就会导致这种情况。您是否在寻找构建时间和运行时类路径的差异?

评论

0赞 Community 8/8/2023
正如目前所写的那样,你的答案尚不清楚。请编辑以添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。您可以在帮助中心找到有关如何写出好答案的更多信息。