Welcome! Please see the About page for a little more info on how this works.

+10 votes
in Other by
edited by

What is the best approach for developing for Android?

I know clojurescript/react native is one approach. I thought just clojure on Android suffers from very slow startup, but I've seen mention graalvm being used with Android. Are their other ways? What are the trade offs from various approaches. How trodden is each path? How viable is Android development?


1 Answer

+4 votes

I've never tried Android development in Clojure, but from what I've heard, the best approach would most likely be React Native and ClojureScript. Here's a good resource for it: https://cljsrn.org/

GraalVM does not currently support compilation for Android or iOS from what I know. It can compile to ARM64 Linux, but not yet for Android or iOS. You'd also still need a UX layer though, so most likely you'd implement that and have it call into the Graal compiled library. So it wouldn't be a full fledged solution right off the bat.

Using Clojure directly should work in theory as well. But Java doesn't support Java 8 byte code fully, and Clojure 1.9+ compiles down to Java 8 byte code. So it is possible some things won't work with Clojure 1.9+. That said, Android is constantly trying to add more Java 8 feature support, so it might be it is good enough now. There's not going to be a lot of tooling for Clojure on Android though. Expect to have to roll your own. You most likely will need to use AOT compilation, and plug the generated .class files into the Android toolchain so it gets desugared and compiled to dex byte code.

Also consider Clojure is slow at loading its namespaces, initialising its Vars, etc. So it won't be the most responsive language choice for Android.

One thing that could have potential, but I have no idea how feasible it is to use Clojure for it is Gluon: https://gluonhq.com/products/mobile/

There you go. With the caveats and lack of tooling for Clojure over the Android toolchain, and Gluon, and because Graal does not currently support Android ARM as a target, and because it wouldn't be a full solution anyways, I believe React Native with ClojureScript is the best approach as of this writing.