Suragch
Suragch

Reputation: 511548

How to set build and version number of Flutter app

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

version: 2.0.0

but I don't see a place for the build number.

Upvotes: 131

Views: 189138

Answers (12)

Jawad Abbasi
Jawad Abbasi

Reputation: 148

In pubspec.yaml you can see:

version: 1.0.5+3

where 1.0.5 is version name and 3 is the build number.

If you want manually manage version for android and iOS you can do as follows:

For Android :

1 - Go to android/app/build.gradle

2 - Search android block

3 - Inside android block you can find defaultConfig.

4 - Inside defaultConfig you can see:

versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

5 - Now you can manually set version name & code for your android app like:

versionCode 3
versionName "1.0.5"

For iOS :

1 - Go to ios/Runner/info.plist

2 - Search for CFBundleShortVersionString and CFBundleVersion.

<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>

3 - Manually add version and build number like this

<key>CFBundleShortVersionString</key>
<string>1.0.5</string>
<key>CFBundleVersion</key>
<string>3</string>

Note: You can also add 2 digits CFBundleShortVersionString and VersionName when configuring manually.

Upvotes: 5

MendelG
MendelG

Reputation: 19988

For me, what worked was to set the correct version in the pubspec.yaml file and then run:

flutter clean

and then:

flutter pub get

flutter clean really does the trick.

You should also run:

pod install

at your /ios directory

Finally, you must execute:

flutter run

As this not only runs your app but also updates the local.properties file, which then also sets the build.gradle file once you execute flutter run.

See also:

Upvotes: 18

sohrabonline
sohrabonline

Reputation: 664

  1. run flutter build ios in Android Studio terminal
  2. after on Project mode right click ios folder and tap Flutter=>Open iOS/MacOS module in xCode
  3. on xCode window, click Product=>Clean build folder then Archieve

Upvotes: 1

N.K.
N.K.

Reputation: 490

The answers above are great but I want to add some more context I discovered relating to how pubspec.yaml updates android/local.properties:

The version in pubspec.yaml does overwrite the flutter.versionName and flutter.versionCode in local.properties when you run flutter run.

And when you run flutter build, flutter.buildMode is updated in local.properties as well.

This applies when you have the following within your android/app/build.gradle:

if (flutterVersionCode == null) {
    throw new Exception("versionCode not found. Define flutter.versionCode in the local.properties file.")
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    throw new Exception("versionName not found. Define flutter.versionName in the local.properties file.")
}```


Upvotes: 1

Michael Barr
Michael Barr

Reputation: 55

Make sure you are running flutter build ipa! I was running flutter build ios, and kept trying to upload the older build, wondering why the version wasn't changing!

Upvotes: 2

Yusuf Amr
Yusuf Amr

Reputation: 587

For me my version was

version: 1.0.0+1

and i changed it to

version: 1.2.0+1

then in terminal

flutter build appbundle --build-name=1.2.0+1 --build-number=2

Upvotes: 22

MKLarsen
MKLarsen

Reputation: 121

On my local builds I use this solution to get ride of the warning while building.

Action Required: You must set a build name and number in the pubspec.yaml file version field before submitting to the App Store.

build.sh

#!/bin/bash
#my vars
BUILD_NAME="Local build 3.2.3"
BUILD_NO=10

#my vars injection 
perl -i -pe 's/^(version:\s+\d+\.\d+\.\d+\+)(\d+)$/$1.('$BUILD_NO')/e' pubspec.yaml

#build ios
flutter build ipa --target=lib/main.dart \
  --build-name=$BUILD_NAME \
  --build-number=$BUILD_NO \
  --export-options-plist=./ExportOptions.plist \
  --release

#build android
flutter build apk --target=lib/main.dart \
  --build-name=$BUILD_NAME \
  --build-number=$BUILD_NO \
  --release

pubspec.yaml

name: radioavisenapp
description: Tidligere Radioavisen App
publish_to: 'none'
version: 3.2.5+10

Upvotes: 4

Sumit Shukla
Sumit Shukla

Reputation: 4494

What worked for me (Android) :

  • Update pubspec.yaml inside flutter project file for versionname and versioncode.
  • Run flutter pub get on terminal.
  • Run your project in a device.
  • Open android module in Andriod Studio and check local.properties for updated flutter.versionName flutter.versionCode file in gradle folder.

Upvotes: 7

Md Tariqul Islam
Md Tariqul Islam

Reputation: 2804

if you are using android studio most easiest way to change it from local.properties

enter image description here

Upvotes: 2

Suragch
Suragch

Reputation: 511548

Setting the version and build number

You can update both the version name and the version code number in the same place in pubspec.yaml. Just separate them with a + sign. For example:

version: 2.0.0+8

This means

  • The version name is 2.0.0
  • The version code is 8

This is described in the documentation of a new project (but you might have deleted that if you are working on an old project):

The following defines the version and build number for your application. A version number is three numbers separated by dots, like 1.2.43 followed by an optional build number separated by a +. Both the version and the builder number may be overridden in flutter build by specifying --build-name and --build-number, respectively. Read more about versioning at semver.org.

version: 1.0.0+1

Re-enabling auto versioning

If your Flutter versioning is not automatically updating anymore, see this answer for how to fix it.

See also:

Upvotes: 208

Suragch
Suragch

Reputation: 511548

Thanks to user abion47 for finding and condensing the following answer from the article Versioning with Flutter.

Re-enabling auto versioning

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:

iOS

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:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  ...
  <key>CFBundleVersion</key>
  <string>$(FLUTTER_BUILD_NUMBER)</string>
  <key>CFBundleShortVersionString</key>
  <string>$(FLUTTER_BUILD_NAME)</string>
  ...
</dict>
...

Android

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
  }
}

Upvotes: 114

Mohd Danish Khan
Mohd Danish Khan

Reputation: 1101

In Android, build-name is used as versionName while build-number used as versionCode. Read more about Android versioning at https://developer.android.com/studio/publish/versioning In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. Read more about iOS versioning at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

This above information you can get in pubsec.yaml

You will find versionCode or buildnumber (for android) in your android/app/build.gradle.

defaultConfig {
        applicationId "com.fabio.resturanto"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true

    }

You have flutterVersionCode and flutterVersionName in your local.properties file. This is specific to Android build

Both iOS / Android version can be set from pubspec.ymal

version: 1.2.0+1

Here 1.2.0 is Version Name and +1 is Version code. changes here (pubspec.ymal) will reflect for both Android and iOS version name and version code.

Upvotes: 4

Related Questions