45

We're making some library, basicly for our API, that we would make life easier for our external developers.

So we created new library project and put Retrofit and some other libraries as dependencies.

dependencies { compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.google.code.gson:gson:2.6.2' compile 'com.squareup.retrofit2:retrofit:2.0.1' compile 'com.squareup.retrofit2:converter-gson:2.0.1' compile 'com.squareup.okhttp3:okhttp:3.2.0' } 

Now when we build it, it produces aar file.

But now when we put the aar file to libs directory and set it as dependency, we still have to put the same dependency in user's build.gradle file, which sucks. It should be taken from the library, right?

repositories { flatDir { dirs 'libs' } } dependencies { compile(name: 'ourlibrary', ext: 'aar') { transitive = true; } } 

How to make transitive = true work?

4
  • 1
    Looking for a solution for the exact same problem, how did you end up with this? Commented Sep 26, 2016 at 15:11
  • hi, are you able to solve the issue? Commented Sep 8, 2017 at 7:39
  • Hey, how did you solve this? Commented Jan 7, 2019 at 13:47
  • 2
    By putting the dependencies to README :-( Commented Jan 7, 2019 at 13:52

1 Answer 1

70

The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.

It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.

In your case adding transitive=true doesn't resolve your issue for the reason described above.

You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.

Sign up to request clarification or add additional context in comments.

5 Comments

could you elaborate on "you have to specify the dependencies also in your project"
Finally got here. It seems you have to publish it to somewhere to make the transitive work.
publish to mavenLocal. The transitive for AAR not working.
*aar file doesn't contain the nested (or transitive) dependencies* is that true for any local libs folder directory of the Android Library? Or is it for dependencies added via gradle?
@Abbas I'm looking for a proper solution for this, as I'd like to distribute a library in one file. So far the only solution I've found is creating a fat aar. However this can mess up other dependencies in the host app, so be careful if you decide to use it. Here's a link a for script that does this: github.com/adwiv/android-fat-aar Also an explanation why it's a bad idea: stackoverflow.com/questions/28605367/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.