forked from MrWu94/AndroidNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
449 lines (384 loc) · 15.5 KB
/
build.gradle
File metadata and controls
449 lines (384 loc) · 15.5 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
apply plugin: 'com.android.application'
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'android-apt'
apply plugin: 'com.antfortune.freeline'
apply plugin: 'com.jakewharton.hugo'
apply plugin: 'tinyPIC'
apply plugin: 'AndResGuard'
//Groovy 的基本语法
//方法调用
//以上语句中的apply是一个方法,给它传递了一个参数plugin,plugin 的值
//闭包
//Groovy中花括号包含的部分成为一个闭包(Closure)。例如下面的代码
//compileOptions 是一个 Method, 它的参数是一个闭包
//def releaseTime() {
// return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
//}
android {
def globalConfiguration = rootProject.ext.android
compileSdkVersion globalConfiguration.AndroidCompileSdkVersion
buildToolsVersion globalConfiguration.AndroidBuildToolsVersion
defaultConfig {
applicationId globalConfiguration.applicationId
minSdkVersion globalConfiguration.AndridMinSdkVersion
targetSdkVersion globalConfiguration.AndroidTargetSdkVersion
multiDexEnabled true
resConfigs "zh"
versionCode globalConfiguration.versionCode
versionName globalConfiguration.versionName
//ADD THIS LINE:
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
ndk {
moduleName "hello_jni" //生成的so文件名字,调用C程序的代码中会用到该名字
// abiFilters "armeabi", "armeabi-v7a", "x86" //输出指定三种平台下的so库,设置所需要的so库架构
}
}
//构建类型
buildTypes {
release {
// 不显示Log
// buildConfigField "boolean", "LOG_DEBUG", "false"
// 混淆
minifyEnabled true
// Zipalign优化
zipAlignEnabled true
// 移除无用的resource文件
shrinkResources true
// 前一部分代表系统默认的android程序的混淆文件,该文件已经包含了基本的混淆声明,后一个文件是自己的定义混淆文件
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationIdSuffix '.release' // 设置release时的包名,设置应用 ID
// 定义库的私有混淆
// consumerProguardFiles 'consumer-proguard-rules.pro'
}
}
// android.applicationVariants.all { variant ->
// variant.outputs.each { output ->
// def outputFile = output.outputFile
// if (outputFile != null && outputFile.name.endsWith('.apk')) {
// //这里修改apk文件名
// def fileName = outputFile.name.replace("app","${defaultConfig.applicationId }_${defaultConfig.versionName}_${releaseTime() }")
// output.outputFile = new File(outputFile.parent, fileName)
// }
// }
// }
//关于Android Studio中点9图的编译错误问题
// Android Studio内嵌了SDK中的draw9Patch工具,可以直接打开点9图并编辑预览,
// 只需要将引入的点9图四边黑线按要求补全,然后重新Clean一下
// Error:Execution failed for task ':app:mergeDebugResources'.
// > Some file crunching failed, see logs for details
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
//显示依赖包的存储路径
task showMeCache << {
configurations.compile.each { println it }
}
// useLibrary 'org.apache.http.legacy'
lintOptions {
disable 'InvalidPackage'
abortOnError false
}
// 提示:如果要从增量构建中永久跳过lint检查,可以将其添加到build.gradle中:
tasks.whenTaskAdded { task ->
if (task.name.equals("lint")) {
task.enabled = false
}
}
packagingOptions {
// Java的注释冲突
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
sourceSets {
main {
java.srcDirs = ['src/main/java', 'src/main/java-gen']
res.srcDirs = ['src/main/res/layout/activity',
'src/main/res/layout/fragment',
'src/main/res/'
]
// jni.srcDirs = ['src/main/jni', 'src/main/jni/']
}
}
//开启gradle的增量编译,加快编译。
// 使用递增的dex
// 增加dex的容量.http://stackoverflow.com/questions/25006075/extremely-long-build-with-gradle-android-studio
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
// incremental true
}
signingConfigs {
debug {
}
release {
//storeFile file("../yourapp.keystore")
//storePassword "your password"
//keyAlias "your alias"
//keyPassword "your password"
//setting your signing.properties
//first, add signing.properties to ./app/
//second, add property STORE_FILE, STORE_PASSWORD, KEY_ALIAS, KEY_PASSWORD
}
}
// 设置java版本
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
andResGuard{
// mappingFile = file("./resource_mapping.txt")
mappingFile = null
// 当你使用v2签名的时候,7zip压缩是无法生效的。
use7zip = true
useSign = true
// 打开这个开关,会keep住所有资源的原始路径,只混淆资源的名字
keepRoot = false
whiteList = [
// for your icon
"R.drawable.icon",
// for fabric
"R.string.com.crashlytics.*",
// for umeng update
"R.string.umeng*",
"R.string.UM*",
"R.string.tb_*",
"R.layout.umeng*",
"R.layout.tb_*",
"R.drawable.umeng*",
"R.drawable.tb_*",
"R.anim.umeng*",
"R.color.umeng*",
"R.color.tb_*",
"R.style.*UM*",
"R.style.umeng*",
"R.id.umeng*",
// umeng share for sina
"R.drawable.sina*",
// for google-services.json
"R.string.google_app_id",
"R.string.gcm_defaultSenderId",
"R.string.default_web_client_id",
"R.string.ga_trackingId",
"R.string.firebase_database_url",
"R.string.google_api_key",
"R.string.google_crash_reporting_api_key",
// umeng share for facebook
"R.layout.*facebook*",
"R.id.*facebook*",
// umeng share for messager
"R.layout.*messager*",
"R.id.*messager*",
// umeng share commond
"R.id.progress_bar_parent",
"R.id.webView"
]
compressFilePattern = [
"*.png",
"*.jpg",
"*.jpeg",
"*.gif",
"resources.arsc"
]
sevenzip {
artifact = 'com.tencent.mm:SevenZip:1.2.1'
//path = "/usr/local/bin/7za"
}
}
tinyinfo {
apiKey = 'UOw4TImgfWX6J_HufF24Rimgl8AHjWNK'
//是否跳过此task
skip = true
//是否打印日志
isShowLog = false
}
repositories {
flatDir {
dirs 'aars'
}
}
//http://tech.meituan.com/mt-android-auto-split-dex.html
tasks.whenTaskAdded { task ->
if (task.name.startsWith('proguard') && (task.name.endsWith('Debug') || task.name.endsWith('Release'))) {
task.doLast {
makeDexFileAfterProguardJar();
}
task.doFirst {
delete "${project.buildDir}/intermediates/classes-proguard";
String flavor = task.name.substring('proguard'.length(), task.name.lastIndexOf(task.name.endsWith('Debug') ? "Debug" : "Release"));
generateMainIndexKeepList(flavor.toLowerCase());
}
} else if (task.name.startsWith('zipalign') && (task.name.endsWith('Debug') || task.name.endsWith('Release'))) {
task.doFirst {
ensureMultiDexInApk();
}
}
}
def propFile = project.rootProject.file('signing.properties');
if (propFile.exists()) {
def Properties props = new Properties()
props.load(new FileInputStream(propFile))
if (props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') &&
props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) {
android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
} else {
android.buildTypes.release.signingConfig = null
}
} else {
android.buildTypes.release.signingConfig = null
}
// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
'main', // main sample code; look here for the interesting stuff.
'common', // components that are reused by multiple samples
'template'] // boilerplate code that is generated by the sample template process
repositories {
jcenter()
maven { url "https://github.com/alter-ego/advanced-android-logger/raw/develop/releases/" }
}
checkstyle {
toolVersion = "6.14"
}
task checkstyle(type: Checkstyle) {
configFile file("${project.rootDir}/config/checkstyle/checkstyle.xml")
source 'src/main/java'
include '**/*.java'
exclude '**/gen/**'
classpath = files()
}
//findbugs 分析的是 class 文件,所以就从 classes 配置来找原因。发现 java 和 android 构建后的目录结构是不一样的
//classes = files("$project.buildDir/intermediates/classes") ----- android
//classes = files("$project.buildDir/classes") ----- java
task findbugs(type: FindBugs) {
ignoreFailures = false
effort = "max"
reportLevel = "high"
excludeFilter = new File("${project.rootDir}/config/quality/findbugs/findbugs-filter.xml")
classes = files("${project.rootDir}/app/build/intermediates/classes")
source 'src'
include '**/*.java'
exclude '**/gen/**'
reports {
xml.enabled = false
html.enabled = true
xml {
destination "$project.buildDir/reports/findbugs/findbugs.xml"
}
html {
destination "$project.buildDir/reports/findbugs/findbugs.html"
}
}
classpath = files()
}
//Exclude可以设置不编译指定的模块
//configurations {
// all*.exclude group: 'org.hamcrest', module: 'hamcrest-core'
//}
def SUPPORT_VERSION = "24.2.0"
def aaVersion = '3.3.2';
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
def googleDependencies = rootProject.ext.goodleDependencies
def otherDependencies = rootProject.ext.otherDependdencies
compile googleDependencies.appcompat_v7
compile 'com.android.support:recyclerview-v7:' + SUPPORT_VERSION
compile 'com.android.support:design:' + SUPPORT_VERSION
apt "org.androidannotations:androidannotations:${aaVersion}"
compile "org.androidannotations:androidannotations:${aaVersion}"
compile 'com.jakewharton:butterknife:6.0.0'
compile project(':customview')
// compile project(':animation')
//module和aar只能有一个
compile(name: 'animation-release', ext: 'aar')
compile 'com.jiechic.library:xUtils:2.6.14'
compile 'com.google.code.gson:gson:2.3.1'
compile 'io.reactivex:rxjava:1.1.0'
compile 'io.reactivex:rxandroid:1.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'org.greenrobot:greendao:2.2.0'
provided 'org.projectlombok:lombok:1.16.6'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.getbase:floatingactionbutton:1.7.0'
compile 'com.android.support:cardview-v7:' + SUPPORT_VERSION
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'com.eftimoff:android-pathview:1.0.8@aar'
compile project(':hanshenghttpclient')
compile project(':simplenet')
compile 'com.github.castorflex.smoothprogressbar:library-circular:1.0.0'
configurations {
all*.exclude module: 'android'
}
compile 'com.github.ctiao:DanmakuFlameMaster:0.5.0'
// Image
compile 'com.github.bumptech.glide:glide:3.7.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
compile 'com.jakewharton.timber:timber:4.3.1'
compile 'com.orhanobut:hawk:2.0.1'
// If you want to bind to Android-specific lifecycles
compile 'com.trello:rxlifecycle-android:1.0'
// If you want pre-written Activities and Fragments you can subclass as providers
compile 'com.trello:rxlifecycle-components:1.0'
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.facebook.stetho:stetho-okhttp3:1.4.1'
compile 'com.jakewharton.rxbinding:rxbinding:1.0.0'
compile 'io.realm:realm-android:0.84.1'
compile 'com.wanjian:sak:0.0.2'
// LeanCloud 基础包
compile('cn.leancloud.android:avoscloud-sdk:v3.+')
// LeanCloud 应用内搜索包
compile('cn.leancloud.android:avoscloud-search:v3.+@aar')
android {
useLibrary 'org.apache.http.legacy'
}
compile 'com.melnykov:floatingactionbutton:1.1.0'
debugCompile 'com.amitshekhar.android:debug-db:0.4.0'
compile 'com.mikepenz:iconics-core:2.5.5@aar'
compile 'com.mikepenz:material-design-iconic-typeface:2.2.0.1@aar'
compile 'com.mikepenz:fontawesome-typeface:4.5.0.1@aar'
compile 'com.mikepenz:foundation-icons-typeface:3.0.0.1@aar'
compile 'com.orhanobut:logger:1.15'
compile 'com.github.scribejava:scribejava-apis:3.2.0'
compile 'com.zhuge.analysis:zhugeio:latest.integration'
// 去掉重复依赖,剔除整个组织的库
// compile 'com.alibaba.fastjson.latest.integration' {
// exclude module: 'annotations', group: 'com.google.android'
// }
// 剔除某个库
// compile('com.android.support:appcompat-v7:23.2.0') {
// exclude group: 'com.android.support', module: 'support-annotations' // 写全称
// exclude group: 'com.android.support', module: 'support-compat'
// exclude group: 'com.android.support', module: 'support-v4'
// exclude group: 'com.android.support', module: 'support-vector-drawable'
// }
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
// if you have multiple outputs (when using splits), you may want to have other index than 0
//resourcePackageName 'org.androidannotations.gradle'
// If you're using Android NBS flavors you should use the following line instead of hard-coded packageName
resourcePackageName android.defaultConfig.applicationId
// You can set optional annotation processing options here, like these commented options:
// logLevel 'INFO'
// logFile '/var/log/aa.log'
}
}