When I attempt to build my project using gradle, I get the following error:
Failed to resolve: com.trnql:lib-release 1.0.0
It seems it cannot find the android archive file (aar) that is in the libs folder. The dependencies section of the build.gradle file looks like this:
And the project structure looks like this:
The aar file is valid, it is just not resolved by the build system. What can I do to fix this problem?
The problem here is that gradle will try to find this aar in one of the declared repository. The libs directory is not a repository... BUT you can declare it like this :
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
and gradle will find it.
When you create a new Android studio project, your top level build.gradle will have a buildscript and an allproject part (see below), and if you insert the
flatDir {
dirs 'libs'
}
part into the buildscript's repositories, it won't work.
You have to paste it into the allprojects' repositories, like here:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
}
In my case, in my library module my build.gradle looked something like:
buildscript {
repositories {
flatDir {
dirs "libs"
}
}
}
I had to remove the buildscript
bit so that it looked like this in the end:
repositories {
flatDir {
dirs "libs"
}
}
Then it was able to sync and, thereafter, build.
And to be complete as possible: Lets say you want your AAR's in another directory in a sub-module....
Then in your TOP LEVEL project's build.gradle file, you would do the following:
buildscript {
// stuff here
}
allprojects {
repositories {
// all your standard stuff, jcenter, maven, etc
flatDir {
dirs project(':MY_MODULE_NAME').file('MODULE_SUB_DIRECTORY')
}
}
}
If your module directory layout looked like this:
MyFancyModule/
/aars <-- aar files go here
/build
/libs <-- jar files go here
/src
build.gradle <-- this is NOT your top level gradle file
Then the line in your TOP LEVEL GRADLE FILE would look like:
dirs project(':MyFancyModule').file('aars')
put your aar file in libs dir, then modify part of your build.gradle file like below, the difference is that you missed *.aar when compile fileTree
repositories {
flatDir {
dirs 'libs'
}
}
compile fileTree(dir:'libs', include:['*.jar', '*.aar'])
The dependency needs to be at the top of the list of dependencies.
compile 'com.trnql:lib-release:1.0.0@aar' goes to the top of the list just under "compile fileTree..."
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.