Android DexException:无法将新索引 65536 合并到非巨型指令中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26093664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:59:36  来源:igfitidea点击:

DexException: Cannot merge new index 65536 into a non-jumbo instruction

androidandroid-studioandroid-gradle-plugin

提问by Martynas Jurkus

For some unknown reason my app suddenly won't build from Android Studio.

由于某种未知原因,我的应用程序突然无法从 Android Studio 构建。

I'm keep getting

我不断得到

> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /home/martynas/android-sdk/build-tools/19.1.0/dx --dex --num-threads=4 --output
...
...
...
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Cannot merge new index 65536 into a non-jumbo instruction!

While the same application is built successfully from command line. I've checked method references count and it's way below the dreaded 64k.

虽然从命令行成功构建了相同的应用程序。我检查了方法引用计数,它远低于可怕的 64k。

I'm using AS 0.8.11 now.

我现在使用的是 AS 0.8.11。

采纳答案by Haresh Chhelana

Try to add this line on your project.properties

尝试在您的 project.properties 添加此行

dex.force.jumbo=true

dex.force.jumbo=真

Which increment the limit for strings in a dex files. And your project will probably compile.

这会增加 dex 文件中字符串的限制。你的项目可能会编译。

Note :Also with jumbo set, the is another limit of 64K only for methods in an single dex. If you get this limit in the future , you will need to remove some dependencies.

注意:同样使用 jumbo set,另一个 64K 限制仅适用于单个 dex 中的方法。如果您将来获得此限制,则需要删除一些依赖项。

Update - Google Play Services 6.5 (12-08-14)

更新 - Google Play 服务 6.5 (12-08-14)

With version 6.5 Google finally unbundled the Google Play Services. So from now on it'll be possible to selectively compile the APIs into your executable.

Google 终于在 6.5 版中解开了 Google Play 服务的捆绑。因此,从现在开始,可以有选择地将 API 编译为可执行文件。

Example :

例子 :

compile 'com.google.android.gms:play-services-maps:6.5.+'
compile 'com.google.android.gms:play-services-ads:6.5.+'

For all the other individual Google Play Services APIs check this page on d.android.com.

对于所有其他单独的 Google Play 服务 API,请查看d.android.com 上的页面。

Update (21-04-2015) : https://developer.android.com/tools/building/multidex.html

更新(21-04-2015):https: //developer.android.com/tools/building/multidex.html

回答by lydia_schiff

Set the jumboMode property in build.gradle:

在 build.gradle 中设置 jumboMode 属性:

android {
    ...
    dexOptions {
        jumboMode true
    }

}

I also found this useful: Showing dex method count by package.

我也发现这很有用:Showing dex method count by package

回答by Sayooj

This works for me. I was getting com.android.dex.DexIndexOverflowException: Cannot merge new index 66636 into a non-jumbo instruction!

这对我有用。我得到com.android.dex.DexIndexOverflowException: Cannot merge new index 66636 into a non-jumbo instruction!

android {
    ...
    dexOptions {
        jumboMode true
    }
}

If this isn't working, you might have reached method reference limit in dex which is a different issue. You need to use either multidex or proGuard.

如果这不起作用,您可能已经达到了 dex 中的方法引用限制,这是一个不同的问题。您需要使用 multidex 或 proGuard。

回答by goonerDroid

This is a bug in the merger when the dex files that are being merged have more than 65536 strings. The new index can't fit in a const-string instruction, and the dex merger doesn't support changing instructions if they are different sizes, so it can't be widened to a const-string/jumbo instruction.This was fixed in jb-mr1 by adding a new option: --force-jumbo.This bug can be fixed by adding "dex.force.jumbo=true"to the project.properties.

当正在合并的 dex 文件具有超过 65536 个字符串时,这是合并中的一个错误。新索引不能放入const-string指令,并且dex合并不支持大小不同的改变指令,所以不能扩展为const-string/jumbo指令。 jb-mr1 通过添加一个新选项:--force-jumbo。可以通过添加"dex.force.jumbo=true"到 project.properties来修复此错误。

回答by SamuraiSong

With latest Android Studio and flag "force jumbo" checked on Android Studio compiler settings, this problem disappear.

使用最新的 Android Studio 并在 Android Studio 编译器设置中选中“force jumbo”标志,这个问题就消失了。