Androidsx is now Perops. Visit us at perops.com

Androidsx Androidsx | android and wearable developers

 

Subscribe for market insights and new posts

 

How to link/add an Android library project with Gradle in Android Studio

July 29, 2013 at 1:28 am | android, blog | 22 comments

 

This post intends to share how to import and add your Android project from Eclipse into Android Studio and Gradle, the new build system for Android. In particular, we address the case where you use at least one Android library project.

To answer this question, we have prepared this project in GitHub that just does the bare minimum to get this setup working:

  • An Android application in the HelloWorld project.
  • An Android library in the MyLibrary project library.

Once it is done, it all looks fairly obvious. The key is to add a dependency from the application project, in the build.gradle file:

dependencies {
    compile files('libs/android-support-v4.jar')
    compile project(':MyLibrary')
}

And, in the IntelliJ Module file, HelloWorld.iml:

<orderEntry type="library" name="android-support-v4" level="application" />
<orderEntry type="library" name="MyLibrary.aar" level="project" />

In the library project, there’s not much to do: tell Gradle and Android Studio that this is an Android library, with apply plugin: ‘android-library’ and <option name=”LIBRARY_PROJECT” value=”true” />, respectively.

In our case, for Chat Toolkit, we have a few libraries, so our property files are a bit more complicated:

Chat Toolkit modules

If your dependency tree is also complex and you’re unfamiliar with Gradle, we’d strongly encourage you to experiment first with this Hello-world type project to understand the basics before you migrate your project.

Good luck!

 

Categories:

Recent posts:

Search:

Subscribe