Clojure Master on android

28 views
Skip to first unread message

MHOOO

unread,
May 27, 2010, 7:45:12 PM5/27/10
to Clojure
After reading on the dev group about running clojure on android I
figured I might just as well try the hello-dalvik example myself.
However the master branch fails because it is exhausing the heap?:

----------------------------------------------------------------------
thomas@lisper:~/sources/clojure$ ./hello-dalvik.sh
Compiling HelloDalvik to .

UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: Java heap space
at java.util.HashMap.<init>(HashMap.java:204)
at java.util.HashMap.<init>(HashMap.java:216)
at java.util.HashSet.<init>(HashSet.java:142)
at
com.android.dx.dex.code.OutputFinisher.getAllConstants(OutputFinisher.java:
144)
at
com.android.dx.dex.code.DalvCode.getInsnConstants(DalvCode.java:176)
at com.android.dx.dex.file.CodeItem.addContents(CodeItem.java:
132)
at
com.android.dx.dex.file.MixedItemSection.prepare0(MixedItemSection.java:
280)
at com.android.dx.dex.file.Section.prepare(Section.java:214)
at com.android.dx.dex.file.DexFile.toDex0(DexFile.java:486)
at com.android.dx.dex.file.DexFile.toDex(DexFile.java:196)
at com.android.dx.command.dexer.Main.writeDex(Main.java:434)
at com.android.dx.command.dexer.Main.run(Main.java:143)
at com.android.dx.command.dexer.Main.main(Main.java:120)
at com.android.dx.command.Main.main(Main.java:89)
thomas@lisper:~/sources/clojure$
----------------------------------------------------------------------

Anyone else experience this error?

Remco van 't Veer

unread,
May 28, 2010, 3:26:30 AM5/28/10
to clo...@googlegroups.com
On 2010/05/28 01:45, MHOOO wrote:

> After reading on the dev group about running clojure on android I
> figured I might just as well try the hello-dalvik example myself.
> However the master branch fails because it is exhausing the heap?:
>
> ----------------------------------------------------------------------
> thomas@lisper:~/sources/clojure$ ./hello-dalvik.sh
> Compiling HelloDalvik to .
>
> UNEXPECTED TOP-LEVEL ERROR:
> java.lang.OutOfMemoryError: Java heap space
>

> Anyone else experience this error?

Try giving the dx command a bit more memory by adding something like:

-Jmx1024m

before --dex.

For reference: I am not experiencing this problem on ubuntu lucid using
openjdk.

HTH,
Remco

MHOOO

unread,
May 28, 2010, 5:06:22 AM5/28/10
to Clojure


On May 28, 9:26 am, Remco van 't Veer <rwvtv...@gmail.com> wrote:
>
> Try giving the dx command a bit more memory by adding something like:
>
>   -Jmx1024m
>
> before --dex.
>
Unfortunately that didn't work quite so well. The java process ended
up using 1.4GB ram without terminating (waited approximately 10
minutes before I killed it).
I am using:
---------------------------------------------------------------
thomas@lisper:/$ java -version
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)

thomas@lisper:/$ uname -a
Linux lisper 2.6.32-22-generic #33-Ubuntu SMP Wed Apr 28 13:28:05 UTC
2010 x86_64 GNU/Linux

thomas@lisper:/$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04 LTS"
--------------------------------------------------------------
The script I am using (hello-dalvik.sh):
--------------------------------------------------------------
#!/bin/sh

export ANDROID_DIR=/home/thomas/sources/android-sdk-linux_86
export CLOJURE_JAR=/home/thomas/sources/clojure/clojure.jar

set -e
rm -rf hello-dalvik; mkdir hello-dalvik; cd hello-dalvik

echo '(ns HelloDalvik (:gen-class)) (defn -main [] (println (str
"hello dalvik from clojure " (clojure-version))))' > HelloDalvik.clj
java -classpath $CLOJURE_JAR:. -Dclojure.compile.path=.
clojure.lang.Compile HelloDalvik

$ANDROID_DIR/platforms/android-8/tools/dx -Jmx1024m --dex --
output=classes.dex HelloDalvik*.class $CLOJURE_JAR
$ANDROID_DIR/platforms/android-8/tools/aapt add HelloDalvik.jar
classes.dex
jar uf HelloDalvik.jar -C ../src/clj clojure/version.properties
$ANDROID_DIR/tools/adb push HelloDalvik.jar /sdcard/

echo dalvikvm -classpath /sdcard/HelloDalvik.jar HelloDalvik \; exit |
$ANDROID_DIR/tools/adb shell
-------------------------------------------------------------
Anything wrong with my configuration?

Remco van 't Veer

unread,
May 28, 2010, 8:59:45 AM5/28/10
to clo...@googlegroups.com
Hmm, I have a 32 bit setup to that's probably the issue:

java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)

OpenJDK Server VM (build 14.0-b16, mixed mode)

Don't have a clue how to fix this.

MHOOO

unread,
May 28, 2010, 7:02:32 PM5/28/10
to Clojure
Worked around the issue by removing some unnecessary stuff from the
clojure build.xml, thus making the final clojure.jar smaller. (In
particular the dx program would halt on generating code for zip
$remove).
Reply all
Reply to author
Forward
0 new messages