I have a multi-module project in android studio and I want to integrate an .aar
file in a module which is beeing referenced as library in the App module. The project structure is namely:
- module1
- module2
- module3
- module4
- moduleApp
The module1 is used as library reference in the module2.
build.gradle module2
:
dependencies {
...
compile project(':module1')
}
The module2 and the other modules are referenced in th App module.
build.gradle moduleApp
:
dependencies {
...
compile project(':module2')
compile project(':module3')
compile project(':module4')
}
I need to integrate an .aar file as library in the module1, since it is required from the module1 impementation. I do the integration in the normal manner:
build.gradle module1
:
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile 'package.name.of.aar:myLibrary@aar'
}
However when I run the gradle sync
I receive the error:
failed to resolve package.name.of.aar:myLibrary@aar in module2
failed to resolve package.name.of.aar:myLibrary@aar in moduleApp
What should I do to let module2 and moduleApp find the .aar library? Should I include something more in their the build.gradle files?
Try changing
dependencies {
compile 'package.name.of.aar:myLibrary@aar'
}
to:
dependencies {
compile ('package.name.of.aar:myLibrary@aar'){
transitive=true
}
}
Alternatively, just add:
compile 'package.name.of.aar:myLibrary@aar'
to module2 and moduleApp
Since you are using an aar file with a flat repo
, in all modules which use the module1 (in your case module2 and the app) where you need the aar file you have to add in your build.gradle
the repository:
repositories {
flatDir {
dirs 'libs'
}
}
and add the dependency:
dependencies {
compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.