-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildApp.gradle
171 lines (144 loc) · 5.3 KB
/
buildApp.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
apply {
plugin "com.android.application"
plugin Config.depConfig.plugin_api.pluginId
plugin "kotlin-android"
plugin 'kotlin-kapt'
plugin "kotlin-android-extensions"
}
configSigning()
configApkName()
android {
compileSdkVersion Config.compileSdkVersion
defaultConfig {
minSdkVersion Config.minSdkVersion
versionCode Config.versionCode
versionName Config.versionName
applicationId Config.applicationId + suffix
// applicationId Config.applicationId
targetSdkVersion Config.targetSdkVersion
multiDexEnabled true
// 仅保留中文语种的资源
resConfigs 'zh'
// 仅保留 xxhdpi 图片资源(目前主流分辨率 1920 * 1080)
resConfig 'xxhdpi'
// 仅保留两种架构的 so 库,根据 Bugly 统计得出
ndk {
// armeabi:万金油架构平台(占用率:0%)
// armeabi-v7a:曾经主流的架构平台(占用率:10%)
// arm64-v8a:目前主流架构平台(占用率:90%)
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
//route 获取 moduleName
javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
javaCompileOptions {
annotationProcessorOptions {
arguments = [moduleName: project.getName()]
}
}
}
buildTypes {
debug {
debuggable true
jniDebuggable true
// 移除无用的资源文件
shrinkResources false
// ZipAlign 优化
zipAlignEnabled false
// 设置混淆
minifyEnabled false
proguardFiles 'proguard-rules.pro', 'proguard-lib.pro', 'proguard-sdk.pro'
resValue "string", "app_name", Config.appName + suffix + ".debug"
// resValue "string", "app_name", suffix + ".debug"
}
release {
debuggable false
jniDebuggable false
// 移除无用的资源文件
shrinkResources true
// ZipAlign 优化
zipAlignEnabled true
// 设置混淆
minifyEnabled true
proguardFiles 'proguard-rules.pro', 'proguard-lib.pro', 'proguard-sdk.pro'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "app_name", Config.appName + suffix
}
}
packagingOptions {
exclude 'META-INF/*'
}
dexOptions {
preDexLibraries true
javaMaxHeapSize "8g"
maxProcessCount 8
dexInProcess = true
}
// 支持 Java JDK 8
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
//支持dataBinding
dataBinding {
enabled true
}
}
dependencies {
// 根据 Config.pkgConfig 来依赖所有 pkg
for (def entrySet : ConfigUtils.getApplyPkgs().entrySet()) {
GLog.d("dependencies = " + entrySet.value)
api entrySet.value.dep
}
if (Config.depConfig.apt_compiler.isApply) {
GLog.d("apt_compiler isApply " )
kapt Config.depConfig.apt_compiler.dep
}
if (Config.depConfig.apt_annotation.isApply) {
GLog.d("apt_annotation isApply " )
api Config.depConfig.apt_annotation.dep
}
}
def getSuffix() {
if (project.name == "feature_launcher_app") return ""
return "." + project.name.substring("feature_".length(), project.name.length() - "_app".length())
}
def configSigning() {
File signPropertiesFile = file("${rootDir.path}/sign/keystore.properties")
if (!signPropertiesFile.exists()) return
project.android {
Properties properties = new Properties()
properties.load(new FileInputStream(signPropertiesFile))
signingConfigs {
debug {
storeFile new File(signPropertiesFile.getParent(), properties['keystore'])
storePassword properties['storePassword']
keyAlias properties['keyAlias']
keyPassword properties['keyPassword']
}
release {
storeFile new File(signPropertiesFile.getParent(), properties['keystore'])
storePassword properties['storePassword']
keyAlias properties['keyAlias']
keyPassword properties['keyPassword']
}
}
buildTypes.release.signingConfig signingConfigs.release
}
// GLog.d("${project.toString()} sign end...")
}
def configApkName() {
project.android.applicationVariants.all { variant ->
if (variant.buildType.name != "debug") {
def artifact = variant.getPackageApplicationProvider().get()
artifact.outputDirectory = new File("${rootDir.path}/apk")
artifact.outputScope.apkDatas.forEach { apkData ->
// apkData.outputFileName = "open9527" + suffix + rootProject.releaseTime() +
apkData.outputFileName = suffix + ("_" + rootProject.releaseTime()) +
(variant.flavorName == "" ? "" : ("_" + variant.flavorName)) +
"_" + variant.versionName.replace(".", "_") +
"_" + variant.buildType.name +
".apk"
}
}
}
}