I always used to increment version code in my android/app/build.gradle
file, and it always used to work. Then, after a recent update in Android Studio, it suddenly didn't anymore, and I got this error!
I never cared to dig into the build.gradle
code, but now, I did. Here, at the "TODO", is where I used to change the version code number:
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 FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '19' // TODO: ---Count up with each release
}
But that only works if the version code from the local.properties
file comes back as "null"!... I just realized. So probably, all this time, my compiler never managed to get values from local properties, but now all of a sudden, it does!
So I found the android/local.properties
file and tried changing the version code there:
sdk.dir=C:\\Users\\karol\\AppData\\Local\\Android\\sdk
flutter.sdk=C:\\src\\flutter
flutter.buildMode=release
flutter.versionName=1.0.0
flutter.versionCode=1 //Change this to 19 (my current version code number)
But that didn't work, because the moment I ran flutter build appbundle
, this file changed itself back to the original values...
I then tried adding version code values to my AndroidManifest.xml
file, according to serraosays' answer, but that didn't help me either.
Functioning work-around
In the end, I did this in the android/app/build.gradle
file:
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
//if (flutterVersionCode == null) {
flutterVersionCode = '19' // TODO: ---Count up with each release
//}
That is, I commented out the condition. Now, my setting would over-write any value retrieved from the local.properties
file.
If anyone can tell me the proper way to increment the version code number, I'm all ears! But in the meantime, this worked for me, and hopefully for someone else as well.