How do you set the version name and version code of a Flutter app without having to go into the Android and iOS settings?
In my pubspec.yaml I have
v
Thanks to user abion47 for finding and condensing the following answer from the article Versioning with Flutter.
By default a Flutter project is set up to automatically update the Android and iOS settings based on the version setting in pubspec.yaml when you build the project. If, however, you have since overridden those settings, you can re-enable that behavior by doing the following:
Open the ios/Runner/Info.plist file. Set the value for CFBundleVersion to $(FLUTTER_BUILD_NUMBER) and set the value for CFBundleShortVersionString to $(FLUTTER_BUILD_NAME). The XML for the file should look something like this:
...
CFBundleVersion
$(FLUTTER_BUILD_NUMBER)
CFBundleShortVersionString
$(FLUTTER_BUILD_NAME)
...
...
Open the android/app/build.gradle file. Ensure you are properly loading the Flutter properties at the top of the file:
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.")
}
Then set the android.defaultConfig section so that versionName is flutterVersionName and versionCode is flutterVersionCode.toInteger():
android {
...
defaultConfig {
...
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}