Android的摇篮添加外部库和嵌入外部库项目 [英] Android Gradle adding external library and nested external libraries to a project
问题描述
我如何添加一个外部库和嵌入外部库到Android项目?
How do i add an external library and nested external libraries to an android project?
我的项目结构(不能更改)
- 应用程序/
- 在App1的/
- build.gradle
- settings.gradle
- Apps/
- App1/
- build.gradle
- settings.gradle
- LIBRARY1 /
- build.grade
- settings.gradle
- library1/
- build.grade
- settings.gradle
- build.grade
- settings.gradle
- build.grade
- settings.gradle
- build.grade
- settings.gradle
程序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 does not directly depend on
library3
orlibrary4
, however, it will complain if i don't include them in the dependencies in thebuild.gradle
file and thesettings.gradle
file. So, i have them included just to stop it from complaining.程序App1 / settings.gradle
include ':' include '..:libraries:library1' include '..:libraries:library2' include '..:libraries:library3' include '..:libraries:library4'
LIBRARY1
LIBRARY1 / build.gradle
library1
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'
library2..4
library2..4 / build.gradle
library2..4
library2..4/build.gradle
buildscript { ... } apply plugin: 'android-library' dependencies { compile fileTree(dir: 'libs', include: '*.jar') } android { ... }
library2..4 / settings.gradle
include ':'
在对
程序App1
我收到以下错误试图gradlew干净的构建
:
When trying to
gradlew clean build
onApp1
i get the following error: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行是
编制项目(':..:library3')
在LIBRARY1 / build.gradle
文件。我如何添加一个外部库和嵌入外部库到Android项目?
How do i add an external library and nested external libraries to an android project?
推荐答案
在你的顶层settings.gradle(程序App1 / settings.gradle)的文件做这样的事情每个库
In your top level settings.gradle (App1/settings.gradle) file do something like this for each library
include ':library1' include ':library2' include ':library3' include ':library4' project(':library1').projectDir = new File(rootProject.projectDir, '../libraries/library1') project(':library2').projectDir = new File(rootProject.projectDir, '../libraries/library2') project(':library3').projectDir = new File(rootProject.projectDir, '../libraries/library3') project(':library4').projectDir = new File(rootProject.projectDir, '../libraries/library4')
删除其他settings.gradle文件,你不需要他们。
Remove the other settings.gradle files, you don't need them
然后在每个生成脚本,你只需要使用
then in each build script you only need to use
compile project (':library1') compile project (':library2') etc....
上面所述只是用在根项目(App1的)。一个settings.gradle文件
as stated above just use a single settings.gradle file in the root project (App1).
然后从App1的文件夹中运行
gradlew清洁:LIBRARY1:打造
来验证LIBRARY1是建立正确Then from your App1 folder run
gradlew clean :library1:build
to validate that library1 is building correctly.至于有关App1的问题抱怨缺少库的3安培; 4,你确定你没有code在应用程序直接引用这些库,要么或编译LIBRARY1时库没有被发现。建立每个库单独验证它们都建立ok了。
As for the issue about App1 complaining about missing libraries 3 & 4, are you sure you have no code in the app directly referencing these libraries, either that or the libraries are not being found when compiling library1. Build each library individually to validate they all build ok.
这篇关于Android的摇篮添加外部库和嵌入外部库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- App1/
- 在App1的/