Disable META-INF/* generation in gradle android library kotlin project
The original purpose of .kotlin_module
files is to store the package parts mapping to the compiled class files. The compiler uses them to resolve top-level function calls in a library attached to the project. Also, Kotlin reflection uses the .kotlin_module
files to construct the top level members metadata at runtime. See more: Improving Java Interop: Top-Level Functions and Properties
Given that, you don't want to disable their generation in library projects, because it might break compilation against the libraries.
Instead, you can get rid of the duplicates by using packagingOptions
in your app build.gradle
, as said here:
android {
// ...
packagingOptions {
exclude 'META-INF/library_release.kotlin_module'
}
}
Note: excluding these files from an application APK interferes with reflection at runtime and therefore is is not the best solution either.
Another option is to use unique module names in your libraries:
compileReleaseKotlin.kotlinOptions.freeCompilerArgs += ["-module-name", "my.library.id"]
Choose the task that produces the output that is then packed into the AAR.
It might not be compileReleaseKotlin
, and also note that doing this might affect the tests compilation for this variant.
Or, what's more reliable, just choose unique Gradle module names, because the Kotlin module is named after the Gradle project.
I was able to resolve this by renaming modules to be uniquem when simpler module names conflicted.