admin管理员组文章数量:1292175
I would like to know how to set the OutputfileName generated by AndroidStudio with a Graddle project depends on the value of a buildConfigField.
For exemple, i define a boolean field named "NO_BLUETOOTH_CHECK".
The OutputFileName should be
myproject_BTOn_r_10.0.2.apk if NO_BLUETOOTH_CHECK is false
myproject_BTOff_r_10.0.2.apk if NO_BLUETOOTH_CHECK is true
I do not not how to deal with it. I tried the code below and much more but i got always compiling errors.
buildTypes {
release {
buildConfigField "boolean", "NO_BLUETOOTH_CHECK", "true"
buildConfigField "String", "SFTP_USERNAME", '""'
buildConfigField "String", "SFTP_PASSWORD", '""'
signingConfig signingConfigs.release
}
debug {
buildConfigField "boolean", "NO_BLUETOOTH_CHECK", "true"
buildConfigField "String", "SFTP_USERNAME", '"******"'
buildConfigField "String", "SFTP_PASSWORD", '"******"'
signingConfig signingConfigs.debug
}
applicationVariants.all { variant ->
// signingConfig signingConfigs.variant
variant.outputs.all { output ->
def BTValue = variant.buildTypes.buildConfigFields[ "NO_BLUETOOTH_CHECK"].value ? "BTOff" : "BTOn"
if (variant.buildType.name == 'release')
outputFileName = new File("${rootProject.name}_${BTValue}_r_${variant.versionName}.${variant.versionCode}.apk");
else
outputFileName = new File("${rootProject.name}_${BTValue}_d_${variant.versionName}.${variant.versionCode}.apk");
}
}
I would like to know how to set the OutputfileName generated by AndroidStudio with a Graddle project depends on the value of a buildConfigField.
For exemple, i define a boolean field named "NO_BLUETOOTH_CHECK".
The OutputFileName should be
myproject_BTOn_r_10.0.2.apk if NO_BLUETOOTH_CHECK is false
myproject_BTOff_r_10.0.2.apk if NO_BLUETOOTH_CHECK is true
I do not not how to deal with it. I tried the code below and much more but i got always compiling errors.
buildTypes {
release {
buildConfigField "boolean", "NO_BLUETOOTH_CHECK", "true"
buildConfigField "String", "SFTP_USERNAME", '""'
buildConfigField "String", "SFTP_PASSWORD", '""'
signingConfig signingConfigs.release
}
debug {
buildConfigField "boolean", "NO_BLUETOOTH_CHECK", "true"
buildConfigField "String", "SFTP_USERNAME", '"******"'
buildConfigField "String", "SFTP_PASSWORD", '"******"'
signingConfig signingConfigs.debug
}
applicationVariants.all { variant ->
// signingConfig signingConfigs.variant
variant.outputs.all { output ->
def BTValue = variant.buildTypes.buildConfigFields[ "NO_BLUETOOTH_CHECK"].value ? "BTOff" : "BTOn"
if (variant.buildType.name == 'release')
outputFileName = new File("${rootProject.name}_${BTValue}_r_${variant.versionName}.${variant.versionCode}.apk");
else
outputFileName = new File("${rootProject.name}_${BTValue}_d_${variant.versionName}.${variant.versionCode}.apk");
}
}
Share
Improve this question
edited Feb 13 at 10:25
Yaegaki2
asked Feb 13 at 10:24
Yaegaki2Yaegaki2
96 bronze badges
1 Answer
Reset to default 0I can't see any buildTypes
property for variant
. Perhaps you meant buildType
(without an ending s
)?
There are two other issues that I can see:
- Accessing the
buildConfigFields
Map
may returnnull
, which you need to deal with. - Your boolean BuildConfig fields will actually return strings, which you need to convert to booleans if you want to use them as such.
So something like this should work:
def BTValue = variant.buildType.buildConfigFields["NO_BLUETOOTH_CHECK"]?.value?.toBoolean() ? "BTOff" : "BTOn"
本文标签: gradleAndroidHow to generate outputFileName with buildConfigField optionsStack Overflow
版权声明:本文标题:gradle - Android : How to generate outputFileName with buildConfigField options - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741548652a2384746.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论