1
2
3
|
<!-- 自动升级类型 self、_360、baidu -->
<meta-data android:name=
"sdk_key_version_update_type"
android:value=
"${CHANNEL_VALUE}"
>
</meta-data>
|
方法 1:直接在 app: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
|
android {
defaultConfig {
...
flavorDimensions
"versionCode"
}
productFlavors {
google {
manifestPlaceholders = [CHANNEL_VALUE:
"google"
]
}
qh360 {
manifestPlaceholders = [CHANNEL_VALUE:
"360"
]
}
baidu {
manifestPlaceholders = [CHANNEL_VALUE:
"baidu"
]
}
self {
manifestPlaceholders = [CHANNEL_VALUE:
"self"
]
}
}
}
或者批量修改
defaultConfig {
...
flavorDimensions
"versionCode"
}
android {
productFlavors {
kuan {}
xiaomi {}
qh360 {}
baidu {}
wandoujia {}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [CHANNEL_VALUE: name]
}
}
|
方法 2:通过快捷键 command + ; 打开配置界面。( Windows 对应的快捷键 Ctrl + Alt + Shift + S )并添加对应的配置渠道。如下图:
注意:这里仅修改 Name 即可,其他信息无特别需求不要修改
1
2
|
APK_SIGN_KEY_PASSWORD=******
APK_SIGN_STORE_PASSWORD=******
|
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
|
//签名
signingConfigs {
release{
keyAlias
'1'
keyPassword APK_SIGN_KEY_PASSWORD
storeFile file(
'../snaillove.keystore'
)
storePassword APK_SIGN_STORE_PASSWORD
}
debug{
keyAlias
'1'
keyPassword APK_SIGN_KEY_PASSWORD
storeFile file(
'../snaillove.keystore'
)
storePassword APK_SIGN_STORE_PASSWORD
}
}
buildTypes {
release {
//启用混淆代码的功能
minifyEnabled
false
//指定混淆规则,需要压缩优化的混淆要把proguard-android.txt换成proguard-android.txt
signingConfig signingConfigs.release
}
}
|
注意:一定要把 signingConfigs 文件配置到 buildTypes 前面 否则会编译时抛出异常 Could not find property ‘debugConfig’ on SigningConfig container.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
android {
// 自定义APK输出配置
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if
(outputFile !=
null
&& outputFile.name.endsWith(
'.apk'
)) {
// 输出apk名称为com_biniusports_app_bnsports_v1.0.0_20171205_baidu.apk
def fileName =
"com_biniusports_app_bnsports_v${defaultConfig.versionName}_${getNowTime()}_${variant.productFlavors[0].name}.apk"
outputFileName = fileName
}
}
}
}
//获取时间戳
def getNowTime() {
def date =
new
Date()
def now = date.format(
'yyyyMMdd'
)
return
now
}
|
注意:Android Studio 版本大于 3.0 时不要使用v ariant.outputs.each 进行查找内容并且不要使用 new File(outputFile.parent, fileName),否则会抛出异常 Android Gradle 3.0.0-alpha2 plugin, Cannot set the value of read-only property ‘outputFile’。