Android 'dex' stage takes a very long time with Clojure

140 views
Skip to first unread message

Matt Clark

unread,
May 28, 2010, 10:12:15 AM5/28/10
to Clojure
I'm new to Android, but I've been wanting to give it a try for a while
so I thought I'd try using Clojure's master branch. It all seems to
be working fairly well except the dex stage of installation takes
around 2 minutes for a simple Hello World app. How do others get
around this lag?

I'm pretty sure it's caused by the large clojure.core namespace, as
I've already taken everything else that I can out of the clojure jar
file. I'm just not sure if there's anything else I can do. I am
using emacs and android-mode, if that is of any help. I've also tried
giving it more memory as suggested here: http://groups.google.com/group/clojure/msg/c38e015582cf7623

Thanks a lot

Matt

MHOOO

unread,
May 28, 2010, 7:06:33 PM5/28/10
to Clojure
I've just started with development on android myself, but from what
I've read on the internets, you could probably write a .dex loader in
the default classes.dex (which will be loaded when you start your
application) and write your actual program in other .dex files. This
way you'll be able to compile the entire clojure system into the
classes.dex and will only have to update your custom .dex files.
This is actually something I'm currently trying to get to work.
For further info, see:
http://code.google.com/p/android/issues/detail?id=7147
http://developer.android.com/reference/dalvik/system/DexClassLoader.html

Remco van 't Veer

unread,
May 29, 2010, 3:09:15 AM5/29/10
to clo...@googlegroups.com
Nice! This will speedup development and allow you to workaround the
terribly long startup time with a distracting splash screen.

MHOOO

unread,
May 29, 2010, 10:07:54 AM5/29/10
to Clojure
I'd like to try to compile the clojure code (i.e. its different parts
like .core, .main, .set, etc) into different .dex files so as to speed
up both compilation (since you'll only have to recompile those .dex
files which have changed) and start-up (since only those .dex files
are loaded which are needed during program runtime). However I'm not
quite sure where to hook into as I have only little understanding of
how clojure loads files. Is there a function somewhere in the java/
clojure side of the code which is responsible for finding a namespace
(possibly compiling it first) and loading it?

MHOOO

unread,
May 29, 2010, 6:31:43 PM5/29/10
to Clojure
Well, that was easy enough. I modified the load function inside
RT.java to load classes/namespaces out of .dex files. (use
'my.compiled.namespace) will now look for either the compiled .class
(and load it), or it will look for a .clj (and compile & load it -
thanks to George Jahad's work), or it will look for a .dex file
("my.compiled.namespace.dex") inside the .apk and try to load the
class from there.
Charming!
I've already split clojure-master into several parts (.dex files for
core,main,zip,set,walk,xml,java,inspector,pprint,repl), so now the
next step would be to figure out how to get it all together and
integrate it with leiningen: Build clojure-master .dex files (<- done)
with a custom main (<- todo) which calls the users main android
activity (<- todo), package everything into an apk (<- done) and
install it on the emulator (<- done).

Matt Clark

unread,
Jun 1, 2010, 7:30:07 PM6/1/10
to Clojure
Do you have a public repository of the work you've done so far? I'm
very interested to learn more about this.

MHOOO

unread,
Jun 2, 2010, 9:01:05 AM6/2/10
to Clojure
No, I have yet to set up a public repo. I'll see to it that I at least
set one up for the modified clojure-master project sometime today or
tomorrow. As for a hello-world project, I'm currently running into
some issues with android's call stack limit: (use 'swank.swank) kinda
uses too much of that. I've possibly solved the problem by running
clojure entirely in its own thread, however for some reason I get
exceptions about *compile-path* not being set upon initialization, so
I've tried to fix the problem by manually specifying it - but that
results in strange errors which I have yet to resolve.

MHOOO

unread,
Jun 4, 2010, 7:42:11 AM6/4/10
to Clojure
I've pushed my changes to clojure-master to github (master from
today):
git://github.com/MHOOO/clojure.git

This should work so far. As for a hello-clojure-android application:
I'll try to get my example up and running on the weekend - possibly
together with a leiningen plug-in which automates the install process
(as there are some preconditions to be met before clojure can run).
Reply all
Reply to author
Forward
0 new messages