java Gradle 构建无法解析 aar 库依赖项 (trnql sdk)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34864931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle build failed to resolve aar library dependency (trnql sdk)
提问by Cognitio
When I attempt to build my project using gradle, I get the following error:
当我尝试使用 gradle 构建我的项目时,出现以下错误:
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:
似乎找不到 libs 文件夹中的 android 存档文件 (aar)。build.gradle 文件的依赖项部分如下所示:
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?
aar 文件是有效的,只是构建系统没有解析它。我能做些什么来解决这个问题?
采纳答案by nazmul idris
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..."
compile 'com.trnql:lib-release:1.0.0@aar' 转到“compile fileTree...”下方的列表顶部
回答by ben75
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 :
这里的问题是 gradle 会尝试在声明的存储库之一中找到这个 aar。libs 目录不是存储库...但是您可以像这样声明它:
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
and gradle will find it.
并且 gradle 会找到它。
回答by Andras Kloczl
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
当你创建一个新的 Android studio 项目时,你的顶级 build.gradle 将有一个 buildscript 和一个 allproject 部分(见下文),如果你插入
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 的存储库,它不会工作。
您必须将其粘贴到 allprojects 的存储库中,如下所示:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
}
回答by Tash Pemhiwa
In my case, in my library module my build.gradle looked something like:
就我而言,在我的库模块中,我的 build.gradle 看起来像:
buildscript {
repositories {
flatDir {
dirs "libs"
}
}
}
I had to remove the buildscript
bit so that it looked like this in the end:
我不得不删除该buildscript
位,使其最终看起来像这样:
repositories {
flatDir {
dirs "libs"
}
}
Then it was able to sync and, thereafter, build.
然后它能够同步,然后构建。
回答by huangxin
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
将你的 aar 文件放在 libs 目录中,然后像下面这样修改你的 build.gradle 文件的一部分,不同的是你在编译 fileTree 时错过了 *.aar
repositories {
flatDir {
dirs 'libs'
}
}
compile fileTree(dir:'libs', include:['*.jar', '*.aar'])
回答by Richard
And to be complete as possible: Lets say you want your AAR's in another directory in a sub-module....
并尽可能完整:假设您希望您的 AAR 位于子模块的另一个目录中....
Then in your TOP LEVEL project's build.gradle file, you would do the following:
然后在您的 TOP LEVEL 项目的 build.gradle 文件中,您将执行以下操作:
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:
然后您的 TOP LEVEL GRADLE FILE 中的行将如下所示:
dirs project(':MyFancyModule').file('aars')