drakeet / MultiType

Flexible multiple types for Android RecyclerView.
Apache License 2.0
5.76k stars 751 forks source link

More than one file was found with OS independent path 'META-INF/library_release.kotlin_module' #283

Closed litangyu closed 5 years ago

litangyu commented 5 years ago
 FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDefaultDebug'.
> More than one file was found with OS independent path 'META-INF/library_release.kotlin_module'

When i use this library. I can not build apk. Gradle throw exception like it.

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

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.

I think it will fix this problem.

litangyu commented 5 years ago

How to reproduce it?

1.Create new project. 2.Add Multitype 4.0.0 and Notify to dependencies 3.Run to your devices 4.The exception will reproduce.