我无法在android studio 0.4.6的项目中添加google-play-services.jar

时间:2014-03-07 23:03:58

标签: android-studio google-play-services

有我的行为: 1)从我项目中“libs”目录中的sdk目录添加文件google-play-services.jar。 2)在我的项目(不在解决方案中)的build.gradle中添加依赖项“编译文件('libs / google-play-services.jar')”。 同步项目已成功完成,但在运行应用程序后,我看到了错误:

任务执行失败':TestMcSiRun:dexDebug'。

  

com.android.ide.common.internal.LoggedErrorException:无法运行命令:       D:\ SDK \ sdk \ sdk \ build-tools \ 19.0.2 \ dx.bat --dex --output C:\ Users \ MCSIMUSIC \ AndroidStudioProjects \ TestMcSiRun \ TestMcSiRun \ build \ dex \ debug C:\ Users \ MCSIMUSIC \ AndroidStudioProjects \ TestMcSiRun \ TestMcSiRun \ build \ classes \ debug C:\ Users \ MCSIMUSIC \ AndroidStudioProjects \ TestMcSiRun \ TestMcSiRun \ build \ dependency-cache \ debug C:\ Users \ MCSIMUSIC \ AndroidStudioProjects \ TestMcSiRun \ TestMcSiRun \ build \ pre-dexed \调试\类-2b5c8c8b2a23992eb9323b131861658b5a6c4592.jar C:\用户\ MCSIMUSIC \ AndroidStudioProjects \ TestMcSiRun \ TestMcSiRun \建立\预dexed \调试\类-442363482f1c8783c26a5e38b6ee593d3f54a067.jar C:\用户\ MCSIMUSIC \ AndroidStudioProjects \ TestMcSiRun \ TestMcSiRun \建立\预-dexed \ debug \ google-play-services-da249c1d3c777ecbc074adaa5e3cd781485d270c.jar C:\ Users \ MCSIMUSIC \ AndroidStudioProjects \ TestMcSiRun \ TestMcSiRun \ build \ pre-dexed \ debug \ support-v4-18.0.0-00a4eeb2a43f491f4d8b1d7286b2ebe4b40b994e.jar   错误代码:       2   输出:       意外的顶级例外情况:       com.android.dex.DexException:多个dex文件定义Lcom / google / ads / AdRequest $ ErrorCode;           在com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)           在com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)           在com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)           在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)           在com.android.dx.merge.DexMerger.merge(DexMerger.java:188)           在com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)           在com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)           在com.android.dx.command.dexer.Main.run(Main.java:230)           在com.android.dx.command.dexer.Main.main(Main.java:199)           在com.android.dx.command.Main.main(Main.java:103)

我做错了什么? 我的build.gradle:

apply plugin: 'android'


android {
    compileSdkVersion 18
    buildToolsVersion '19.0.2'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 15
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
            'proguard-rules.txt'
        }
    }
}
dependencies {
    compile 'com.android.support:appcompat-v7:18.0.+'
    compile 'com.google.android.gms:play-services:4.0.30'
    //compile files('libs/google-play-services.jar')
}

1 个答案:

答案 0 :(得分:1)

你有这样的事情:

dependencies {
    compile 'com.google.android.gms:play-services:4.0.30'
    compile files('libs/google-play-services.jar')
}

但这包括图书馆两次。这就足够了:

dependencies {
    compile 'com.google.android.gms:play-services:4.0.30'
}

它将正确编译,并且它将在您的APK中包含正确的库。