我创建了一个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'
}
我还是得到了这个问题。任何帮助将不胜感激。
2条答案
按热度按时间d4so4syb1#
在MPP中,您需要为每个目标声明依赖关系。例如:
commonMain
需要具有上面使用的依赖项:androidMain
需要有自己的依赖项:iosMain
还需要它自己的依赖项:注意后缀
ktor-client-xxxx
。所以我的猜测是,您只需要将主项目中的依赖项替换为io.ktor:ktor-client-okhttp
(或者您喜欢的任何客户端)。8qgya5xd2#
请确保您已添加Android和iOS的特定依赖也。
对于安卓,
用于ios