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

Hacking the plugin

satchit8 edited this page May 10, 2016 · 11 revisions

This documents explains how to setup an environment where you can modify lein-droid, experiment with it, implement new features, fix bugs etc.

Code layout

leiningen.droid is a facade namespace for all other lein-droid subtasks. It is responsible for adding different defaults to the project map by calling leininingen.droid.utils/android-parameters, before it passes the project map to the subtasks.

leiningen.droid.aar contains functions that operate on AAR archives. AAR is a special packaging format for Android libraries that combines compiled code and resources. Lein-droid must first unzip AAR dependencies before they can be used.

leininged.droid.classpath initializes several hooks that modify Leiningen behavior in certain ways. For example, there is a hook that adds a proper android.jar to the classpath every time get-classpath is called; a hook for removing duplicate dependencies from the project etc.

leiningen.droid.(code-gen|compile|build|deploy) mostly consist of subtasks and helper functions that bring the project the whole way from clean target to a deployed application.

leiningen.droid.manifest hosts functions that operate on AndroidManifest.xml and its templates, create and parse manifests.

leiningen.droid.new namespace is a home to new subtask that creates new Clojure-Android projects from a template. Template resources live in res/templates/ directory.

leiningen.droid.sideload is an utility namespace that allows to dynamically load some tooling libraries that can only be obtained from SDK directory, and exposes functionality of those libraries via reflection.

leiningen.droid.test provides a subtask for running local tests in Clojure-Android projects.

leiningen.droid.utils contains general-purpose utilities which are used by other namespaces.

Dev environment

You can develop lein-droid using CIDER or any other REPL provider. If used with CIDER, you’d have to comment :eval-in-leiningen true line, and add [leiningen "2.5.1"] to the dependencies (this is a workaround for a bug in Leiningen). Now you can jack into the plugin.

Another way to use the development plugin is to set some environment variables (LEIN_DROID_PROFILES and LEIN_DROID_PROJECT) and run the lein droid ... commands from the plugin folder. To make sure that lein-droid is loaded from sources and not from the packaged jar from Clojars:

  1. Determine which profile(s) to use (e.g. dev) and the full path to a Clojure on Android project.
  2. Call lein droid ... subtasks from lein-droid/ directory with the environment variables LEIN_DROID_PROFILES and LEIN_DROID_PROJECT set appropriately. This way sources of the plugin will be loaded and used.

For example (assuming lein-droid and foreclojure-android source directories live under ~/src):

cd ~/src/lein-droid
LEIN_DROID_PROFILES=dev \
LEIN_DROID_PROJECT=$HOME/src/foreclojure-android/project.clj \
lein do clean, droid clean, droid doall

Now you are able to execute lein-droid subtasks from lein-droid/ folder like you do from your project folder, and using the latest changes you’ve made to the plugin. But to do that you’ll have to have :eval-in-leiningen true in lein-droid (i.e. plugin)’s project.clj, so you must comment/uncomment that line every time you restart a REPL.