Android Gradle配置productFlavors、apk路径及文件名示例

productFlavors

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
productFlavors {
defaultConfig {
//versionNameSuffix 'default'
}
developTest {
minSdkVersion 15
applicationId 'cn.appblog.example'
targetSdkVersion 28
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode versionCode
versionName versionName
//versionNameSuffix 'devtest'
}
productTest {
minSdkVersion 15
applicationId 'cn.appblog.example'
targetSdkVersion 28
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode versionCode
versionName versionName
//versionNameSuffix 'protest'
}
home {
minSdkVersion 15
applicationId 'cn.appblog.example'
targetSdkVersion 28
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode versionCode
versionName versionName
//versionNameSuffix 'home'
}
update {
minSdkVersion 15
applicationId 'cn.appblog.example'
targetSdkVersion 28
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode versionCode
versionName versionName
//versionNameSuffix 'update'
}
googleplay {
minSdkVersion 15
applicationId 'cn.appblog.example'
targetSdkVersion 28
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode versionCode
versionName versionName
//versionNameSuffix 'googleplay'
}
}

apk路径及文件名

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
applicationVariants.all { variant ->
variant.getPackageApplication().outputDirectory = new File(project.rootDir.absolutePath + '/outputs/' + versionName) //指定apk输出目录
def buildName = 'AppBlog'
if (variant.buildType.name.equals('release')) {
variant.outputs.all { output ->
def type = variant.buildType.name
def flavor = variant.productFlavors[0].name
def releaseApkName
if (flavor.equals('defaultConfig')) {
releaseApkName = buildName + '-v' + versionName + '-release.apk'
} else {
releaseApkName = buildName + '-v' + versionName + '-release' + '-' + flavor + '.apk'
}
//def releaseApkName = buildName + '_' + type + "_" + versionName + '_' + getTime() + '.apk'
outputFileName = releaseApkName
}
} else if (variant.buildType.name.equals('debug')) {
variant.outputs.all { output ->
def flavor = variant.productFlavors[0].name
println 'flavor: ' + flavor
def debugApkName = buildName + '-v' + versionName + "-debug" + "-" + flavor + '.apk'
outputFileName = debugApkName
}
}
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :