I was able to build the release version of my app and uploaded to play store, Now I want to update it and I need to change the versionCode
. However when I look in my <android/app/build.gradle>
the part which says version which is supposed to be an integer is now something like flutterVersionCode.toInteger()
and versionName
flutterVersionName
is a bit confusing for me and I dont know where to change it from.
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
throw new GradleException("versionCode not found. Define flutter.versionCode in the local.properties file.")
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
throw new GradleException("versionName not found. Define flutter.versionName in the local.properties file.")
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.someApp"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
//implementation 'com.google.firebase:firebase-core:15.0.2'
//compile 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-core:15.0.2'
}
apply plugin: 'com.google.gms.google-services'
int generateVersionCode(String versionName) {
def parts = versionName.split("\\.").collect { it.toInteger() }
return parts[0] * 10000 + parts[1] * 100 + parts[2]
}
here is a nice method to generate the version from he flutterVersionName
defaultConfig {
[...]
versionCode generateVersionCode(flutterVersionName)
versionName flutterVersionName
}
You don't need to modify manually your build.gradle.
Open your pubspec.yaml
and you will find an entry like this:
version: 1.0.0+1
Flutter uses semantic versioning so what do you need is modify that entry:
version: 1.0.1+2
In this case the version name will be 1.0.1
and the version code will be 2
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