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!

Related posts

Tags: , , , , , ,

<< Back to Blog Discuss this post

 

Checkout our new pet project:

Subscribe to our newsletter

 

22 Comments to “How to link/add an Android library project with Gradle in Android Studio”

  1. Johnb683 says:

    Fantastic website. A lot of useful information here. I’m sending it to a few pals ans also sharing in delicious. And naturally, thank you in your sweat! ddddedgakgak

  2. Ram Patnaik says:

    i am using gradle for my android app . I am having one debug.jar which have the symbol “Log & sec log” In eclipse when i add the debug.jar as dependency then build success and my app generate apk . But for gradle build i am getting error . It says symbol “Log ” not found . It not adding in gradle build . I added as below

    dependencies {
    compile ‘/home/user/repository/debug.jar’
    }

    please suggest

  3. LB says:

    What if the project doesn’t exist on maven?
    I’ve made this library, for example:
    https://github.com/AndroidDeveloperLB/MaterialPreferenceLibrary
    I’d like an app I use to import the folder of the project directly (with or without copying the content).

    How do I do that?

  4. LB says:

    Ignore the “maven” part. I accidentally wrote about this, instead of writing something else.

    Anyway, the question still stands.

  5. 失去金钱的人损失甚少,失去健康的人损失极多,失去勇气的人损失一切。

  6. It’s going to be ending of mine day, except before ending
    I am reading this wonderful piece of writing to improve my know-how.

  7. หนัง says:

    Right now it appears like BlogEngine is the top blogging platform out there right now.

    (from what I’ve read) Is that what you’re using on your blog?

  8. Hello There. I found your weblog the use of msn. This is a really smartly written article.
    I’ll be sure to bookmark it and come back to learn extra
    of your useful info. Thanks for the post.
    I will definitely return.

  9. Aw, this was an extremely nice post. Spending some time and actual
    effort to produce a top notch article… but what can I
    say… I procrastinate a lot and never manage
    to get anything done.

  10. Himanshu srivastava says:

    I am using ngnstack library ,after importing library it gives error

    Error:(1, 0) Plugin with id ‘com.android.library’ not found.

    in build.gradle of library project
    here is my library project build.gradle
    apply plugin: ‘com.android.library’

    android {
    compileSdkVersion 23
    buildToolsVersion “23″

    defaultConfig {
    minSdkVersion 15
    targetSdkVersion 23

    }

    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.txt’
    }
    }
    }

    dependencies {
    compile files(‘libs/simple-xml-2.3.4.jar’)
    }

  11. Aelaf says:

    great topic, except while contemplating about libs in android studio the very image u posted is similar to the old timer eclipse.

  12. hd porno says:

    Hi to ᥱvery body, it’s my fiгst visit of this webpage; this wᥱЬlog carrіes awesome and genuinely good stuff dеsigned for readers.

  13. porn tube says:

    I don’t even know the wаy I ended up here, hoѡever I thought this post was once good.
    I don’t know who you’re however certainly you are going
    to a famoսs blogցer in the event you aren’t already.
    Cheers!

  14. sex says:

    Greetings from Ꮮos angeles! I’m bored to tears at work so I deciԁed to checқ oսt your site on my iphone
    during lunch break. I ⅼove the info ʏou ρrovide herе and can’t wait to take
    а look when I get ɦome. I’m amazed at how quicк yοur blog ⅼoaded ߋn my cell phone ..
    ӏ’m not even using WIFI, just 3G .. Anyways, amazing
    bloǥ!

  15. xxx says:

    Thanks for every other іnfoгmatiᴠe blog. Where else may
    I аm getting that kind of info written in ѕuch
    an ideaⅼ method? I have a venture that I am simply noѡ working
    on, and I have been at the glance out for such
    info.

  16. porn video says:

    It’s realⅼy a nice and useful piece of info. I am happy that
    yօս just shared this helpful info with us. Please keeр us informed like this.
    Thank you for sharing.

  17. xxx says:

    Prᥱtty great post. I just stumbⅼed upon your weblog and wisheⅾ to mᥱntion that
    I’ve reallʏ enjoyed surfing around your weblog posts. In ɑny cɑѕe I will be suƄscribing for your feed аnd I hopе you
    write again very soon!

  18. porn says:

    Yоu can ceгtainly see your enthusiasm within the article you write.
    The sector hopes for more passionate wrіters such as
    you who aren’t afraid to mention how they believe. All the time go after your heart.

  19. free porn says:

    It is perfect time to make ѕome plans for the future and it is time
    to be happy. I have read this post and if I coսld I desire to suggest you few interesting thіngs or suggestions.
    Maybe you can wrіte next aгticles referring to this aгticle.
    I want to read even more things аbout it!

  20. xxx says:

    Hi, tɦis weekend iѕ pleɑsant designed foг mе, beϲaᥙse this occasion i am reading this
    great educаtional article here at my house.

  21. porn movies says:

    Way ϲool! Some extremely valid points! I apprеciate you
    writing this article and the rest of the website is also really good.

  22. sex videos says:

    Hi ɑll, here every one is sharing these knowledge, therefore it’s nice
    to read this weblog, and I used to pay a visit this web site everyday.

Categories:

Recent posts:

Search:

Subscribe