views:

295

answers:

4

Building our Android app from Ant fails with this error:

    [apply] 
    [apply] UNEXPECTED TOP-LEVEL ERROR:
    [apply] java.lang.OutOfMemoryError: Java heap space
    [apply]     at java.util.HashMap.<init>(HashMap.java:209)
    [apply]     at java.util.HashSet.<init>(HashSet.java:86)
    [apply]     at com.android.dx.ssa.Dominators.compress(Dominators.java:96)
    [apply]     at com.android.dx.ssa.Dominators.eval(Dominators.java:132)
    [apply]     at com.android.dx.ssa.Dominators.run(Dominators.java:213)
    [apply]     at com.android.dx.ssa.DomFront.run(DomFront.java:84)
    [apply]     at com.android.dx.ssa.SsaConverter.placePhiFunctions(SsaConverter.java:265)
    [apply]     at com.android.dx.ssa.SsaConverter.convertToSsaMethod(SsaConverter.java:51)
    [apply]     at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:100)
    [apply]     at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:74)
    [apply]     at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:269)
    [apply]     at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:131)
    [apply]     at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:85)
    [apply]     at com.android.dx.command.dexer.Main.processClass(Main.java:297)
    [apply]     at com.android.dx.command.dexer.Main.processFileBytes(Main.java:276)
    [apply]     at com.android.dx.command.dexer.Main.access$100(Main.java:56)
    [apply]     at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:228)
    [apply]     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
    [apply]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130)
    [apply]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108)
    [apply]     at com.android.dx.command.dexer.Main.processOne(Main.java:245)
    [apply]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:183)
    [apply]     at com.android.dx.command.dexer.Main.run(Main.java:139)
    [apply]     at com.android.dx.command.dexer.Main.main(Main.java:120)
    [apply]     at com.android.dx.command.Main.main(Main.java:87)

BUILD FAILED

Ive tried giving Ant more memory by setting ANT_OPTS="-Xms256m -Xmx512m". (This build machine has 1Gb RAM).

Do I just need more memory or is there anything else I can try?

A: 

Try setting the apply task's spawn attribute to true, so that each execution is spawned as its own process. You didn't include the portion of your build.xml where you use the apply task, but it will look something like this:

<apply spawn="true" executable="command">
  <fileset dir="."/>
</apply>

You get the idea.

Rob Heiser
Im using the Android-generated build.xml so most of the config is pulled in from android_rules.xml and my build file is mostly empty.
Eno
same problem here. Any other solutions besides moving to another dev box?
Mike
A: 

I moved our build to a new Hudson install on a Linux box. Problem went away.

Eno
I'm also having this problem, and this particular solution is not a problem. Any other ideas?
Mike
+1  A: 

Found this link that helps: http://groups.google.com/group/android-beginners/browse_thread/thread/1e0a66a5ab115168

The solution seems to be to edit your dx or dx.bat shell script (depending on your platform) and uncomment the line that sets the heap size.

For example,

vi $ANDROID_SDK/platforms/*/tools/dx

will let you edit each of your dx files on a mac (and possibly linux).

Then uncomment the javaOpts line that says something like the following:

# If you want DX to have more memory when executing, uncomment the following
# line and adjust the value accordingly. Use "java -X" for a list of options
# you can pass here.
# 
# javaOpts="-Xmx256M"

This isn't an ideal solution obviously, since your changes will get clobbered every time you update your platform SDKs. But it did do the trick for me.

Mike
A: 

Hi ,

iam facing problem in creating the .apk file using the ant script . The generated .apk named as _unaligned.apk instead of .apk and on installing the _unaligned.apk file to the device i get force-close showing the java.lang.VerifyError exaception , but the same apk generated using IDE works fine . i am struck on this for a long time , is it possible for you to share the build.xml file that generates the .apk file .

thank you and regards Sheik Ahmed.j

sheik
How did you generate your build.xml?I used "android update project -p <path_to_project>" to generate build.xml and local.properties (<path_to_project> is the path to your project files).
Eno