这个问题是由于Ktor client的一个NativeUtilsJvmKt类没有被正确引用导致的。解决方法是在build.gradle文件中加入以下依赖:
implementation "io.ktor:ktor-client-okhttp:$ktor_version"
implementation "io.ktor:ktor-client-core:$ktor_version"
其中$ktor_version指的是Ktor版本号,在项目的build.gradle文件中添加类似如下的依赖配置:
buildscript {
ext.kotlin_version = "1.5.21"
ext.compose_version = '1.1.0-beta01' // <<<< add this line
ext.ktor_version = "1.6.4" // <<<< add this line
// ...
}
// ...
dependencies {
implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation "com.google.android.material:material:$material_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$compose_version" // <<<< add this line
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
// ...
implementation "io.ktor:ktor-client-okhttp:$ktor_version" // <<<< add this line
implementation "io.ktor:ktor-client-core:$ktor_version" // <<<< add this line
// ...
}
然后重新构建应用程序即可解决此问题。