If you have created a library in Android Studio, you certainly want to use it in another project. The easiest way should be to create the aar file and then reference it from your new project. Prior to Android Studio 0.4.4, referencing local aar files was not supported as you can see from Xavier Ducrohet or in this issue report.

But there is an easy workaround for this. Lets see what we have to do, lets say, after you’ve created a stand alone library.

Once again, this tutorial is for Android Studio prior to version 0.4.4. Starting with version 0.4.4, things got far better as aar files can be referenced as jar files.
dependencies {
    compile files('libs/mylib.aar')
}

But if you are still using a previous version, just follow those steps.

To use an aar library, that library should be stored in a repository. You could use your local Maven repository, but using Gradle, there are other kind of repositories. And the most interesting is the flat directory repository.

So, first, lets add this kind of repository in our build.gradle file.

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

Here, I assume that your aar files will be stored in the libs folder in your project.

You can now add a dependency like

dependencies {
    compile 'net.my.package:mylib:1.0@aar'
}

Note that you must add @aar to indicate the packaging type. It looks like the group (net.my.package) don’t matter in the artifact name, only the artifact name, version and packaging type are needed.

Using the flat directory repository is certainly the easiest way to include an library in another project. But you will wave to keep the references up to date yourself. This will work great for small indie or test projects.

About Darko Stankovski

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