forked from Blankj/AndroidUtilCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.gradle
198 lines (172 loc) · 6.35 KB
/
config.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
ext {
androidConfig = [
applicationId : 'com.blankj.androidutilcode',
appName : 'Util',
compileSdkVersion: 27,
minSdkVersion : 14,
targetSdkVersion : 27,
versionCode : 1_018_004,
versionName : '1.18.4'// E.g 1.9.72 => 1,009,072
]
versionConfig = [
// plugin
gradle : '3.1.3',
kotlin : '1.2.30',
// lib
support : '27.1.0',
gson : '2.8.2',
glide : '4.7.1',
leakcanary : '1.5.4',
// test
junit : '4.12',
robolectric: '3.1.2'
]
depConfig = [
gradle : "com.android.tools.build:gradle:$versionConfig.gradle",
kotlin_gradle_plugin: "org.jetbrains.kotlin:kotlin-gradle-plugin:$versionConfig.kotlin",
support : [
appcompat_v7: "com.android.support:appcompat-v7:$versionConfig.support",
design : "com.android.support:design:$versionConfig.support",
],
kotlin_stdlib_jdk7 : "org.jetbrains.kotlin:kotlin-stdlib-jdk7",
leakcanary : [
android : "com.squareup.leakcanary:leakcanary-android:$versionConfig.leakcanary",
android_no_op: "com.squareup.leakcanary:leakcanary-android-no-op:$versionConfig.leakcanary",
],
gson : "com.google.code.gson:gson:$versionConfig.gson",
glide : "com.github.bumptech.glide:glide:$versionConfig.glide",
junit : "junit:junit:$versionConfig.junit",
robolectric : "org.robolectric:robolectric:$versionConfig.robolectric",
]
configAndroidDomain = this.&configAndroidDomain
configAppDependencies = this.&configAppDependencies
configUtilCodeDependencies = this.&configUtilCodeDependencies
configSubUtilDependencies = this.&configSubUtilDependencies
}
def configAndroidDomain(Project pro) {
if (pro.plugins.hasPlugin("com.android.application")) {
configAppAndroidDomain(pro)
} else {
configLibAndroidDomain(pro)
}
}
def configAppAndroidDomain(Project pro) {
configField(pro)
configSigning(pro)
configApkName(pro)
pro.android {
compileSdkVersion androidConfig.compileSdkVersion
defaultConfig {
applicationId androidConfig.applicationId
minSdkVersion androidConfig.minSdkVersion
targetSdkVersion androidConfig.targetSdkVersion
versionCode androidConfig.versionCode
versionName androidConfig.versionName
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.res.srcDirs += 'src/main/res_core'
main.res.srcDirs += 'src/main/res_sub'
}
lintOptions {
abortOnError false
}
}
}
def configField(Project pro) {
pro.android.defaultConfig {
resValue "string", "app_name", androidConfig.appName
}
}
def configSigning(Project pro) {
File signPropertiesFile = file('sign/keystore.properties')
if (!signPropertiesFile.exists()) return
pro.android {
Properties properties = new Properties()
properties.load(new FileInputStream(signPropertiesFile))
signingConfigs {
release {
storeFile file(properties['keystore'])
storePassword properties['storePassword']
keyAlias properties['keyAlias']
keyPassword properties['keyPassword']
}
}
buildTypes.release.signingConfig signingConfigs.release
}
}
def configApkName(Project pro) {
pro.android.applicationVariants.all { variant ->
if (variant.buildType.name != "debug") {
variant.getPackageApplication().outputDirectory = new File(project.rootDir.absolutePath + "/apk")
variant.getPackageApplication().outputScope.apkDatas.forEach { apkData ->
apkData.outputFileName = "util_" + variant.versionName.replace(".", "_") + ".apk"
}
}
}
}
def configLibAndroidDomain(Project pro) {
pro.android {
compileSdkVersion androidConfig.compileSdkVersion
defaultConfig {
minSdkVersion androidConfig.minSdkVersion
versionCode androidConfig.versionCode
versionName androidConfig.versionName
}
buildTypes {
release {
minifyEnabled false
// consumerProguardFiles 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
testOptions.unitTests.all {
testLogging {
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
}
}
}
}
def configAppDependencies(Project pro) {
pro.dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':utilcode')
implementation project(':subutil')
implementation depConfig.support.appcompat_v7
implementation depConfig.support.design
implementation 'com.r0adkll:slidableactivity:2.0.5'
// LeakCanary
debugImplementation depConfig.leakcanary.android
releaseImplementation depConfig.leakcanary.android_no_op
// implementation 'com.blankj:utilcode:1.18.4'
}
}
def configUtilCodeDependencies(Project pro) {
pro.dependencies {
compileOnly depConfig.support.appcompat_v7
compileOnly depConfig.support.design
testImplementation depConfig.junit
testImplementation depConfig.robolectric
testImplementation depConfig.support.appcompat_v7
}
}
def configSubUtilDependencies(Project pro) {
pro.dependencies {
compileOnly depConfig.support.appcompat_v7
compileOnly depConfig.support.design
api depConfig.gson
api(depConfig.glide) {
exclude group: "com.android.support"
}
testImplementation depConfig.junit
testImplementation depConfig.robolectric
}
}