我得到:错误:任务’:app:transformClassesWithDexForDebug’的执行失败。 制作Google地图应用时

我按照以下链接中的说明操作: https : //developers.google.com/maps/documentation/android-api/start使用Google Maps API创建一个简单的Android应用程序,但是当我运行应用程序时,我总是会遇到此错误我的手机:

错误:任务’: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

干净,看到仍有错误,如果是的话,

1.go到你的build.gradle文件。 添加multiDexEnabled true

  defaultConfig { multiDexEnabled true } 

2.在你的依赖项中添加compile 'com.android.support:multidex:1.0.1'

 dependencies { compile 'com.android.support:multidex:1.0.1' } 

3.在menifest中你的应用程序标签添加android:name="android.support.multidex.MultiDexApplication"

  

4.在启动活动中使用此覆盖方法

  @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } 

检查您是否依赖于整个Google Play服务,而不仅仅依赖于地图组件。 从文档中

如果您的应用程序中的方法引用数超过65K限制,您的应用程序可能无法编译。 在编译应用时,您可以通过仅指定应用使用的特定Google Play服务API而不是所有应用来缓解此问题。 有关如何执行此操作的信息,请参阅在可执行文件中选择性地编译API。

例如(使用上一个Play服务版本),在build.gradle更改此build.gradle

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

对此

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

如果添加其他Play服务模块,则需要将它们分别添加到build.gradle