Multiple dex files define /BuildConfig, can't find the cause:

后端 未结 5 1567
不知归路
不知归路 2020-11-30 08:19

I\'m using the new gradle build system and I\'m facing the following problem:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex file         


        
相关标签:
5条回答
  • 2020-11-30 09:00

    In my case the similar error happened because there were 2 modules with the same package name in AndroidManifest.xml files. Using different package names in the modules solved the problem.

    Also the same thing happens when a library jar is being included twice (or more times) in several modules, as a dependency. In this case error message says about duplicate configs named after that library's package name. I solved it with including the library as a dependency in one module, and the second module had in dependencies the first module.

    0 讨论(0)
  • 2020-11-30 09:03

    Add this to your build.gradle:

    android {
        dexOptions {
            preDexLibraries = false
        }
    }
    

    I suppose this way there is no conflicting BuildConfig.java.

    EDIT:

    Why the above works: Android studio will first dex the libraries before dex-ing the app module. If you have a library module with the same package name as your app module, this 'pre-dexing' will result in the creation of a BuildConfig.java in the same package as for the app.

    Note: 'pre-dexing' will slow down your build process a bit so I suggest that you change your library's package name instead.

    0 讨论(0)
  • 2020-11-30 09:11

    If using NewRelic, then update it to at least 5.21.1.

    0 讨论(0)
  • 2020-11-30 09:17

    I was getting this problem signing my instant apk. The problem:

    bad module/app/manifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.stackoverflow">
    

    good: module/app/manifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.stackoverflow.app">
    

    Just adding the .app at the end of the package name

    0 讨论(0)
  • 2020-11-30 09:19

    For me, simply doing a clean on the project cleared this error.

    0 讨论(0)
提交回复
热议问题