错误:com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中:65536

时间:2015-12-10 10:01:57

标签: java android gradle dex

这是我的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'])
}

2 个答案:

答案 0 :(得分:5)

就我而言,我刚刚更换了

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

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

因为包含超过65K的方法。

答案 1 :(得分:1)

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

Multidex.install(this);

修改: -

- >还有另一条线,如果堆积或gcoverhead超出问题发生,那么下面的行将对你有用: -

dexOptions {
javaMaxHeapSize "4g"
}