In Android Studio Error:Execution failed for task

2019-08-10 03:53发布

问题:

Here i am work on twitter integration (login with twitter) with "Fabric Plugin" in android studio 1.1.0

Error:Execution failed for task ':app:dexDebug'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command: /home/dhruv/Dhruv/sdk/build-tools/21.0.2/dx --dex --no-optimize --output /home/dhruv/FestEvo/app/build/intermediates/dex/debug --input-list=/home/dhruv/FestEvo/app/build/intermediates/tmp/dex/debug/inputList.txt Error Code: 2 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lcom/google/gson/JsonSerializer; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302) at com.android.dx.command.dexer.Main.run(Main.java:245) at com.android.dx.command.dexer.Main.main(Main.java:214) at com.android.dx.command.Main.main(Main.java:106)

This is build.gradle: file

buildscript {
    repositories {
       // jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.+'
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories{
    flatDir{
        dirs 'libs'
    }
    //jcenter()
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.0.2"

    defaultConfig {
        applicationId "com.festevo.devtesting"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    //compile 'com.android.support:appcompat-v7:21.0.3'

    //compile 'com.spotify.sdk:spotifysdk:1.0.0-beta6@aar'
    compile 'com.spotify.sdk:spotifysdk:1.0.0-beta8@aar'
    // NOTE: Version must match!
   // compile 'com.android.support:support-v4:+'

    compile project ('libraries:FacebookSDK')
    compile project ('libraries:simple-crop-image-lib')
    compile project ('libraries:SlidingMenu')
    compile project ('libraries:nineoldandroids')
    compile project ('libraries:google-play-services_lib')
    compile('com.twitter.sdk.android:twitter:1.3.2@aar') {
        transitive = true;
    }

}

Please suggest me how to solve my problem thanks you in advance:)

回答1:

Had this error as well. The key is here: "Multiple dex files define Lcom/google/gson/JsonSerializer;"

Most likely you are referencing more than one version of gson in your app. So you can right click on your Project Module -> Open Module Settings -> Dependencies tab and any remove any extra gson versions.

If you want a clearer picture, you can go into terminal in Android Studio and do grep -r gson to see all references.