Disable META-INF/* generation in gradle android library kotlin project

Viewed 6485

Good day. I've written a kotlin android library and uploaded it on bintray. But when I try to use it (via gradle compile) in some project, it fails to build with following errors:

> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/library_release.kotlin_module
File1: C:\Users\Charlie\.android\build-cache\2939fbc6b0336396c9c4912d615880645b2c729d\output\jars\classes.jar
File2: C:\Users\Charlie\OneDrive\Dev\Projects\AndroidStudio\MetuCardLib\demo\build\intermediates\bundles\default\classes.jar

I've looked up both of these .jar files and they both contained META-INF folder with library_release.kotlin_module file. But more importantly generated .aar (android archive published in bintray) contained this folder as well as this file. I've checked other decent bintray android libraries and they don't seem to include any META-INF files. However those that do include it (in most cases they contain license files) produce the same DuplicateFileException and the way to resolve it is to explicitly exclude them in use-project's gradle file.

What's the use of this library_release.kotlin_module file and how can I disable its generation during publishing? Because I don't want to explicitly exclude from every project which is using this library and I don't want to ask other developers to do so.

Here's the library's repo: https://github.com/arslancharyev31/Anko-ExpandableTextView/ And it's bintray repo: https://bintray.com/arslancharyev31/android/Anko-ExpandableTextView

3 Answers

I was able to resolve this by renaming modules to be uniquem when simpler module names conflicted.

EDIT: as we just learned the hard way - kotlin module name should only contain all filesystems supported characters.

We used ':' in the module name causing jar to contain file "company:product.kotlin_module". This will fail to extract on windows.

I thin in android realm currently(tested on Android gradle plugin 7.0.2)best solution would be to use android kotlin options section

android{
   kotlinOptions{
      moduleName = "com.example.mylibrary"
   }
}

It results in META-INF/com.example.mylibrary.kotlin_module - which should be sufficently unique content of aar

Related