I'm trying to use Gradle to set app's name. Please, look at this snippet of build.gradle:
android { ... defaultConfig { ... versionCode getVersionCode() versionName getVersionName() ... } ... } ... int getVersionCode() { return 1 } def getVersionName() { return "1.0" }
Android Studio says
'versionCode' cannot be applied to 'java.lang.Integer' 'versionName' cannot be applied to 'java.lang.String'
and when I install the app on a device it has no versionCode and versionName at all.
The problem is clear to me but I don't know how to solve it.
Please advice.
The version code is an incremental integer value that represents the version of the application code. The version name is a string value that represents the “friendly” version name displayed to the users.
versionCode — A positive integer used as an internal version number. This number is used only to determine whether one version is more recent than another, with higher numbers indicating more recent versions. This is not the version number shown to users; that number is set by the versionName setting, below.
It doesn't resolve your issue, but it can be a different solution.
You can use gradle.properties inside your root project and define:
VERSION_NAME=1.2.1 VERSION_CODE=26
Then in your build.gradle you can use:
versionName project.VERSION_NAME versionCode Integer.parseInt(project.VERSION_CODE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With