Transitive Dependencies Not Resolved for Aar Library Using Gradle

Transitive dependencies not resolved for aar library using gradle

I have solved my problem by setting transitive attribute for my aar dependency:

compile ('com.somepackage:LIBRARY_NAME:1.0.0@aar'){
transitive=true
}

Can an AAR include transitive dependencies?

It took a little while but I found what I was looking for. It just happened to be the way I was wording my searches.

This lesser-seen answer was exactly what I was looking for:

Transitive dependencies not resolved for aar library using gradle

Note that dependencies are only associated with aar libraries if they are hosted in a maven repository, in the first place, as the pom file is not included in the aar.

Essentially, I needed to add a

transitive = true

...to the build.gradle of Bar

Example:

compile ('com.foo:FOO:1.0.0@aar'){
transitive=true
}

This way it includes all of my transitive libraries.

Note, however, that this may actually cause conflicts between dependencies (especially local ones) which can be resolved using an exclude tag.

Transitive dependencies for local aar library

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.

Error building Android library: Direct local .aar file dependencies are not supported

I recently encountered the same issue, the fix was to remove the library from libs/ and import it using File -> New -> New Module -> Import .JAR/.AAR Package, then referencing it in the library module build.gradle file:

dependencies {
implementation project(":imported_aar_module")
}

If you are on a newer Android Studio version (4.0.0+), this option is not available. Instead you have to do it manually.

  1. Create a new directory and put the following content into the build.gradle file withing the new directory:
configurations.maybeCreate("default")
artifacts.add("default", file('[nameOfTheAar].aar'))

  1. Place the aar into this new directoy. Next to the build.gradle file.
  2. Add the new created Gradle project to the settings.gradle file:
include(":pathToTheCreatedDirectory")

  1. Include the project in your library where you want to use the aar:
implementation project(":pathToTheCreatedDirectory", configuration = "default")

How to set transitive = true for local .aar library?

It is not possible to download transitive dependencies with a local aar file.

This file does not contains a pom.xml which reference all dependencies linked to this library, so adding transitive = true will do simply nothing.

If Cuckoo library is not hosted in a Maven repository, I'm afraid you will be obliged to load them manually in your build.gradle.

Gradle - Android - 2 Libraries dependency conflict

try this:

implementation(Lib A){
exclude module : 'lib c'
}


Related Topics



Leave a reply



Submit