android java.lang.ClassNotFoundException:未找到类“io.ktor.client.HttpClientJvmKt”

nfeuvbwi  于 2023-04-04  发布在  Android
关注(0)|答案(2)|浏览(139)

我创建了一个Kotlin多平台项目来处理API。我将其集成到我的主项目中,但我遇到了以下异常。

java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/HttpClientJvmKt;

我试图在我的主项目中添加以下依赖项,但问题仍然存在。

dependencies {
implementation "io.ktor:ktor-client-core:1.3.2"
  implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.7"
  implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.20.0"
}

packagingOptions {
      exclude 'META-INF/kotlinx-io.kotlin_module'
      exclude 'META-INF/atomicfu.kotlin_module'
      exclude 'META-INF/kotlinx-coroutines-io.kotlin_module'
      exclude 'META-INF/kotlinx-coroutines-core.kotlin_module'
  }

我还是得到了这个问题。任何帮助将不胜感激。

d4so4syb

d4so4syb1#

在MPP中,您需要为每个目标声明依赖关系。例如:
commonMain需要具有上面使用的依赖项:

implementation "io.ktor:ktor-client-core:1.3.2"

androidMain需要有自己的依赖项:

implementation "io.ktor:ktor-client-okhttp:1.3.2"

iosMain还需要它自己的依赖项:

implementation "io.ktor:ktor-client-ios:1.3.2"

注意后缀ktor-client-xxxx。所以我的猜测是,您只需要将主项目中的依赖项替换为io.ktor:ktor-client-okhttp(或者您喜欢的任何客户端)。

8qgya5xd

8qgya5xd2#

请确保您已添加Android和iOS的特定依赖也。
对于安卓,

implementaion("io.ktor:ktor-client-android:2.2.1")

用于ios

implementation("io.ktor:ktor-client-darwin:2.2.1")

相关问题