无法使用'com.google.android.gms构建APK:播放服务:9.4.0'

Den*_*ach 4 java android google-play-services android-studio

我开始在我的小游戏中使用Google Play服务.就像导游说的那样,我加入compile 'com.google.android.gms:play-services:9.4.0'了我的build.gradle(Module: app).

由于这个改变,我无法构建我的apk,但我仍然可以在我的手机上运行它.我在构建apk时遇到以下错误:

错误:任务':app:transformClassesWithDexForDebug'的执行失败.com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中: 65536

FAILURE:构建因异常而失败.

出了什么问题:任务执行失败':app:transformClassesWithDexForDebug'.com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中: 65536尝试:使用--stacktrace选项运行以获取堆栈跟踪.使用--info或--debug选项运行以获取更多日志输出.

谢谢

Rea*_*hed 6

设置multiDexEnabled在你的build.gradle第一个.

defaultConfig {
    // ...
    multiDexEnabled true
}
Run Code Online (Sandbox Code Playgroud)

我想建议的另一件事就是不要使用com.google.android.gms:play-services:9.4.0.它包括您的项目可能不需要的所有服务.所以我想建议您dependencies更具体地设置.

例如,我不得不添加gcmplaces唯一的.

dependencies {
    //...
    compile 'com.google.android.gms:play-services-gcm:9.2.0'
    compile 'com.google.android.gms:play-services-places:9.2.0'
    compile 'com.android.support:multidex:1.0.1'
}
Run Code Online (Sandbox Code Playgroud)

您可以从这里找到具体要求.

来自链接的示例图像