Disable META-INF/* generation in gradle android project


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


This file contains Kotlin metadata and is required to make the entire API of your library (including top-level functions, nullability and other information that cannot be fully represented in Java) to be available to Kotlin clients. I assume that other decent android libraries you’ve checked are not written in Kotlin.


Indeed, they are not written in kotlin, but my point was that when libraries include META-INF/* in their packages, it may cause projects using those libraries fail to build. Nevertheless, are there any solutions other than explicitly excluding this file in use-projects (which somehow works, even though this file turns out to be required to make the entire API)?


This seems to be more appropriately fixed by aapt (now Kotlin support is official) as they are needed in the aar, but can be safely ignored in the dexed version (that doesn’t do libraries).


Do you suggest that it should rather be reported to google?


The name of the .kotlin_module file comes from the name of the Gradle module. One good way to avoid this problem is not to use the name “library” for all of your library modules.


Thanks, that is what I’m going to do for now. But I still think that this is quite inconvenient, since it’s not mentioned anywhere in the official docs that we shouldn’t apply generic names for gradle modules for this very reason. I wonder, whether I should submit an issue to google about that, so that aapt would automatically exclude *.kotlin_module files from building, or is this the desired behavior?