Consuming AARs from Eclipse
Increasingly, you will find that libraries for Android developers come only in AAR form. For example, many of the libraries that are part of the “L” Developer Preview have only been shipped to date in AAR form.
This is wonderful if you are using Gradle for Android, with or without Android Studio. It is less than wonderful if you are using Eclipse/ADT.
UPDATE: If you are using Eclipse/ADT with Maven, the
which I had forgotten when I originally wrote this post. Many thanks to
William Ferguson for slapping me with an appropriately-sized trout for
Fortunately, a StackOverflow user named
FD_ came up with
a basic recipe for converting an AAR into an Android library project,
one that can be used from Eclipse/ADT. I have tested the recipe, have confirmed
that it appears to work, and have created
a Ruby script to automate the conversion.
The steps that my
deaar script goes through are reminiscent of
UnZIP the AAR into some directory.
Create an empty directory that will be the home for the Android library project. For the rest of these steps, I will refer to this as “the output directory”.
assets/directories from the AAR into the output directory.
libs/directory in the output directory. Copy into
classes.jarfrom the root of the unZIPped AAR, plus anything in
libs/in the AAR (e.g.,
mediarouter-v7has its own JAR of proprietary bits).
Decide what build SDK you want to try to use. You might just choose the highest SDK version you have installed. Or, you can use the
-vNNresource set qualifiers to get clues as to what a good build SDK might be. If desired, create a
project.propertiesfile with a
target=android-NNNline, where NNN is your chosen build SDK. Or, you can address this in Eclipse later on.
Import the resulting project into Eclipse, and if needed adjust the build SDK (Project > Properties > Android). Also, you will need to attach to this library project any library projects it depends upon (e.g.,
This is all based on the current AAR packaging, and therefore is subject to change.
Also, be sure to see if the AAR is natively available as an Eclipse-friendly Android library project, such as from an open source project’s repository. For example, all of my CWAC libraries ship as Eclipse-friendly Android library projects, in addition to AARs (and, for those not needing resources, JARs). This sort of AAR conversion should be an avenue of last resort, not the first thing you try.
If you try the
deaar script and run into problems with it, please use the support
options listed in the project’s
README. If you run into AARs that do not appear
to work using this script, drop me a line.
Want an expert opinion on your Android app architecture decisions? Perhaps Mark Murphy can help!