【问题标题】:Cannot Build APK with 'com.google.android.gms:play-services:9.4.0'无法使用“com.google.android.gms:play-services:9.4.0”构建 APK
【发布时间】:2016-08-21 09:17:36
【问题描述】:

我开始在我的小游戏中使用 Google Play 服务。正如指南所说,我在build.gradle(Module: app) 中添加了compile 'com.google.android.gms:play-services:9.4.0'

自从那次更改后,我无法构建我的 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 选项运行以获得更多日志输出。

谢谢

【问题讨论】:

标签: java android android-studio google-play-services


【解决方案1】:

首先在您的build.gradle 中设置multiDexEnabled

defaultConfig {
    // ...
    multiDexEnabled true
}

我要推荐的另一件事是不要使用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'
}

您会发现具体要求from here

【讨论】:

  • 谢谢,“multiDexEnabled true”似乎有帮助。现在我只使用“compile 'com.google.android.gms:play-services:9.4.0'”。
猜你喜欢
  • 1970-01-01
  • 2019-04-15
  • 2022-01-10
  • 2022-01-15
  • 1970-01-01
  • 1970-01-01
  • 2018-11-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多