更新到最新的appcompat和支持库后DexIndexOverflowException问题 [英] DexIndexOverflowException issue after updating to latest appcompat and support library
问题描述
我通过使用下面的设置摇篮
:
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
我也有以下设置在我的摇篮文件:
编译com.android.support:support-annotations:21.0.0
编译com.android.support:appcompat-v7:21.0.0
编译com.android.support:support-v4:21.0.0
我总是得到错误意外的TOP级的异常
。
但是,当我做了 21.0.0
到 20.0.0
它工作得很好...但我不能访问任何Android的API 21个选项。是不是我做错了吗?如何获得它没有这个例外编译?我没有支持罐子其他地方的其他级项目外(脸谱等)。
下面是完整的堆栈跟踪:
意外的顶级例外:
com.android.dex.DexIndexOverflowException:不是方法ID [0,0xFFFF的]:65536
在com.android.dx.merge.DexMerger $ 6.updateIndex(DexMerger.java:502)
在com.android.dx.merge.DexMerger $ IdMerger.mergeSorted(DexMerger.java:283)
在com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
在com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
在com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
在com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
在com.android.dx.command.dexer.Main.run(Main.java:245)
在com.android.dx.command.dexer.Main.main(Main.java:214)
在com.android.dx.command.Main.main(Main.java:106)
这消息听起来像是你的项目过大。
您有太多的方法。只能有 65536方法DEX
由于摇篮插件0.14.0和构建工具21.1.0您可以使用 < STRONG> multidex支持 。
就在添加这些行 build.gradle
:
安卓{
defaultConfig {
...
//启用multidex支持。
multiDexEnabled真
}
...
}
依赖{
编译com.android.support:multidex:1.0.0
}
另外,在你的清单
从multidex支持库添加 MultiDexApplication
类应用程序的元素
&LT; XML版本=1.0编码=UTF-8&GT?;
&LT;舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.android.multidex.myapplication&GT;
&lt;应用
...
机器人:名称=android.support.multidex.MultiDexApplication&GT;
...
&LT; /用途&gt;
&LT; /舱单&GT;
如果您使用的是自己的应用程序
类,从应用程序
父类改为 MultiDexApplication
。
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
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'
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.).
Here is the full stack trace:
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.
You have too many methods. There can only be 65536 methods for dex.
Since the gradle plugin 0.14.0 and the Build Tools 21.1.0 you can use the multidex support.
Just add these lines in the build.gradle
:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
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>
If you are using a own Application
class, change the parent class from Application
to MultiDexApplication
.
这篇关于更新到最新的appcompat和支持库后DexIndexOverflowException问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!