Duplicate files copied in APK META-INF/library_release.kotlin_module

家住魔仙堡 提交于 2019-12-05 22:56:11

问题


I recently added two Android libraries through JitPack and I have the following error:

Duplicate files copied in APK META-INF/library_release.kotlin_module

I've cleared the cached and I've tried excluding the module using

exclude group: 'org.jetbrains'

and

exclude group: 'org.jetbrains.kotlin'

but neither seems to resolve the issue. Is there any way to stop the kotlin stdlib from being added through JitPack? Oddly, other libraries like DbFlow don't have this issue, though I don't see anything special about their setup (other than that it isn't through JitPack)


回答1:


You should add this to the build.gradle file of your app inside the android tag

packagingOptions {
    exclude 'META-INF/library_release.kotlin_module'
}



回答2:


As suggested in the post Kotlin M13 is out! by jetbrains:

Make sure these .kotlin_module files are not stripped by your packaging process.

So, we can't use exclude option to exclude this resource file from being generated.

As descripted in Kotlin M13 is out!, we should:

in Maven we use groupId and artifactId for module names, but you can say

<configuration>
    <moduleName>com.example.mymodule</moduleName>
</configuration>

in Gradle it’s project name + build task name, to customize:

compileKotlin {
    kotlinOptions.moduleName = "com.example.mymodule"    
}

This is my configuration for Android library project:

ext {
    GROUP_ID = 'custom.group.id'
    ARTIFACT_ID = 'artifactid'
}

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"

    compileOptions {
        kotlinOptions.freeCompilerArgs += ['-module-name', "$GROUP_ID.$ARTIFACT_ID"]
    }

    defaultConfig {
        ...
    }
    buildTypes {
        ...
    }
}

Resource file named META-INF/custom.group.id.artifactId.kotlin_module will be generated instead of META-INF/library_release.kotlin_module.No more duplicate files will be found.

You can read this post and this post for more information.




回答3:


After looking at other conflicts, it seems like the resolution is

packagingOptions {
    pickFirst 'META-INF/library_release.kotlin_module'
}

under android in the app gradle.

This allows the apk to build



来源:https://stackoverflow.com/questions/44509608/duplicate-files-copied-in-apk-meta-inf-library-release-kotlin-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!