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.
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.
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
.
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.
- 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'))
- Place the
aar
into this new directoy. Next to thebuild.gradle
file. - Add the new created Gradle project to the
settings.gradle
file:
include(":pathToTheCreatedDirectory")
- Include the project in your library where you want to use the
aar
:
implementation project(":pathToTheCreatedDirectory", configuration = "default")
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
}
Import library module that has dependency on local aar file
IMHO, the cleanest way to make it work would be to use some local repository, like a Maven, publish your local-lib
here, and reference it from here, and do the same for each of your libraries. When you publish to an artifact repository manager - let's say a Maven - you will have your .aar coupled with a pom file, containing all the needed dependencies.
You have to keep in mind here that your aar is kind of a flat file, meaning, while you reference it somewhere, there is not way to keep track of the transitive dependencies of it (that's the job of the pom files on Maven).
This means that when you reference F
in Installed
, the F
aar is added, but Installed
doesn't know that it has to get local-lib
in order for F
to work properly, or doesn't know where. That's why you have lines on the remote repositories: gradle searches everywhere (in every possible place = in every repository you have listed) for the dependency.
When you copy/paste the code as a module of your project, the gradle knows what are the transitive dependencies because it can access the gradle file for each dependency.
When you copy the aar directly inthe Installed/libs folder, it also works because gradle checks here (you probably have a compile line in your gradle checking for that folder).
If you want to keep the flat file, you should try putting somewhere reachable by all modules, on the same folder level (take a look at that question), or you could try to add the local-lib as an Android module project, and not just put it in the libs folder.
Related Topics
How to Use Web Camera in Android Emulator to Capture a Live Image
Android Command Line Tools Sdkmanager Always Shows: Warning: Could Not Create Settings
How to Get an Event in Android Spinner When the Current Selected Item Is Selected Again
Show an Alert Dialog in Broadcast Receiver After a System Reboot
How to Change Progressbar's Progress Indicator Color in Android
Android Studio Emulator Does Not Come with Play Store for API 23
How to Pass Drawable Between Activities
React Native Android Build Failed. Sdk Location Not Found
How to Prevent Android Bluetooth Rfcomm Connection from Dying Immediately After .Connect()
Android Studio Gradle Configuration with Name 'Default' Not Found
Android Failed to Start Emulator:Cannot Run Program
Design Android Edittext to Show Error Message as Described by Google
Custom Facebook Login Button - Android
Detecting Whether a Headset Is Plugged into an Android Device or Not