Thursday, July 8, 2010

Android dx.bat causing out of memory errors

The Android SDK contains a file name dx.bat whose purpose is to convert class files to dex files. Embedded in the file is a JAVA_OPTS setting that is commented out by default.
When you build Android you may see an error like this:

-dex: [echo] Converting compiled files and external libraries into D:\Androidproject\bin\classes.dex...
[apply]
[apply] UNEXPECTED TOP-LEVEL ERROR:
[apply] java.lang.OutOfMemoryError: Java heap space....

First determine which SDK you are building against since all may be installed in the Android SDK location by default. In this case I see the failure:
BUILD FAILED
D:\ProgramFiles\Java\android-sdk-windows\platforms\android-1.6...

You need to edit the dx.bat file that sits in the tools directory for the SDK you're using (ex. D:\ProgramFiles\Java\android-sdk-windows\platforms\android-1.6\tools). There's a 'set javaOpts=' setting that has no value by default, and below in the file a commented section with the value set to -Xmx256M. Either remove the comment from the commented one, or add the value to the empty one.

No comments:

Post a Comment