butterKnifeVersion = “8.8.1”
bannerVersion = “1.4.10”
loggerVersion = “2.1.1”
baseRecyclerViewAdapterHelperVersion = “2.9.30”
dbflowVersion = “4.2.4”
app = [
recyclerView : “com.android.support:recyclerview-v7:
r
e
c
y
c
l
e
r
V
i
e
w
V
e
r
s
i
o
n
"
,
r
x
j
a
v
a
:
"
i
o
.
r
e
a
c
t
i
v
e
x
.
r
x
j
a
v
a
2
:
r
x
j
a
v
a
:
{recyclerViewVersion}", rxjava : "io.reactivex.rxjava2:rxjava:
recyclerViewVersion",rxjava:"io.reactivex.rxjava2:rxjava:{rxjava2Version}”,
rxandroid : “io.reactivex.rxjava2:rxandroid:
r
x
a
n
d
r
o
i
d
V
e
r
s
i
o
n
"
,
d
a
g
g
e
r
:
"
c
o
m
.
g
o
o
g
l
e
.
d
a
g
g
e
r
:
d
a
g
g
e
r
:
{rxandroidVersion}", dagger : "com.google.dagger:dagger:
rxandroidVersion",dagger:"com.google.dagger:dagger:{daggerVersion}”,
daggerCompiler : “com.google.dagger:dagger-compiler:
d
a
g
g
e
r
V
e
r
s
i
o
n
"
,
g
l
i
d
e
:
"
c
o
m
.
g
i
t
h
u
b
∗
∗
《
A
n
d
r
o
i
d
学
习
笔
记
总
结
+
最
新
移
动
架
构
视
频
+
大
厂
安
卓
面
试
真
题
+
项
目
实
战
源
码
讲
义
》
无
偿
开
源
徽
信
搜
索
公
众
号
【
编
程
进
阶
路
】
∗
∗
.
b
u
m
p
t
e
c
h
.
g
l
i
d
e
:
g
l
i
d
e
:
{daggerVersion}", glide : "com.github **《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》无偿开源 徽信搜索公众号【编程进阶路】** .bumptech.glide:glide:
daggerVersion",glide:"com.github∗∗《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》无偿开源徽信搜索公众号【编程进阶路】∗∗.bumptech.glide:glide:{glideVersion}”,
glideCompiler : “com.github.bumptech.glide:compiler:
g
l
i
d
e
V
e
r
s
i
o
n
"
,
b
u
t
e
r
K
n
i
f
e
:
"
c
o
m
.
j
a
k
e
w
h
a
r
t
o
n
:
b
u
t
t
e
r
k
n
i
f
e
:
{glideVersion}", buterKnife : "com.jakewharton:butterknife:
glideVersion",buterKnife:"com.jakewharton:butterknife:{butterKnifeVersion}”,
butterKnifeCompiler : “com.jakewharton:butterknife-compiler:
b
u
t
t
e
r
K
n
i
f
e
V
e
r
s
i
o
n
"
,
b
a
n
n
e
r
:
"
c
o
m
.
y
o
u
t
h
.
b
a
n
n
e
r
:
b
a
n
n
e
r
:
{butterKnifeVersion}", banner : "com.youth.banner:banner:
butterKnifeVersion",banner:"com.youth.banner:banner:{bannerVersion}”,
logger : “com.orhanobut:logger:
l
o
g
g
e
r
V
e
r
s
i
o
n
"
,
b
a
s
e
R
e
c
y
c
l
e
r
V
i
e
w
A
d
a
p
t
e
r
H
e
l
p
e
r
:
"
c
o
m
.
g
i
t
h
u
b
.
C
y
m
C
h
a
d
:
B
a
s
e
R
e
c
y
c
l
e
r
V
i
e
w
A
d
a
p
t
e
r
H
e
l
p
e
r
:
{loggerVersion}", baseRecyclerViewAdapterHelper: "com.github.CymChad:BaseRecyclerViewAdapterHelper:
loggerVersion",baseRecyclerViewAdapterHelper:"com.github.CymChad:BaseRecyclerViewAdapterHelper:{baseRecyclerViewAdapterHelperVersion}”,
dbflowProcessor : “com.github.Raizlabs.DBFlow:dbflow-processor:
d
b
f
l
o
w
V
e
r
s
i
o
n
"
,
d
b
f
l
o
w
C
o
r
e
:
"
c
o
m
.
g
i
t
h
u
b
.
R
a
i
z
l
a
b
s
.
D
B
F
l
o
w
:
d
b
f
l
o
w
−
c
o
r
e
:
{dbflowVersion}", dbflowCore : "com.github.Raizlabs.DBFlow:dbflow-core:
dbflowVersion",dbflowCore:"com.github.Raizlabs.DBFlow:dbflow−core:{dbflowVersion}”,
dbflow : “com.github.Raizlabs.DBFlow:dbflow:
d
b
f
l
o
w
V
e
r
s
i
o
n
"
,
d
b
f
l
o
w
R
x
2
:
"
c
o
m
.
g
i
t
h
u
b
.
R
a
i
z
l
a
b
s
.
D
B
F
l
o
w
:
d
b
f
l
o
w
−
r
x
2
:
{dbflowVersion}", dbflowRx2 : "com.github.Raizlabs.DBFlow:dbflow-rx2:
dbflowVersion",dbflowRx2:"com.github.Raizlabs.DBFlow:dbflow−rx2:{dbflowVersion}”,
]
}
版本号和具体依赖地址也分开了,更加便于管理。 其中除了依赖的地址,所有的变量名都是随便取的。app
对应于项目module app
里的依赖,当然还有 data
,domin
,common
三个 module 的依赖,声明方式跟 app
一样,只是我还没用到所以没写。
2、声明创建的文件
在项目的 build.gradle
第一行加上这行代码: apply from: "buildsystem/dependences.gradle"
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QMIvcxti-1651549340678)(https://user-gold-cdn.xitu.io/2018/11/3/166d7deec3c3dafb?imageView2/0/w/1280/h/960/ignore-error/1)]
声明之后即可在各个 module
中的 build.gradle
中愉快的引用啦。
3、在具体位置引用
打开 app
下的 build.gradle
,在需要用到的地方先声明一个变量:
def appDependence = rootProject.ext.app
rootProject 是什么意思我还不太明白,猜测应该是取到项目的根目录。 还记得 dependences.gradle
文件最外层是 ext
节点吗? rootProject.ext
相当于取到了我们提取文件的根节点,rootProject.ext.app
即取到了 app
节点声明的数组。然后再将它赋值给 appDependence
变量。
接下来就可以放心使用啦
implementation appDependence.recyclerView
implementation appDependence.rxjava
贴出 app/build.gradle
代码:
apply plugin: ‘com.android.application’
android {
compileSdkVersion rootProject.ext.androidCompileSdkVersion
buildToolsVersion rootProject.ext.androidBuildToolsVersion
defaultConfig {
applicationId “com.cachecats.meituan”
minSdkVersion rootProject.ext.androidMinSdkVersion
targetSdkVersion rootProject.ext.androidTargetSdkVersion
versionCode 1
versionName “1.0”
testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner”
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’
}
}
lintOptions {
abortOnError false
}
//支持Java8特性
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
def appDependence = rootProject.ext.app
implementation project(‘:common’)
implementation project(‘:data’)
implementation project(‘:domin’)
implementation fileTree(include: [‘*.jar’], dir: ‘libs’)
implementation ‘com.android.support:appcompat-v7:27.0.2’
implementation ‘com.android.support.constraint:constraint-layout:1.0.2’
testImplementation ‘junit:junit:4.12’
androidTestImplementation ‘com.android.support.test🏃1.0.1’
androidTestImplementation ‘com.android.support.test.espresso:espresso-core:3.0.1’
//denpendence
implementation appDependence.recyclerView
implementation appDependence.rxjava
implementation appDependence.rxandroid
implementation appDependence.dagger
annotationProcessor appDependence.daggerCompiler
implementation appDependence.glide
annotationProcessor appDependence.glideCompiler
implementation appDependence.buterKnife
annotationProcessor appDependence.butterKnifeCompiler
implementation appDependence.banner
implementation appDependence.logger
implementation appDependence.baseRecyclerViewAdapterHelper
implementation appDependence.dbflowCore
implementation appDependence.dbflowRx2
implementation appDependence.dbflow
annotationProcessor appDependence.dbflowProcessor
entation appDependence.dbflowRx2
implementation appDependence.dbflow
annotationProcessor appDependence.dbflowProcessor