Today I got an error when building the APK:

Multiple dex files define L/...

My scenario is that of a project with 2 modules: a core and an app. Both modules use a plugin named androiddevmetrics, which generate some code, including a class which has the same signature in both modules. The linking (APK generation) resulted in an obvious conflict.

My steps to solve this error are:

  1. Identify which package/module generates the error. The L/com/android/... will tell you exactly who the culpable is. In my case, the idea is to find who generates the duplicate file.

  2. In your main module's gradle file (app in my case) add, at the end:

    configurations.all {
        exclude module: 'module'
    }
    

In my case, the addition looked like:

configurations.all {
    resolutionStrategy {
        // Force our version of support-annotations, we have a conflict
        // between app and androidTest dependency resolution.
        force libraries.supportAnnotations
    }
    exclude module: 'androiddevmetrics-plugin'
}

Note: I only got this error when building the APK, which makes it quite annoying.

HTH,