Android Studio Gradle error “Multiple dex files define…”

半腔热情 提交于 2019-11-28 10:02:11

Now they split bolts-android into bolts-applinks and bolts-tasks .so you need exclude both from the gradle build

compile ('com.facebook.android:facebook-android-sdk:4.10.0'){
exclude group: 'com.parse.bolts',
        module: 'bolts-tasks'
exclude group: 'com.parse.bolts',
        module: 'bolts-applinks';}

This works perfectly for me !!!!

For me, I was adding Facebook SDK as a project, and set it as dependencies.

However, the exclude work after i switching to use the maven source.

I think it is for maven only, not for project dependencies? (please provide correct info if someone know about this)

In other word, you can now delete the Facebook SDK project and files.

remember to add

repositories {
    mavenCentral()
}

if you weren't using maven.

So the build.gradle look like this, I commented out the project way.

repositories {
    mavenCentral()
}
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':google-play-services_lib')
    compile ('com.facebook.android:facebook-android-sdk:3.23.0'){
        exclude module: 'bolts-android'
        exclude module: 'support-v4'
    }
//    compile (project(':FacebookSDK')){
//        exclude module: 'bolts-android'
//        exclude module: 'support-v4'
//    }
    compile (project(':UserVoiceSDK')){ exclude module: 'support-v4' }
}

I've had a similar problem. This was really frustrating for me because everything worked fine and suddenly it broke for no reason.

The issue is hinted in duplicate entry: bolts/AggregateException.class. It's a clash of the Bolts library, used by Facebook and Parse.

For me, the problem lay in these two lines:

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.parse.bolts:bolts-android:1.1.4'

I had downloaded the Parse libraries and put them in the /libs/ folder. The problem was that there was another bolts-android file in that folder.

The solution is to delete that library and keep the compile 'com.parse.bolts:bolts-android:1.1.4' part.

Alternative problem

In my case, I used compile 'com.parse.bolts:bolts-android:1.+' instead of a specific version. This always takes the latest version. So when bolts upgraded to version 1.2.0, the thing just seemed to randomly break because all of a sudden the version in the /libs/ folder and the latest version no longer aligned.

Best practice is to avoid 1.+ style versioning and just keep checking and updating to the latest version every now and then.

Hope this helps someone.

no need to remove any jar files. In Gradle file we have written these two lines

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.parse.bolts:bolts-android:1.1.4'

just remove

compile fileTree(dir: 'libs', include: ['*.jar'])

because we are compiling all the jar files and then again including the bolts to compile due to which the error is shown

in my case the i had added a .jar in the library code . the library in turn gets used in the main app . the dex was still in the cache file even if i had cleaned my project and installed it . To be sure in the main app you can check the count of the library . The cache file is "Project -> build -> dex-cache -> cache.xml" . If you have multiple counts of the library then u need to do this in Android Studio -> File -> invalidate cache / restart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!