running 1.0.x, 1.1.x or master on android/dalvikvm

27 views
Skip to first unread message

Remco van 't Veer

unread,
May 25, 2010, 10:55:09 AM5/25/10
to cloju...@googlegroups.com
Hi,

Somebody mentioned android support on the clojure list a couple of days
ago so I made some time and investigated which branches of clojure work
on dalvikvm without modification and which do not. In a nutshell: 1.0.x
does work, 1.1.x and master do not.

For 1.1.x see issue 199 in assembla. For master apply the following
(not dalvikvm specific) patch:

<<snip>>
diff --git a/build.xml b/build.xml
index 615ba5b..756bde4 100644
--- a/build.xml
+++ b/build.xml
@@ -105,6 +105,7 @@
<arg value="clojure.test.tap"/>
<arg value="clojure.test.junit"/>
<arg value="clojure.pprint"/>
+ <arg value="clojure.java.io"/>
</java>
</target>

<<snip>>

Do I need to make a ticket for this? "clojure.java.io missing from
compile-clojure build target"?

For reference, here's my recipe for setting up a test environment and
running a minimal clojure hello-world class on dalvikvm in the android
emulator.

Install the latest android SDK (current is r06):

* download at http://developer.android.com/sdk/
* unpack anywhere
* add [anywhere]/android-sdk-linux_86/tools (or win or osx) to your PATH
* launch android executable
** -> available packages
** -> SDK Platform Android 2.2
** -> Install selected
* create a virtual device
** -> new
** -> name: froyo
** -> target: android 2.2
** -> sd card size: 10 Mib
** -> create AVD
* start it
** -> select froyo
** -> start..

I've wrapped the clojure "hello world" class in a script to compile,
dex, jar, push and launch it on the emulator. Copy the following code
into a script (hello-dalvik.sh) in your clone of the clojure source
tree:

<<snip>>
#!/bin/sh

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 --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
<<snip>>

Build the clojure jar, setup ANDROID_DIR to point to your Android SDK
installation and run the script;

<<snip>>
$ ant jar && sh hello-dalvik.sh
Compiling HelloDalvik to .
'classes.dex' as 'classes.dex'...
1920 KB/s (1122436 bytes in 0.570s)
dalvikvm -classpath /sdcard/HelloDalvik.jar HelloDalvik ; exit
# hello dalvik from clojure 1.2.0-master-SNAPSHOT
<<snip>>

Kind Regards,
Remco

--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To post to this group, send email to cloju...@googlegroups.com.
To unsubscribe from this group, send email to clojure-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/clojure-dev?hl=en.

Stuart Halloway

unread,
May 25, 2010, 11:09:01 AM5/25/10
to cloju...@googlegroups.com
Hi Remco,

Thanks for pointing this out. I just pushed AOT for compilation of
clojure.java.io (and clojure.repl while I was at it).

It seems clojure.repl would have been broken too -- was it just that
you hadn't hit it yet?

Stu

Remco van 't Veer

unread,
May 25, 2010, 11:20:21 AM5/25/10
to cloju...@googlegroups.com
Nope I didn't touch clojure.repl. Didn't touch clojure.java.io directly
either, but that's pulled in by core.clj near line 5327.
Reply all
Reply to author
Forward
0 new messages