转载请注明来源:http://blog.csdn.net/goldenfish1919/article/details/33729679

用eclispe打包的时候报错:

[2014-06-23 13:44:35 - Dex Loader] Unable to execute dex: Cannot merge new index 66195 into a non-jumbo instruction!
[2014-06-23 13:44:35 - tao_apad_2.0] Conversion to Dalvik format failed: Unable to execute dex: Cannot merge new index 66195 into a non-jumbo instruction!

参考:http://www.cnblogs.com/frydsh/archive/2013/02/20/2918969.html

最新的ADT和SDK Tool在将jar转化成dex的时候,可能会合并类的代码,这将导致巨大的类;类中的每一个方法都分配有一个id,字节码中以id标识和调用方法;早期的Dalvik VM内部使用short类型变量来标识方法的id,最大值限制在65535;综合上述因素,代码在安装的时候,不能通过验证,所以安装失败。
最新的Android可能已经解决了这个问题,但是更早的Android版本可能仍然存在此问题。
因此,由于大量遗留机器的存在,这个问题是不能彻底解决的,一个临时的解决方案是:删掉没有实际使用的代码,或者使用ProGuard处理代码(可以减小代码体积)。
一个不幸的推论是:随着一个软件功能的增加,代码的膨胀,APK包终将超出可以处理的范围,也许就是8M(指APK包里面的classes.dex).

参考:https://code.google.com/p/android/issues/detail?id=40409

While the Dalvik team works on a fix, I'm going to allow disabling of the new dex merger features. Builds will be slower (actually back like they were before) but they'll work at least. We were looking at a 21.0.1 release so I'm going to do this now and make sure this gets in.

然后,修改project.properties,添加一行:dex.disable.merger=true,竟然可以了。

文中还有,也是猜的,没有根据:

@18: i think you're confused. there are probably multiple bugs. as i explained in comment 7, the original error is caused by out-of-order annotations. the number of annotations isn't relevant to that bug;all that matters is whether the method indexes they refer to happen to come out in order or not when the merge basically appends them without sorting. (you are though correct that the annotations problem has nothing to do with jumbo mode --- it's the merge step that's the problem.)

looking at libdex, the reason for your new error is a bit more obscure. it seems to mean that there are references to more than one class in a class_data_item. my assumption is that that means thatone of the fields or methods referred to in the class_data_item doesn't belong to the class we're supposedly defining.i'm afraid i don't know enough about the merge process to know how/why that might happen.

我们这个问题的原因大概是:

Ufnortunately method call is encoded with a method_id being a short int (so only 65535 different methods), unlike const string access.

So, to summarize, even though the .dex specs allows more than 65535 classes and methods, the vm doesn't support large number of classes/methods, there wasn't any explicit error message.

一个vm最多只能有65536个方法!

dex.force.jumbo是干嘛的?

To my knowledge, dex.force.jumbo activates the const-string-jumbo opcode which allows to refer to static strings when you have more than 65k strings in your dex file.

如果超过了65k个字符串,启用dex.force.jumbo这个参数才可以引用到所有的字符串。

usually, dx will use the shortest instruction it can. this can make merging impossible if an instruction would need to be widened to fit more bits of string index (or whatever). dex.force.jumbo says "always use the wide form, even if you don't need to", to improve the chances of being able to merge later.

dex.disable.merger的官方解释参考:http://blog.toolib.net/tools/sdk/eclipse-adt.html:

Added a flag to disable dex merging to deal with cases where merging could generate a broken dex file. If this happens to your project, add the following setting to your project.properties file: dex.disable.merger=true。This setting causes the build system to revert to the older, slower dex processing that does not pre-dex libraries.

也就是说merge可能会出问题,具体啥问题,没说,很操蛋!

昨天还试验出了一种方法,在project.properties文件中添加下面两个选项也是可以的:

manifestmerger.enabled=true
dex.force.jumbo=true

我们的工程是因为引入了一个lib工程导致的这个错误,因此启用了manifest merge,然后设置dex.force.jumbo竟然也可以,具体原因有待于进一步查明。

关于manifestmerger.enabled,参考http://stackoverflow.com/questions/10976635/using-the-new-manifestmerger-property-in-android:

Automatic merging of library project manifest files into the including project's manifest. Enable with the manifestmerger.enabled property.

If you want to merge android library project manifest and your current project manifest, you can add manifestmerger.enabled=true in your project.properties file where you referred your library project. But, you should be confirmed some point like ADT version, Also Minimum and target SDK should be same as library project.

因此,这种方式是有局限性的,Minimum和target SDK需要相同才可以。

