我正在尝试使用 Gradle 来设置应用程序的名称。请看一下这个 build.gradle fragment :
android {
...
defaultConfig {
...
versionCode getVersionCode()
versionName getVersionName()
...
}
...
}
...
int getVersionCode() {
return 1
}
def getVersionName() {
return "1.0"
}
Android Studio 说
'versionCode' cannot be applied to 'java.lang.Integer'
'versionName' cannot be applied to 'java.lang.String'
当我在设备上安装应用程序时,它根本没有 versionCode 和 versionName。
问题对我来说很清楚,但我不知道如何解决。
请指教。
最佳答案
它不能解决您的问题,但它可以是不同的解决方案。
您可以在根项目中使用 gradle.properties 并定义:
VERSION_NAME=1.2.1
VERSION_CODE=26
然后在你的 build.gradle 中你可以使用:
versionName project.VERSION_NAME
versionCode Integer.parseInt(project.VERSION_CODE)
关于android - 使用 Gradle 设置 Android 应用版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21329849/