将Google Play SDK添加到Android Studio

时间:2014-11-03 21:23:39

标签: android google-play-services

我尝试将谷歌播放服务添加到我的Android应用程序,但在编译时失败。

build.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.dbaile.app"
        minSdkVersion 15
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            zipAlign true
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/android-support-v4.jar')
    compile 'com.google.android.gms:play-services:6.1.71'
}

我有"谷歌播放服务" V21和" Google Repository"已安装V13 SDK。 gradle同步很棒。但是,当我去构建我的应用程序时,我有这个错误

  

错误:任务':app:dexDebug'执行失败。   com.android.ide.common.internal.LoggedErrorException:无法运行命令:       C:\ Users \ xxx \ AndroidSDK \ sdk \ build-tools \ android-4.4W \ dx.bat --dex --num-threads = 4 --output D:\ Documentos \ AndroidStudio \ DBaile \ app \ build \ intermediates \ dex \ debug D:\ Documentos \ AndroidStudio \ DBaile \ app \ build \ intermediates \ classes \ debug D:\ Documentos \ AndroidStudio \ DBaile \ app \ build \ intermediates \ dependency-cache \ debug D:\ Documentos \ AndroidStudio \ DBaile \ app \ build \ intermediates \ pre-dexed \ debug \ android-support-v4-f658d68db7f86c0620c54bffd0fd34f6b22d2055.jar D:\ Documentos \ AndroidStudio \ DBaile \ app \ build \ intermediates \ pre-dexed \ debug \ classes-249ec408a927bbcc7d8946543bc62d471a008cb8.jar D: \ Documentos \ AndroidStudio \ DBaile \ app \ build \ intermediates \ pre-dexed \ debug \ classes-ead47c12a26c5912b47a682a2596f1ab902eb577.jar D:\ Documentos \ AndroidStudio \ DBaile \ app \ build \ intermediates \ pre-dexed \ debug \ internal_impl-20.0.0 -7a914be15ad7ab72b458c1b59a579044ed2f61de.jar D:\ Documentos \ AndroidStudio \ DBaile \ app \ build \ intermediates \ pre-dexed \ debug \ support-annotations-20.0.0-97822065c059a8d0a913a12a4f49be833d40e415.jar   错误代码:       2   输出:       意外的顶级例外情况:       com.android.dex.DexException:多个dex文件定义了Landroid / support / v4 / accessibilityservice / AccessibilityServiceInfoCompat $ AccessibilityServiceInfoVersionImpl;           在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)

我的Android工作室版本为0.8.9,如果我删除该行"编译com.google.android.gms:play-services:6.1.71'"从应用程序编译的依赖项。 我的上一个播放服务版本是6.1.71,我在" SDK-PATH \ sdk \ extras \ google \ m2repository \ com \ google \ android \ gms \ play-services"

中看到

我按照说明操作,但我无法编译我的应用https://developer.android.com/google/play-services/setup.html

我该怎么办?

2 个答案:

答案 0 :(得分:0)

对于这个游戏版本,你需要使用这样的最新工具:

android {
    compileSdkVersion 21
    buildToolsVersion "21.0.0"

    defaultConfig {
        applicationId "com.dbaile.app"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            zipAlign true
        }
    }
}

答案 1 :(得分:0)

  

com.android.dex.DexException:多个dex文件定义了Landroid / support / v4 / accessibilityservice / AccessibilityServiceInfoCompat ..

compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/android-support-v4.jar')

问题是您要将支持库包括两次。从构建脚本中删除compile files('libs/android-support-v4.jar')行。