【Android , Eclipse】Conversion to Dalvik format failed: Unable to execute dex

解决Android编译过程中Java heap space错误
本文详细介绍了在Android ICS环境下遇到Java heap space错误时的解决步骤,包括修改eclipse.ini文件增加内存配置、正确导入第三方jar包及确保Android SDK组件的最新版本。此外,还提供了通过使用用户库解决特定编译问题的方法。


最近在Android ICS,编译工程的过程中出现Unable to execute dex: Java heap space 的错误,最后导致Eclipse卡,直到需关闭:

修改步骤:

【1】eclipse.int 修改内存,修改eclipse.ini文件[在Eclipse的安装根目录下] : -Xms256m -Xmx512m
【2】额外导入工程的jar包需要通过 add User Library方式导入
右键工程->build path->add Library->user Library->user Libraries->new->"User Libraries Name"->add JARs

若这个时候出现其他的错误:

【1】请检查Android SDK中的tools与Platform-tools是否为最新的版本,并进行更新

【2】检查SDK版本是否为对应的版本,有没有最近的更新


下面是一段英文引用:

As Android developer, I have met a strange problem when I want use a third party jar, it remained me that: Dex Loader] Unable to execute dex: null Conversion to Dalvik format failed: Unable to execute dex: null out of memory error…An internal error occurred during: “Build Project”. Java heap space This is the DEX Error,I find the solutions by Google, one way is to modify the eclipse.ini, you can increase the memory allocated in eclipse.ini to this: -Xms128m -Xmx512m or something higher, but this didn’t work for me. After modify the eclipse.ini, I cannot start the eclipse. By StackOverflow, I find a solution: eclipse.ini file must have -vm on first line and path on second line. don’t try to put everything into one line! -vm C:\Program Files\Java\jdk1.6.0_07\bin\javaw.exe After add the -vm and the path in my eclipse.ini, I can start my Eclipse and the problem has been resolved. Another way to solve the ” Conversion to Dalvik format failed: Unable to execute dex: null” problem is using the user library, the concrete steps are as follows: 1. Right-click the project in Eclipse and select “Build Path -> Add Libraries…”. 2. Select User Library from the list and click Next. 3. Click the “User Libraries…” button. 4. Click “New…” in the User Libraries dialog. 5. Give the user library a name and select the System library checkbox and click OK. 6. Highlight the newly added user library in the list and click the “Add JARs…” button and add the desired jar files. 7. Click OK on the User Libraries dialog. 8. Make sure the new user library is checked in the Add Library dialog and … Posted by CuteAndroid

Java开发过程中,`java.lang.AssertionError` 是一种常见的错误类型,通常与开发者在代码中使用断言有关。当断言失败时,会抛出 `AssertionError`。在某些情况下,该错误可能与复杂逻辑或数据结构转换相关,例如在将查询或操作转换为关系代数(relational algebra)时,数据类型未能正确保留,从而导致断言失败。 ### 错误原因分析 当提示 `java.lang.AssertionError: Conversion to relational algebra failed to preserve datatypes` 时,表明在将某种表达式或查询结构转换为关系代数的过程中,某些数据类型的定义未能正确保留。这可能是由于以下原因导致: 1. **表达式结构转换逻辑错误**:在将逻辑查询计划转换为关系代数形式时,某些节点的类型信息未被正确传播或推断。 2. **类型推断机制缺陷**:如果系统依赖自动类型推断机制,那么在某些复杂表达式中可能会导致类型信息丢失或误判。 3. **断言条件设置过于严格**:在调试阶段,某些断言可能要求输入和输出的类型必须完全一致,而实际转换过程中允许某些隐式转换,从而导致断言失败。 4. **代码逻辑缺陷或未覆盖的边界情况**:在实现转换逻辑时,可能未正确处理某些边缘情况,例如嵌套表达式、多态类型或自定义类型。 ### 解决方案 #### 1. 检查转换逻辑中的类型传播 确保在转换过程中,每个节点的输出类型能够正确地从其输入类型推导出来。例如,在关系代数表达式中,每个操作符(如投影、选择、连接等)都应有明确的类型推导规则。如果使用了自定义类型系统,应确保其在转换过程中保持一致性。 ```java assert outputType.equals(expectedType) : "Output type " + outputType + " does not match expected type " + expectedType; ``` 上述断言如果失败,可能表明类型推导逻辑存在问题,需要检查 `outputType` 的生成逻辑是否正确。 #### 2. 优化断言条件 如果断言的目的在于验证类型一致性,但允许某些隐式转换(如数值类型之间的提升),则应调整断言条件,使其更符合实际需求。例如,可以引入类型兼容性检查而非严格相等判断: ```java assert TypeSystem.isAssignableFrom(expectedType, outputType) : "Output type is not compatible with expected type"; ``` #### 3. 添加调试日志 在断言失败前添加详细的日志输出,记录输入结构、推导出的类型以及预期类型,有助于快速定位问题根源: ```java System.out.println("Input expression: " + expr); System.out.println("Expected type: " + expectedType); System.out.println("Inferred type: " + inferredType); ``` #### 4. 单元测试验证类型转换逻辑 编写针对类型推导逻辑的单元测试,模拟各种表达式结构并验证其类型是否被正确保留。这有助于在开发阶段发现潜在问题并防止回归错误。 ```java @Test public void testTypePropagationInProjection() { Expression inputExpr = new Literal(42); RelationalNode projection = new ProjectNode(inputExpr, INTEGER_TYPE); RelationalNode algebraForm = convertToRelationalAlgebra(projection); assertEquals(INTEGER_TYPE, algebraForm.getOutputType()); } ``` #### 5. 调试与代码审查 通过调试器逐步执行转换逻辑,观察类型信息的变化路径。同时,进行代码审查以确保所有转换规则都正确处理了类型传播。 ### 注意事项 - **断言应作为调试工具而非运行时控制机制**:在生产环境中应禁用断言(使用 `-da` 参数),以避免性能损失。 - **避免在断言中执行有副作用的操作**:断言可能在生产环境中被禁用,因此不应包含任何影响程序行为的逻辑。 - **保持断言简洁明确**:每个断言应只验证一个逻辑点,便于定位问题。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值