DexIndexOverflowException

DexIndexOverflowException

本文介绍了更新到最新的 appcompat 和支持库后出现 DexIndexOverflowException 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 gradle 使用以下设置:

I'm using the below settings through gradle:

compileSdkVersion 21
ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.0.2
ANDROID_BUILD_SDK_VERSION=21

我的 gradle 文件中还有以下设置:

I also have the following settings in my gradle file:

compile 'com.android.support:support-annotations:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:support-v4:21.0.0'

我总是收到错误UNEXPECTED TOP LEVEL EXCEPTION.
但是,当我将 21.0.0 设为 20.0.0 时,它工作正常……但我无法访问任何 Android API 21 选项.我在这里做错了吗?如何在没有此异常的情况下编译它?除了其他年级项目(facebook 等)之外,我在其他任何地方都没有支持 jar.

I always get the error UNEXPECTED TOP LEVEL EXCEPTION.
But when I make the 21.0.0 to 20.0.0 it works fine...but i'm not able to access any of the Android API 21 options. Is there something i'm doing wrong here? How do I get it to compile without this exception? I do not have the support jars anywhere else outside of other grade projects (facebook etc.).

这是完整的堆栈跟踪:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
    at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
    at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:283)
    at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
    at com.android.dx.command.dexer.Main.run(Main.java:245)
    at com.android.dx.command.dexer.Main.main(Main.java:214)
    at com.android.dx.command.Main.main(Main.java:106)

推荐答案

此消息听起来像是您的项目太大.

This message sounds like your project is too large.

你的方法太多了.dex 只能有65536 个方法.

You have too many methods. There can only be 65536 methods for dex.

由于 gradle 插件 0.14.0 和构建工具 21.1.0,您可以使用 multidex 支持.

Since the gradle plugin 0.14.0 and the Build Tools 21.1.0 you can use the multidex support.

只需在 build.gradle 中添加这些行:

Just add these lines in the build.gradle:

android {

    defaultConfig {
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

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

也在你的 Manifest 中添加 MultiDexApplication 类从 multidex 支持库到应用程序元素

Also in your Manifest add the MultiDexApplication class from the multidex support library to the application element

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

如果您使用自己的 Application 类,请将父类从 Application 更改为 MultiDexApplication.

If you are using a own Application class, change the parent class from Application to MultiDexApplication.

这篇关于更新到最新的 appcompat 和支持库后出现 DexIndexOverflowException 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 03:49