编译Jars并将其添加到android项目中
好吧,事情是这样的,我花了几天时间,搜索所有数据库,所以要么是我没有搜索到正确的单词,要么没有答案,希望“还”。
症状: - 编译 Android 项目 DX 每次构建项目时编译所有 jar - 没有理由做一次就足够了,无论每次如何做,每次构建都可能需要很长时间而不是花费几秒钟分钟。
真正的问题:
- 添加几个 Jars 会导致 eclipse 崩溃 - 现在这是使用这些设置(重 jar) -Xms256米 -Xmx1024米 -XX:+使用并行GC -XX:PermSize=256M -XX:MaxPermSize=512M
(这实际上提供了更好的性能,所以如果你的 eclipse 编译速度很慢,你可以添加 -XX:+UseParallelGC 它将有所帮助)(我无法将其设置得比这更高,当 eclipse 时,java 堆大小达到 750m崩溃,gc 在 DX 编译 jar 时不起作用,它会尝试,但 CPU 很忙,不允许这样做,所以当它到达第 5 个 jar(每个 3MB)时,它有大约 600MB在堆上,这就是我使用 gcoverheadlimit 的原因)将
它们中的每一个或几个一起编译会很好地编译它(在同一个 android 项目内),问题是我找不到一种方法来单独编译它们(然后我需要apks 安装在客户端设备上),当我将它们编译在一起时 Eclipse 崩溃。
我尝试使用 cmd 和 DX 逐一编译它们,尽管它已构建,但当我在 eclispe 中构建项目时,它会重建它,所以就像我什么也没做,也尝试将 jars 转换为 DEX 文件,但没有帮助。
我红色了很多关于java堆大小的帖子,这不是我的情况,我什至使用了gcoverheadlimit,太多的jar会导致它崩溃,如果有人有一个想法/解决方案,我会向他/她致敬......
总结一下: 我想将java常规jar转换为Dalvik格式,然后将其作为资源添加到android项目中,因此当项目编译时,不需要将jar转换为Dalvik格式,因为它已经完成了。
Ok here is the thing, i put days into it, searching all the data base, so it's either i didn't search for the right words or there is no answer for it, hopefully “yet”.
Symptoms:
-compiling the Android project DX compile all the jars every time the project is built - there is no reason to do it one time should be enough, any how it does it every time, every build can take long time instead of taking seconds it takes minutes.
The real problem:
-Adding several Jars cause to eclipse to crash -- now this is with these settings(heavy jars)
-Xms256m
-Xmx1024m
-XX:+UseParallelGC
-XX:PermSize=256M
-XX:MaxPermSize=512M
(Which actually give better performance so if your eclipse compile slow you can add -XX:+UseParallelGC it will help)(I couldn't set it any highr than this, java heap size get to 750m when eclipse crash, gc doesn't work while DX compiling a jar, it tries between but the CPU is busy which doesn't let it, so at the time that it get to the forth-fifth jars which are 3MB each it has something like 600MB on the heap, this is why i used gcoverheadlimit)
Compiling each one or several of them together will compile it well(within the same android project), the problem is that i cannot find a way to compile them separately(then i will need to apks installed on the client device), and when i compile them together Eclipse crash.
I tried to compile them one by one, using cmd and DX, although it's built, when i build the project in eclispe it rebuild it, so it's like i did nothing, tried to convet the jars to DEX files too, didn't help.
I red many posts regarding to java heap size, this is not my case i even used gcoverheadlimit, too many jars cause it to crash, if someone has an idea/solution i will salute him/her ...
To summarize it all :
I want to convert java regular jars to Dalvik format, then add it as a resource to an android project, so when the project is complied it won't need to convert the jars to Dalvik format because it's already done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,经过长时间的研究,我想我知道问题是什么,但我还不知道如何解决它。
症状:编译大 jar 和/或多个 jar,导致 eclipse 崩溃,当它不崩溃时错误消息:写入输出时遇到问题:opcode == null,转换为 Dalvik 格式失败,错误 2。
原因:DX 无法处理超过 16 位字符串所能包含的内容,因此,无法包含(至少不能同时)超过该字符串的长度。
结果:无法将复杂的 Android 应用程序编写为一个 APK。
给android开发者的建议(我不太确定你是如何构建它的,但是):你可以对这些字符串使用arraylist,每个字符串依次将自己写入classes.dex文件,然后,写入就没有限制一个 APK 的代码,和/或根据开发人员需要添加尽可能多的 jar,这是一种假设,这不会很容易,但也不会太复杂,对于那些制作 Android 的人来说绝对不是,同意吗?
解决方法:抱歉,但我还没有解决方法,我花了一些时间才解决这个问题,因为 Eclipse 崩溃了,我没有收到“opcode == null”错误消息,所以我认为这是一个eclipse 问题,我很高兴获得关于这个问题的第二个和第三个意见。
Ok after a long research, i think that i know what is the problem, however i don't know how to workaround it yet.
Symptoms : compiling large jar and or several jars, cause to eclipse to crash, when it doesn't crash error message : trouble writing output: opcode == null , Conversion to Dalvik format failed with error 2 .
Cause : DX is unable to process more than it can contain in a string of 16bit, thus, there is no way to include(at least not in the mean time) more than the length of this string.
Result : unable to program complicated apps for Android as one APK.
Advice for android developers (i don't quite sure how you built it but): you can use arraylist for these strings, which each one of them writes itself in turn to classes.dex file, then, there will be no limit for writing code for one APK, and/or adding as many jars as the developer needs, this is an assumption, making it won't be easy but not too complicated too, definitly not to the ones who made Android, Agree ?
Workaround : sorry but i don't have a workaround yet, it took me some time to figure this problem, because the eclipse crashed and i didn't get the "opcode == null", error message so i thought that this is an eclipse issue, I will be glad to get second and third opinion on this one.
构建 JAR 后,将它们添加为外部 JAR...
在 Eclipse 中选择“Project”菜单 -> “属性”然后是“Java 构建路径”。选择“库”选项卡,然后单击“添加外部 JAR...”按钮,然后浏览并添加它们。
Once the JARs have been built then add them as External JARs...
In Eclipse select the 'Project' menu -> 'Properties' then 'Java Build Path'. Select the 'Libraries' tab then click the 'Add External JARs...' button then browse and add them.
我也遇到过同样的问题。详细输出中有很多“Dx 处理...”消息,构建classes.dex(3.4 Mb)大约需要 3-4 分钟。
那速度非常慢,我感到很痛。
然后我进行了研究,发现问题的原因是错误的eclipse JVM设置(eclipse.ini)。顺便说一句,我从一些 stackoverflow 答案中得到了这个令人讨厌的配置,有超过 100 个接受。
请确保 eclipse.ini 不包含以下行:
我删除了此行,现在编译需要约 10 秒!!!
另外,现在我在 eclipse 配置中使用 ParallelGC 而不是 G1GC,因为它更稳定并且不会导致我的 IDE 崩溃。
因此,您的主要任务是修改您的 eclipse.ini 并删除所有可疑的和实验性的参数。
I have had the same problem. There was lot of "Dx processing ..." messages in verbose output and it took about 3-4 minutes to build classes.dex(3.4 Mb).
That was very slow and I felt a butthurt.
Then I made a research and found out that the reason of the problem was in wrong eclipse JVM settings(eclipse.ini). BTW, I got this nasty config from some stackoverflow answer with more than 100 accepts.
Please make sure that eclipse.ini doesn't contains following line:
I removed this line and now compilation takes ~10 sec!!!
Also, now I use ParallelGC instead of G1GC in eclipse config because it's more stable and it doesn't crash my IDE.
So, your main task is to revise your eclipse.ini and get rid of all suspicious and experimental parameters.