在添加Google Play服务时出现了意想不到的顶级异常

时间:2015-04-20 07:38:21

标签: android google-plus google-play-services

我正在开发一个Android应用程序,我正在整合Google Plus登录。为此,我已将google play服务库添加到我的项目中。当我运行我的应用程序时,它会给我以下错误:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;
    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:303)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)

这是我的build.gradle文件:

    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"

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

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:22.0.0'
        compile 'com.google.android.gms:play-services:7.0.0'
        //compile 'com.google.android.gms:play-services-plus:7.0.0'
        //compile 'com.google.android.gms:play-services-identity:7.0.0'
        compile files('E:/google plus/GooglePlus/libs/google-play-services.jar')
    }

我在stackoverflow上经历了很多问题,但没有得到解决方案。我的build.gradle文件有什么问题.. ??

1 个答案:

答案 0 :(得分:2)

错误非常明显。您正在两次编译Google Play服务。应该是:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services:7.0.0'
    //compile 'com.google.android.gms:play-services-plus:7.0.0'
    //compile 'com.google.android.gms:play-services-identity:7.0.0'
    //compile files('E:/google plus/GooglePlus/libs/google-play-services.jar')
}