Android-Cannot merge new index 66195 into a non-jumbo instruction的解决办法的更多相关文章

  1. Android-Cannot merge new index 66195 into a non-jumbo instruction的解决的方法

    转载请注明来源:http://blog.csdn.net/goldenfish1919/article/details/33729679 用eclispe打包的时候报错: [2014-06-23 13 ...

  2. android开发找不到模拟器(PANIC: Could not open:)解决办法

    android开发找不到模拟器(PANIC: Could not open:)解决办法   2013/4/3 17:44:15 0人评论 213次浏览 分类:android开发 在系统环境变量设置名为 ...

  3. 【转】Android Fragment中使用SurfaceView切换时闪一下黑屏的解决办法

    重构了下之前自己的一个新闻客户端,全部使用了Fragment来进行页面切换,只有一个入口Activity作为程序的启动Activity,其中有一个界面需要调用摄像头识别二维码, 于是就会用到Surfa ...

  4. 【转载】Android Gradle Build Error:Some file crunching failed, see logs for details解决办法

    Android Gradle Build Error:Some file crunching failed, see logs for details解决办法 转载请标明出处: http://www. ...

  5. Android界面隐藏软键盘的探索(兼findViewById返回null解决办法)

    最近写的APP,老师说我的登陆界面虽然有ScrollView滑动,但用户体验不太好,因为软键盘会挡住输入框或登录button(小米Pad,横屏,当指定只能输入数字时没找到关闭系统自带键盘的下箭头). ...

  6. eclipse或adt-bundle创建的android项目没有自动生成MainActivity.java和activity_main.xml等文件解决办法

    以前我电脑一直以来都是用的eclipse3.7来开发android项目的,创建android项目也能正常生成MainActivity.java和activity_main.xml等文件.后来不知道什么 ...

  7. Unable to handle 'index' format version '2', please update rosdistro的解决办法

    之前安装的ROS是Fuerte版本的,好久没有更新,不知不觉又出来了好几个新的版本,今天删除了Fuerte,计划安装Hydro版本的尝尝新,按照官网的安装流程,很快就可以把新版本安装上去了,但是在&q ...

  8. Android中竖线随内容高度变化而变化的问题和解决办法

    项目中要求显示竖线,并且竖线高度不确定,竖线的高度要随着内容的变化而变化.不能使用match_parent 充满,也不能在布局中写死,此时使用 android:layout_height=" ...

  9. Android之Error: 'L' is not a valid file-based resource name character解决办法

    1.问题 Error:Execution failed for task ':mergeBYODReleaseResources'.> /home/chenyu/Android_dev/sang ...

随机推荐

  1. 有关windows Gateway Ipsec 和NAT 兼容性问题

    1.简单通信拓扑: 将Windows 平台 作为一个网关,同一时候开启IPsec 和NAT来支持private和public的通信. 注意:IPSEC Gateway  和 Client1 Ipsec ...

  2. 数据库行列转换sql

    经常折腾数据库,常常遇到数据库行列转换的问题,下面就用一个小例子来演示下如何进行行列转换. 1.创建一张表 CREATE TABLE [android_source]( [CREATETIME] [d ...

  3. C# 正则表达式过滤危险HTML

    下面是两个过滤的方法 /// <summary> /// 此处过滤危险HTML方法 /// </summary> /// <param name="html&q ...

  4. <转>lua解析脚本过程中的关键数据结构介绍

    在这一篇文章中我先来介绍一下lua解析一个脚本文件时要用到的一些关键的数据结构,为将来的一系列代码分析打下一个良好的基础.在整个过程中,比较重要的几个源码文件分别是:llex.h,lparse.h.l ...

  5. MATLAB 在同一个m文件中写多个独立的功能函数

    MATLAB 在同一个m文件中写多个独立的功能函数,从而实现在外部可以直接调用这个文件中的某一个函数. 鉴于MATLAB的函数文件的函数名与文件名要一样,就需要有一个统一的接口来涵盖这些功能函数. 例 ...

  6. Spring异常解决 java.lang.NullPointerException,配置spring管理hibernate时出错

    @Repository public class SysUerCDAO { @Autowired private Hibernate_Credit hibernate_credit; /** * 根据 ...

  7. 成都达内推荐PHP书籍【update 2017.1.10】

    [初阶](基础知识及入门) 01. <PHP与MySQL程序设计(第4版)> 02. <深入浅出MySQL 数据库开发 优化与管理维护 第2版> 03. <实战Nginx ...

  8. SoapUI利用Groovy把外部数据加载到request中

    默认已经用Groovy把外部数据给读取出来了,关键是读取出来后,如何加载到request中去?这里提供了两种方法:1.该Groovy脚本的名称是"setUp" def num = ...

  9. Idea集成Lombok代码注释来精简代码

    转载http://www.cnblogs.com/holten/p/5729226.html Lombok介绍及使用方法 lombok简介 lombok是暑假来到公司实习的时候发现的一个非常好用的小工 ...

  10. VS2017 IDE开发工具选型、安装和使用

    原文地址:https://blog.csdn.net/boonya/article/details/78739500 距离上次使用VS工具已是2年前了,这次准备选择比较新的版本来开发桌面程序了.总的来 ...