[英]Fat jar problem with Ktor and Kotlin multiplatform
I have a kotlin multiplatform project targeting Android and iOS and recently integrated ktor so that the shared library can load web resources. 我有一个针对Android和iOS的kotlin跨平台项目,最近集成了ktor,以便共享库可以加载Web资源。 It's working on iOS, but on Android I get this error:
它在iOS上正常工作,但在Android上却出现此错误:
java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/HttpClientJvmKt
I'm guessing my build pipeline is creating a jar that doesn't contain all the dependencies that ktor needs. 我猜我的构建管道正在创建一个不包含ktor需要的所有依赖项的jar。 So I'm trying to make a fat jar using the gradle shadow plugin (
com.github.jengelman.gradle.plugins:shadow:2.0.4
). 所以我正在尝试使用gradle shadow插件(
com.github.jengelman.gradle.plugins:shadow:2.0.4
)来制作一个胖子。 Here is my task: 这是我的任务:
task shadowJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
from kotlin.targets.android.compilations.main.output
def runtimeClasspath = kotlin.targets.android.compilations.main.runtimeDependencyFiles
configurations = [runtimeClasspath]
baseName = 'myproject-android-shadow'
exclude 'META-INF/*'
exclude '*.kotlin_metadata'
}
The jar jumped up from 300Kb to 8.5Mb. 广口瓶从300Kb跃升至8.5Mb。
The result is a new error: More than one file was found with OS independent path 'kotlinx/coroutines/CoroutineExceptionHandler.kotlin_metadata'
结果是一个新错误:
More than one file was found with OS independent path 'kotlinx/coroutines/CoroutineExceptionHandler.kotlin_metadata'
You'll notice I've tried excluding files from the shadowJar
, but it's not working. 您会注意到我已经尝试从
shadowJar
排除文件,但是它不起作用。
Although building a fat jar is possible, the easier solution was to include the missing dependencies ( ktor
and kotlinx
) in the app directly. 尽管可以构建胖子罐,但更简单的解决方案是将缺失的依赖项(
ktor
和kotlinx
)直接kotlinx
在应用程序中。 Then I had to add a bunch of exclude 'META-INF ...
statements in packagingOptions
. 然后,我必须在
packagingOptions
添加一堆exclude 'META-INF ...
语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.