As a software developer, you know that reusable ressources should be in libraries. Android is a Java-based technology, so, your library can be a jar file. But if you want to store some Android specific resources, you need to create a Android Library Project.

Google released Android Studio as the main development platform for Android. Android Studio is a packages IntelliJ Idea environment and relies on Gradle for the build management. At the time being, it is a little unclear how to manage a library so this is a first tutorial.

The first source of documentation is the new build system’s User Guide. This is the configuration you’ll see if you look for any information on the web. In short, you will create your project which will contain two modules. One is your main project (your app), the other is your library.

In my opinion, it is not the best structure. The project and the library are stuck together, so you will have to compile them together and store them together in the same GIT project. Unless, of course, you manage to configure different GIT projects in the same Android Studio project…

I don’t have any problem to see both modules in the same project, but a library will certainly evolve independently from the app. You may need to modify your library because of another project, and that modification should not concern the first app.

So, I want that library module to be the only module of my project. To do so, there is only one configuration line to change. Check the build.gradle files. If you want to turn a project in an Android Studio Library project, simply change

apply plugin: 'android'


apply plugin: 'android-library'

That’s it. Now, from a terminal windows, once in your project folder, you can execute the following commands:

./gradlew clean
./gradlew aR

Oh, are you familiar with this one ? aR is an alias for assembleRelease. Once it is done, you’ll find your archive in the build/libs folder as an .aar file.

Awesome, so now, will we just have to copy this aar file in the libs folder of any of our projects ? Yes, but Android Studio does not support local library files that easily. Read my next post to learn how to make it possible.

About Darko Stankovski

Darko Stankovski is the founder and editor of Dad 3.0. You can find more about him trough the following links.