Android 如何在Gradle中的buildType中设置versionname
我可以在flavors中设置versioncode和versionname,但我喜欢在构建类型中设置它们。 这有可能吗Android 如何在Gradle中的buildType中设置versionname,android,android-studio,android-gradle-plugin,android-build-type,Android,Android Studio,Android Gradle Plugin,Android Build Type,我可以在flavors中设置versioncode和versionname,但我喜欢在构建类型中设置它们。 这有可能吗 defaultConfig { versionCode 1 versionName "1" } buildTypes { specialversion { versionCode 2 // <--- Doesn't work. versionName "2" // <--- Doesn't wo
defaultConfig {
versionCode 1
versionName "1"
}
buildTypes {
specialversion {
versionCode 2 // <--- Doesn't work.
versionName "2" // <--- Doesn't work.
}
}
defaultConfig{
版本代码1
版本名称“1”
}
建筑类型{
特化{
versionCode 2//是一个完整的字段列表,可以在buildType
中修改。正如您可能看到的,没有您需要的字段。您最好使用versionNameSuffix
这应该放在productFlavors
中:
defaultConfig {
productFlavors {
specialversion {
versionCode 2 // <--- Doesn't work.
versionName "2" // <--- Doesn't work.
}
}
}
defaultConfig{
产品风味{
特化{
versionCode 2//我用以下方法解决了它。可能不推荐,但在我的情况下,这是一个很好的解决方案
我在buildvariants中使用manifestplaceholder
替换了AndroidManifest.xml中的值
buildTypes {
demo {
...
manifestPlaceholders = [iconpath: "@drawable/icon", versionCode:"161", versionName:"2.37"]
}
}
我的AndroidManifest.xml具有以下内容:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxx"
android:versionCode="${versionCode}"
android:versionName="${versionName}"
android:installLocation="auto">
您可能会找到帮助谢谢,但它并没有真正帮助我。我用manifestPlaceholders=[versionCode:“2”,versionName:“2”]解决了这个问题,并在android manifest.xml中添加了占位符,比如android:versionCode=“${versionCode}”。我知道不建议使用reallz,但在我的情况下,这是目前为止最好的解决方案。请回答