Android Gradle 将外部库和嵌套的外部库添加到项目中
如何将外部库和嵌套的外部库添加到 Android 项目中?
我的项目结构(不允许更改)
- 应用/
- 应用1/
- build.gradle
- settings.gradle
- 库/
- 图书馆1/
- 构建级
- settings.gradle
- 库2/
- 构建级
- settings.gradle
- 库3/
- 构建级
- settings.gradle
- 图书馆4/
- 构建级
- settings.gradle
- 图书馆1/
- 应用1/
应用1
App1/build.gradle
buildscript {
...
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':..:libraries:library1')
compile project(':..:libraries:library2')
compile project(':..:libraries:library3')
compile project(':..:libraries:library4')
}
android {
...
}
App1不直接依赖于或,但是,如果我没有将它们包含在文件和文件的依赖项中,它将抱怨。所以,我把它们包括在内,只是为了阻止它抱怨。library3
library4
build.gradle
settings.gradle
App1/settings.gradle
include ':'
include '..:libraries:library1'
include '..:libraries:library2'
include '..:libraries:library3'
include '..:libraries:library4'
图书馆1
library1/build.gradle
buildscript {
...
}
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':..:library3')
compile project(':..:library4')
}
android {
...
}
library1/settings.gradle
include ':'
include '..:library3'
include '..:library4'
库2..4
库2..4/build.gradle
buildscript {
...
}
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
...
}
库2..4/设置
include ':'
当尝试在 i 得到以下错误:gradlew clean build
App1
FAILURE: Build failed with an exception.
* Where:
Build file '/home/user/projects/branches/branch1/Apps/libraries/library1/build.gradle' line: 15
* What went wrong:
A problem occurred evaluating project ':..:library:library1'.
> Project with path ':..:library3' could not be found in project ':..:library:library1'.
第 15 行位于文件中。compile project(':..:library3')
library1/build.gradle
如何将外部库和嵌套的外部库添加到 Android 项目中?