Android Studio之 build.gradle的常用配置

1,project的下的gradle配置

全当一个笔记,主要是project和modules的区配置,我们都比较清楚,gradle构建配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
//mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' //注入框架必须增加这一句
//classpath 'org.greenrobot:greendao-gradle-plugin:3.2.0'
}
}
allprojects {//在配置中加入自定义的仓库
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

2,module配置,app

配置签名,各种版本信息,sdk,混淆打包,依赖文件,第三方库等

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
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'//依赖注入
//apply plugin: 'org.greenrobot.greendao'
android {
signingConfigs {
oair_android_keystore {
keyAlias 'oair_android'
keyPassword KEY_PASSWORD
storeFile file('../../keystore/android.keystore')
storePassword KEYSTORE_PASSWORD//密码保存在gradle.properties中
}
}
compileSdkVersion 25
buildToolsVersion "25.0.0"//版本与你as的buildtool版本一致
defaultConfig {
applicationId "cn.net.duqian"
minSdkVersion 11
targetSdkVersion 24
versionCode 1
versionName "1.0.2"
signingConfig signingConfigs.android_keystore
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled true//打开混淆
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
shrinkResources true// 移除无用的resource文件
signingConfig signingConfigs.android_keystore
}
debug {
signingConfig signingConfigs.android_keystore
}
}
//多个版本的打包配置
productFlavors {
Version1{
applicationId "package name1"
manifestPlaceholders = [GAO_DE_KEY: "your gaode key1", UMENG_KEY: "your umeng key1"]
}
Version2 {
applicationId "package name2"
manifestPlaceholders = [GAO_DE_KEY: "your gaode key2", UMENG_KEY: "your umeng key2"]
}
}
/* lintOptions {
disable 'InvalidPackage'
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}*/
/*greendao{
schemaVersion 1000 //数据库版本号
daoPackage 'com.oair.ssy.model.db' //设置DaoMaster、DaoSession、Dao包名
targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录
}*/
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':vitamio4.2.6')
testCompile 'junit:junit:4.12'
//testCompile 'org.mockito:mockito-core:2.0.99-beta'
//testCompile 'org.robolectric:robolectric:3.1.2'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:cardview-v7:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.1.3'
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:retrofit-adapters:2.1.0'
compile 'com.squareup.retrofit2:retrofit-converters:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
/*compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'io.reactivex:rxjava:1.1.10'
compile 'io.reactivex:rxandroid:1.2.1'*/
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okio:okio-parent:1.10.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.google.dagger:dagger:2.7'
provided 'com.google.dagger:dagger-compiler:2.7'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'com.squareup.leakcanary:leakcanary-android:1.4'
compile 'com.umeng.analytics:analytics:5.6.4'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.chrisbanes:PhotoView:1.3.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.barteksc:android-pdf-viewer:2.3.0'
//compile 'org.greenrobot:greendao:3.2.0'
}

未完待续