6

I am using Android Studio 1.2

I create a private library I want to use that one in another application.

To use it I create an AAR files, but this AAR don't work. I have in my library a dependency to an AAR file.

The AAR files do not the dependencies?

If I use the jar and I includ ans create all the dependencies the project works fine.

NOTE :

I know how to importe the AAR file. The problem is to use an AAR in the AAR..

Thanks.

  • The 2nd line in your question seems to conflict with the last. If you want to depend on an AAR in another AAR, that means you want to use an AAR in a **Library** project, but the 2nd line says "I want to use that one in another **application**" – Stan Kurdziel Jun 22 '15 at 04:11
  • did you find any solution? – mostafa hashim Jun 11 '19 at 12:34

2 Answers2

8

If I'm understanding your question correctly, there are 3 projects involved:

Library Project 2 --> Library Project 1 --> Application Project

You are editing "Library Project 1" and have added to it's app/build.grade a dependency on the Library Project 2's aar. Something like this: compile 'com.arasthel:gnavdrawer-library:1.1.5'

I am not sure where you are running into an issue, but I'll attempt an answer anyway. If I'm completely off-base, can you please elaborate on how the AAR dependency is not working? Any error messages?, a class/resource not found, etc.

I think it's unlikely you are unable to use a class from Library Project 2 inside Library Project 1, because I just tried this myself and it seems to be working just fine. It's worth noting that the Library Project 1 aar file will NOT include classes or resources from Library Project 2. Library Project 2 will be noted as a dependency in Library Project 1's pom if published using gradle's maven plugin to publish Library Project 1.

My guess is that you are having a problem in the Application Project? Perhaps the class from Library Project 2 is not found in the Application Project? If that is correct, then there are two possible solutions:

  1. Enable transitive dependencies on the aar dependency in the Application project's app/build.gradle: Instead of compile 'com.example:myLibrary:versionX', make it compile('com.example:myLibrary:versionX'){transitive=true}. I just verified this causes gradle to read Library Project 1's pom and automatically add dependencies found there into the Application Project.

    If you would like to use transitive dependencies, your Library Project will need to be generating a pom and publishing it along with the aar. See https://stackoverflow.com/a/30085677/431296 for some additional information on how I have this working.

  2. Manually add the dependency on Library Project 2 to the Application Project - so that your Application has a dependency line for both Libraries. Depending on your specific situation this may or may not be a workable solution.

Community
  • 1
  • 1
Stan Kurdziel
  • 5,476
  • 1
  • 43
  • 42
  • Your schematisation is good. I have 4 Library Project 2, but this don't change the problem. In reality, I would like to have just an AAR file with all the dependencies. Now, we are putting the Library Project 2 like a dependency of the Application Project for use it with the Library Project 1. It's a little bit confused. – David Cesar Santos Jun 24 '15 at 08:52
  • OK, so it sounds like you are already using option 2 (manually adding extra dependencies to the app). Using transitive dependencies (option 1) would allow you to specify the dependencies once in Library Project 1. – Stan Kurdziel Jun 24 '15 at 13:36
  • @StanKurdziel I just tried your suggestion and it worked like a charm for me. Here is a link to my question: http://stackoverflow.com/questions/34445399/create-an-aar-with-multiple-aars-jars – Anil Gorthy Dec 28 '15 at 08:40
-2

Add following code to you project build.gradle file, and you should put you AAR file to the libs folder.

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

And finally add compile info to your dependencies:

dependencies {
    compile(name:'AARFileName', ext:'aar')
}
codezjx
  • 9,012
  • 5
  • 47
  • 57
  • It's much better to publish your Library projects to your local maven repo using `gradlew uploadArchives` than adding the libs folder as a local repository. Here's some info on doing that: http://stackoverflow.com/a/30085677/431296 – Stan Kurdziel Jun 22 '15 at 05:09