I'd like to do Android development in Clojure
, using the Cursive
plugin in Android Studio
. I've seen several posts where people have stated that it is possible, but I haven't been able to get it working.
When I try to build, I get errors reported where I'm trying to call Clojure from Java:
Error:(6, 18) error: package com.domain does not exist
Error:(15, 49) error: cannot find symbol variable tiny
Here's what I tried:
I already have
Cursive
running inIntelliJ
withleiningen
, building and running standalone Clojure appsStart Android Studio, version 1.5.1
Create a new Android project. Selected API level 15, Empty Activity
Install Cursive plugin, as per this post: Is it possible to get the Cursive Plugin installed with Android Studio?
Add clojure jar to classpath: Open module settings, dependencies, +Library Dependency, search for and select
org.clojure:clojure:1.8.0-RC5
Switch from
Android
view toProject
view, to create Clojure src directory: selectapp/src/main
and create new directoryclojure
The next step is to create a
Clojure
source file, which can be called from Java, using the example in this post: Calling clojure from javaSelect src directory
clojure
, right-clickNew
Clojure Namespace
and enter:com.domain.tiny
(to match the ns used in the example)Paste the code from the example above into the new file (note that the ns in the new file was
tiny
and should have beencom.domain.tiny
)It will say
File tiny.clj is not under a source root
so click onAdd source root
. Now we have bothsrc/java
andsrc/clojure
set as src rootsBuild the project. At this point it looks like everything is happy, no syntax errors in either the Java or Clojure code. We can deploy and run the (almost) empty Android project, and run a local REPL to load and test our Clojure code.
We want to call some Clojure code from Java, so add the following code to
MainActivity
(again, from the example above):System.out.println("(binomial 5 3): " + tiny.binomial(5, 3)); System.out.println("(binomial 10042, 111): " + tiny.binomial(10042, 111));
Android Studio can find the package
com.domain.tiny
and thetiny
class, no syntax errors, so looks goodNow try and build the project - at this point I get an error:
Error:(6, 18) error: package com.domain does not exist Error:(15, 49) error: cannot find symbol variable tiny
At this point, I'm stuck. I'm guessing that even though the compiler is seeing the Clojure code ok, there's still something missing in the build process. Does leiningen
need to be involved? If so, I don't know how, or what I might have to put in the project.clj
configuration file.
Anyone have any ideas? Thanks!