Repository navigation
Expand file tree
/
Copy pathbuild.gradle
More file actions
87 lines (77 loc) · 2.63 KB
/
Copy pathbuild.gradle
File metadata and controls
87 lines (77 loc) · 2.63 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
// AndroidProject 版本:v17.0
plugins {
alias(libs.plugins.application) apply false
alias(libs.plugins.library) apply false
alias(libs.plugins.kotlin) apply false
alias(libs.plugins.aop) apply false
alias(libs.plugins.easyLauncher) apply false
}
void main() {
loadAppConfig()
}
/**
* 根据 Gradle 命令行参数配置 App 的服务器类型和相关参数
*/
void loadAppConfig() {
// 测试服
def serverTypeTest = "test"
// 预发布服
def serverTypePreview = "pre"
// 正式服
def serverTypeProduct = "product"
def taskName = project.gradle.startParameter.taskNames[0]
if (taskName == null) {
taskName = ""
}
// 打印当前执行的任务名称
println "GradleLog TaskNameOutput " + taskName
def serverType
if (taskName.endsWith("Debug")) {
serverType = serverTypeTest
} else if (taskName.endsWith("Preview")) {
serverType = serverTypePreview
} else {
serverType = serverTypeProduct
}
// 从 Gradle 命令中读取参数配置,例如:./gradlew assembleRelease -P ServerType="test"
if (project.hasProperty("ServerType")) {
serverType = project.properties["ServerType"]
}
// 打印当前服务器配置
println "GradleLog ServerTypeOutput " + serverType
// 挂载全局变量,供各个模块使用
ext {
// 友盟 AppKey
UMENG_APP_KEY = "5cb16d93570df399fd0014e2"
// QQ AppId
QQ_APP_ID = "101828096"
// QQ Secret
QQ_APP_SECRET = "9dfd3300c3aa3c4596a07796c64914b2"
// 微信 AppId
WX_APP_ID = "wxd35706cc9f46114c"
// 微信 Secret
WX_APP_SECRET = "0c8c7cf831dd135a32b3e395ea459b5a"
switch(serverType) {
case serverTypeTest:
// fallthrough
case serverTypePreview:
LOG_ENABLE = true
BUGLY_ID = "请自行替换 Bugly 上面的 AppId"
BUGLY_KEY = "请自行替换 Bugly 上面的 AppKey"
if (serverType == serverTypePreview) {
HOST_URL = "https://www.pre.baidu.com/"
} else {
HOST_URL = "https://www.test.baidu.com/"
}
break
case serverTypeProduct:
LOG_ENABLE = false
BUGLY_ID = "请自行替换 Bugly 上面的 AppId"
BUGLY_KEY = "请自行替换 Bugly 上面的 AppKey"
HOST_URL = "https://www.baidu.com/"
break
}
}
}
// 由于 Gradle 这种脚本代码没有函数入口,所以必须手动调用一下 main 方法
main()