【问题标题】:Error:com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536错误:com.android.dex.DexIndexOverflowException:方法 ID 不在 [0, 0xffff] 中:65536
【发布时间】:2015-12-10 10:01:56
【问题描述】:

这是我的 build.gradle

android {
    ...
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        ...
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 2
        versionName "1.4.0"
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
    }
}

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile(name: 'identitytoolkit-api11', ext: 'aar')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile ([group: 'com.google.api-client', name: 'google-api-client-android', version: '1.21.0'])
    compile 'com.android.support:multidex:1.0.0'
}

我得到这个错误:

Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_80\bin\java.exe'' finished with non-zero exit value 2

我使用 google 端点,并使用 doc. 生成 API 库 并将jar文件包含到libs文件夹中。

我收到此错误,我什至不知道如何获取更多信息以及如何才能过来。

解决办法:

android {
    ...
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        ...
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 2
        versionName "1.4.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
    }
}

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile(name: 'identitytoolkit-api11', ext: 'aar')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.android.gms:play-services-maps:8.3.0'
    compile ([group: 'com.google.api-client', name: 'google-api-client-android', version: '1.21.0'])
}

【问题讨论】:

  • 您的应用程序是否扩展了MultiDexApplication
  • 不,我不这么认为。你能给我更多信息吗?
  • 我希望你已经看过这个stackoverflow.com/questions/18021901/… 检查你是否使用了重复的库?
  • 请看docs,你会发现multiDexEnabled = true并不是它唯一提到的东西。它继续说“在您的清单中,将 MultiDexApplication 类从 multidex 支持库添加到应用程序元素。”

标签: java android gradle dex


【解决方案1】:

就我而言,我只是替换了

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

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

因为包含了超过 65K 种方法。

【讨论】:

    【解决方案2】:

    defaultconfig 中检查 multidexenable true 并在您的应用程序中添加应用程序类,然后 --> 通过 MultidexApplication 扩展它并在应用程序的 oncreate 方法中使用以下行:-

    Multidex.install(this);
    

    编辑:-

    --> 还有另外一行,如果发生 heapsize 或 gcoverhead 超出问题,那么下面的行将对您有用:-

    dexOptions {
    javaMaxHeapSize "4g"
    }
    

    【讨论】:

    • 目前正确的解决方案是只包含所需的库。谢谢,如果达到或超过限制,我一定会考虑这种方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-19
    • 2014-09-14
    相关资源
    最近更新 更多