Creating AAR libraries

Alexander Yakushev edited this page Jul 25, 2015 · 1 revision

AAR is a special Android packaging format that combines code and resources. It was created to replace the inconvenient library project dependencies that required you to keep every dependency on your disk in source code format. Lein-droid used to support it too via :project-dependencies option, but now AAR libraries is a preferred method.

How to include already existing AAR libraries is described here, this document focuses on how to create and publish your own AARs.

Creating a new library project

You can create a library project by executing:

lein new droid awesomelib :library true

This will create a scaffolding for your future library that can contain Java code, Clojure code and resources. In order to build the library use:

lein droid aar

You may also publish the freshly created AAR package to your local Maven repository:

lein droid local-repo

Or you can deploy it to a remote repository just like any other JAR archive. Just make sure that the library is remotely saved as an AAR and not JAR.

Converting an existing library project

If you have a library that you previously used as a project dependency, you can convert it into AAR too. First, execute the following inside its root folder:

lein new droid :init

This will create a project.clj file for the library. You may want to make some changes to it, like uncomment :java-only true if the project only contains Java code; or provide source paths to Clojure code. To package the archive you perform the same lein droid aar.

Creating JAR libraries

If the library you are making doesn’t have any resources, you can distribute it in a JAR like any other Java dependency. In this case you’d want to create a new library project and remove :packaging "aar". from project.clj. To build the library use:

lein droid jar
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.