Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle Build: duplicate entry: META-INF/app_release.kotlin_module

I'm trying to build a release app via Android Studio > Generate Signed Bundle or APK > Android App Bundle > Release

However gradle fails with

: > Task :core:transformClassesWithMergeClassesForRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':core:transformClassesWithMergeClassesForRelease'.
> 1 exception was raised by workers:
  java.util.zip.ZipException: duplicate entry: META-INF/app_release.kotlin_module

In my build.gradle I've tried adding:

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

But it isn't making any difference whatsoever.

How do I fix this?

For extra context, it's a multi module project.

I have a core module, and an installed module which is declared in the core build.gradle with dynamicFeatures = [":installed"]

Thanks

like image 814
TomH Avatar asked Aug 13 '19 17:08

TomH


3 Answers

Build -> Clean Project Worked for me

like image 165
Zohab Ali Avatar answered Oct 17 '22 20:10

Zohab Ali


Please make sure all your dependencies are api or implementation, I have the flowing dependency grap.

meemo_sdk: api project(":gvoice")

app project:
implementation project(":gvoice") implementation project("meemo_sdk")

It complains "META-INF/gvoice_debug.kotlin_module" collision. After change api to implementation, it works!

like image 4
hoot Avatar answered Nov 09 '22 12:11

hoot


So I figured it out.

I pressed shift twice in Android studio (to open up the search everywhere dialog) and searched for app_release.kotlin_module

I saw two files, that were under two of my dependencies (which funnily enough were libraries that I had created!)

I opened up these library projects, and in the build.gradle file I had to add:

ext {
    PUBLISH_GROUP_ID = 'com.companyname'
    PUBLISH_ARTIFACT_ID = 'packagename'
}

android {
    ...
    compileOptions {
            kotlinOptions.freeCompilerArgs += ['-module-name', "$PUBLISH_GROUP_ID.$PUBLISH_ARTIFACT_ID"]
    }
}

Rebuilt the library projects with new versions, used these new versions in my other project, and it started compiling :)

like image 3
TomH Avatar answered Nov 09 '22 11:11

TomH