3

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.

Ben
  • 91
  • 1
  • 7
  • any update on this? I'm facing the same problem when I build an apk using a ~9MB jar – JeffE Feb 17 '12 at 19:32
  • hi, are there any updates on this ? I am using many jar files as well and it keeps saying heap size error thingy during the conversion into an apk. If you do, please let me know as well. Thanking you in anticipation. =) – AuroraBlaze Oct 16 '14 at 02:10

3 Answers3

2

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.

Ben
  • 91
  • 1
  • 7
0

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:


    CompileThreshold=5

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.

kord
  • 482
  • 3
  • 12
0

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.

Squonk
  • 48,735
  • 19
  • 103
  • 135
  • I wish that it was that easy, to build jars is the easy part, to import them is easy enough, the hard part is to conevert them to Dalvik format, and add them to Android project, which must be built on one APK, unless someone has an idea to work around this ... – Ben May 27 '11 at 02:30
  • @Ben: Sorry I shouldn't have said to import them - this is the wrong thing to do. Add them to the Java Build Path. I've edited my answer to show this. Once added as external JARs they're not included in the Project build process. – Squonk May 27 '11 at 02:52
  • First thank you for replying,i appriciate it,i'm pretty much became a master of importing jars, i used all the methods available in eclipse, however, my problem is not adding the jars, my problem is when you compile an android project all the resources are converted to Dalvik, using DX, in this conversion eclipse crash, and this is because i add too many jars, but i must have them all,and like i mentioned the conversion of these jars to dalvik takes too long, every time that i compile the project it's taking all the jars that i added and convert them to Dalvik,i must find a workaround for this – Ben May 27 '11 at 12:37