Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Lean compilation

Alexander Yakushev edited this page Feb 23, 2015 · 8 revisions

Lein-droid supports lean compilation mode via Project Skummet. This gives much faster load time and smaller APK size/memory footprint for your Clojure-Android applications.

Howto

Insert the following profile into :profiles map of your project.clj:

:lean
[:release
 {:dependencies ^:replace [[org.skummet/clojure-android "1.7.0-alpha5-r1" :use-resources true]
                           [neko/neko "3.2.0-preview3" :exclusions [org.clojure-android/clojure]]]
  :jvm-opts ["-Dclojure.compile.ignore-lean-classes=true"]
  :global-vars ^:replace {clojure.core/*warn-on-reflection* true}
  :android {:lean-compile true
            :skummet-skip-vars ["#'neko.init/init"
                                "#'neko.context/context"
                                "#'neko.resource/package-name"
                                "#'neko.-utils/keyword->static-field"
                                "#'neko.-utils/keyword->setter"
                                "#'neko.ui.traits/get-display-metrics"
                                "#'test.leindroid.sample.main/MainActivity-onCreate"
                                "#'test.leindroid.sample.main/MainActivity-init"]}}]

Latest Skummet version:

https://clojars.org/org.skummet/clojure-android/latest-version.svg

Here we define a new profile called :lean that inherits from :release profile. It overrides dependencies vector with its own one, where Clojure is replaced with special Skummet jar, and also Clojure dependency is excluded from Neko. You should do this for every dependency you include in your project, because you can’t have both Clojure and Skummet on your classpath. :jvm-opts line is just necessary. :globar-vars is added here because *warn-on-reflection* Var has to be namespace-qualified with Skummet. :lean-compile parameter is also just necessary. :skummet-skip-vars is a list of Vars that should not be lean-compiled. Besides the given list of Neko vars you should include there all gen-classed methods (like the shown -onCreate, init etc) and other Vars that you reference directly in one way or another.

After you include and customize this profile, you can build your application with:

lein with-profile lean do clean, droid doall

Example

There is an example of Skummet usage in the sample project.

Clone this wiki locally