【问题标题】:Getting error while running Android Studio Default **Map Application**运行 Android Studio Default **Map Application** 时出错
【发布时间】:2016-12-26 16:47:10
【问题描述】:

我正在为地图应用程序运行 android studio 模板代码。但是出现错误。我点击这个链接只是为了运行一个简单的地图应用程序。

https://developers.google.com/maps/documentation/android-api/utility/setup

以下是错误。

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

我的问题是为什么我会收到此错误,因为我按照上面官方 Google 链接提供的所有步骤操作。

这是我的应用程序 Gradle 代码。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "app.com.example.android.mapsnew"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    // compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
    testCompile 'junit:junit:4.12'
}

这是此错误的图像。

亲切的问候, 缩略词。

【问题讨论】:

  • 谢谢@KNeerajLal 其实我正在关注这个官方链接。 >>developers.google.com/maps/documentation/android-api/utility‌​/... 那么为什么在我的情况下这会出错。它应该按照链接中的说明工作。您所指的答案是告诉做很多与 MultiDexing 相关的程序。希望你明白我的意思。
  • build.gradle 中的一个或多个依赖项导致您的 apk 中的方法数量超出 65k 方法限制。您可用的选项是,删除导致此或 Multidex 的依赖项。
  • 在你的情况下,我认为删除 compile 'com.google.android.gms:play-services:9.4.0' 会起作用。
  • 我已经尝试过了,删除了 'compile 'com.google.android.gms:play-services:9.4.0'' 。它没有用并导致更多错误。我想说的是,除了来自谷歌的 ApiKey 之外,我没有在代码中添加任何内容。这应该可以正常工作,因为我正在学习教程:link

标签: android android-studio google-maps-api-3


【解决方案1】:

在你的 build.gradle(Module:app) 文件中添加multiDexEnabled true

defaultConfig {
    multiDexEnabled true
}

【讨论】:

    【解决方案2】:

    The number of method references in your app exceeds the 65K limit, your app may fail to compile. You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them

    这就是您的应用程序中的问题。您可能不需要所有的 google play 服务。所以不要完全删除这条线

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

    在你在 cmets 中提到的 gradle-app 文件中,而不是添加那一行

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

    还有另一种解决方法,您可以让您的应用甚至支持所有 google play 服务,您可以关注 this link.

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2013-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-23
      • 1970-01-01
      • 2021-03-03
      • 2019-12-12
      相关资源
      最近更新 更多