Android Gradle在另一个模块中包含模块依赖项 [英] Android Gradle include module dependencies in another module
问题描述
我正在使用最新的Android Studio 3.0.0-beta6来构建我的Android项目,并且存在此依赖项问题.
Gradle
鼓励我将所有compile's
替换为implementation's
.这是我的项目结构:
I am using the latest Android Studio 3.0.0-beta6 to build my Android project and there's this dependency issue.
Gradle
encouraged me to replace all compile's
with implementation's
. Here's my project structure:
项目:
-
module1
module1
- module2
Module1依赖于某些库,module2依赖于module1.但是,来自module1的库在module2中不可见.我不想复制粘贴依赖项,而是只将库依赖项声明一次.有一个简单的解决方案吗?谢谢.
Module1 depends on some libraries, module2 depends on module1. However, the libraries from module1 are not visible in module2. I don't want to copy-paste dependencies and would rather have the library dependencies declared only once. Is there a simple solution to this? Thank you.
module1的构建包:
module1's build gradle:
dependencies {
....
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
...
}
module2的构建包:
module2's build gradle:
implementation project(':module1')
推荐答案
在您的Root Project中-> build.gradle,您应该具有以下内容:
In your Root Project -> build.gradle you should have something like:
allprojects {
repositories {
jcenter()
}
}
在此处添加依赖项!
更新
如果您不希望所有模块都具有公共依赖性,而只希望特定模块,那么请执行以下操作:
If you do not want all your modules to have the common dependencies but only specific modules then do this:
- 在您的Root Project/gradleScript中创建一个文件夹
-
在此文件夹中创建一个.gradle文件(例如gradleScript/dependencies.gradle) 看起来像这样:
- Create a folder in your Root Project/gradleScript
Create a .gradle file in this folder (e.g. gradleScript/dependencies.gradle) that looks like:
ext {
//Version
supportLibrary = '22.2.1'
//Support Libraries dependencies
supportDependencies = [
design : "com.android.support:design:${supportLibrary}",
recyclerView : "com.android.support:recyclerview-v7:${supportLibrary}",
cardView : "com.android.support:cardview-v7:${supportLibrary}",
appCompat : "com.android.support:appcompat-v7:${supportLibrary}",
supportAnnotation: "com.android.support:support-annotations:${supportLibrary}",
]
}
在您的根项目build.gradle中添加以下行:
In your root project build.gradle add this line:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
// Load dependencies
apply from: 'gradleScript/dependencies.gradle'
在您的模块中相应地添加以下内容:
In your modules accordingly add this:
// Module build file
dependencies {
//......
compile supportDependencies.appCompat
compile supportDependencies.design
}
希望这会有所帮助!
这篇关于Android Gradle在另一个模块中包含模块依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!