当我添加 google 映射 api 时,.dex 文件超过 64k

.dex file exceed 64k when i added google maps api

我在 Intellij Idea 2016.2.2 中创建了一个 google 映射 activity,但是当我添加我的 api 键时 64k limit exceed 发生错误。我知道我们必须在 build.gradle 中启用 multidex true 但问题是我的 'build.gradle' 文件看起来像这样:

buildscript {
 repositories {
   jcenter()
  } 
 dependencies {
   classpath 'com.android.tools.build:gradle:2.0.0'

   // NOTE: Do not place your application dependencies here; they belong
   // in the individual module build.gradle files }  } allprojects {repositories {
   jcenter()
  }  
}  
task clean(type: Delete) {  delete rootProject.buildDir }

(抱歉代码对齐混乱)

1- 所以这里没有 defaultConfig 当我尝试手动添加它时它给了我错误。

2- 当我在清单中添加这一行时

"android:name="android.support.multidex.MultiDexApplication">"

再次出错。

我试过这里写的所有东西https://developer.android.com/studio/build/multidex.html 在其他问题中,人们询问了这个问题,但没有任何效果。 任何人都知道如何解决这个问题?我会很感激:)

如果您的项目包含一个模块(即 app),您应该有两个 build.gradle 文件:

第一个是针对您的项目(即您从中发布代码段的项目),您不应在其中添加依赖项(如注释行中所述),也不应更改 defaultConfig 那里

另一个用于您的 app 模块。这是您应该添加依赖项并设置 multiDexEnabled true 的地方。你应该看到 defaultConfig 块在那里。

您也可以尝试只添加 Google Play 服务中您需要的部分,而不是全部添加到依赖项中。 像这样:编译'com.google.android.gms:play-services-maps:9.4.0' 这将使您不超过限制