258

I have published an application on the play store with flutter, now I want to upload a new version of the application. I am trying to change the version code with:

flutter build apk --build-name=1.0.2 --build-number=3

or changing the local.properties like this

 flutter.versionName=2.0.0
 flutter.versionCode=2
 flutter.buildMode=release

but every time I get an error on the play store

You must use a different version code for your APK or your Android App Bundle because code 1 is already assigned to another APK or Android App Bundle.

Pondikpa Tchabao
  • 3,285
  • 6
  • 17
  • 24

24 Answers24

616

version in pubspec.yaml file

Update version:A.B.C+X in pubspec.yaml.

For Android:

A.B.C represents the versionName such as 1.0.0.

X (the number after the +) represents the versionCode such as 1, 2, 3, etc.

Do not forget to execute flutter build apk or flutter run after this step, because: When you run flutter build apk or flutter run after updating this version in the pubspec file, the versionName and versionCode in local.properties are updated which are later picked up in the build.gradle (app) when you build your flutter project using flutter build apk or flutter run which is ultimately responsible for setting the versionName and versionCode for the apk.

For iOS:

A.B.C represents the CFBundleShortVersionString such as 1.0.0.

X (the number after the +) represents the CFBundleVersion such as 1, 2, 3, etc.

Do not forget to execute flutter build ipa or flutter run after this step

Rohan Taneja
  • 9,687
  • 3
  • 36
  • 48
  • 52
    thank you! for android, the key point is to run `flutter run` after changing pubspec.yaml otherwise android studio will build apk / aab with old version code based on local.properties – Dika Nov 27 '19 at 17:05
  • 10
    so at some later point in time, an app can look like `5.1.3+201` right? – Chuck K Jan 07 '20 at 09:19
  • 24
    For every release, version code has to be changed as well. For example, you cannot simply change the version name alone from 1.0.0+1 to 1.1.0+1. It has to be changed to 1.1.0+2 – akfaisel Sep 25 '20 at 15:23
  • @ChuckK Correct. – Rohan Taneja Oct 09 '20 at 08:42
  • @akfaisel could you explain the version name and version code a little more? Is the version code the release counter for each version? Even if someone doesn't apply some updates or fixes and republishes of any reason should the version code be updated? – Neail Oct 06 '21 at 06:48
  • 4
    @Neail Yes, the version code is the integer value or the release counter like you suggest. A version code can only be assigned to one build on the PlayStore/AppStore. So if you've uploaded build number 1 already, you can never upload another build with the same number, regardless of it being in review or published. You can keep the version name the same if you like. – Rohan Taneja Oct 06 '21 at 12:24
  • tried all of this but its still the same version code.. grr – 68060 Jan 31 '22 at 00:41
  • @68060 Even after a `flutter clean`? If you're running on Android, check `local.properties`. If the new `versionCode` doesn't show up there, it'll not show up on the app too. – Rohan Taneja Jan 31 '22 at 09:08
  • How can I use a string value for version name? – withoutOne Mar 10 '22 at 08:31
  • version: any-string-here+1 should work – Rohan Taneja Mar 11 '22 at 09:49
  • My app current version in project is 2.1.3+15. But unexpectedly play store version is 4.0.0+15 play store. can i downgrade flutter versionName from 4.0.0 to 2.1.4 for next appbundle ? – Sharath B Naik Jul 12 '22 at 06:51
  • @SharathBNaik Yes, you can. Play Store only cares about build number, not version name. So if the version name on Play Store is 4.0.0, you can change it to 1.0.0, 0.0, 2.1.4 or even ABC. For build number, since it is 15 on the Play Store, you can only change it to a number > 15. So as per your requirements, your pubspec version should now be 2.1.4+16. – Rohan Taneja Jul 12 '22 at 08:30
  • Before build signed apk, you shour run flutter app, for android! – kokemomuke Feb 04 '23 at 09:38
  • I'm wondering, for AppStore, the build number must be increased ? Like 2.1.3+15, +16, +17, +18, and more? – blackkara Mar 31 '23 at 22:40
  • Yes. When uploading builds to TestFlight, a build with a number that was already used before will be rejected. – Rohan Taneja Apr 02 '23 at 14:28
242

Figured this one out. Documentation is not straight forward

in your pubspec.yaml change the version like this

version: 1.0.2+2

where the stuff is VER_NAME+VER_CODE

Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117
Dave
  • 2,548
  • 1
  • 8
  • 7
  • 42
    I cannot believe this is not provided in the [official delpoyment documentation](https://flutter.dev/docs/deployment/android#review-the-build-configuration). It's so frustrating to find the answer here... – Tokenyet May 22 '19 at 13:36
  • 9
    The strategy here is correct, but the integer after the + is the versionCode, not the versionName. – Daniel Allen Oct 11 '19 at 12:54
  • 1
    As @DanielAllen said before: __versionName__ is _before_ the __+__ and __versionCode__ is _after_ the __+__ – Alex Semeniuk Oct 28 '19 at 09:26
  • 3
    The 1.0.2 is the versionName and +2 is the versionCode. Thnk you! This helped me a lot! – Renan Coelho Jan 23 '20 at 22:26
  • 1
    I had version: 1.0.0+1 in my pubspec.yaml file, I took a build and uploaded to play store. But in play store version code is showing as 2001. Later I edited in pubspec to version: 1.0.0+2 and took a build, this version shows version code 2002 in play store. how does this happen? In android local properties versionName=1.0.0 and versionCode=2 – Vettiyanakan Aug 08 '20 at 13:15
  • You only need to update the version code, version name is not necessary – Filippos Zofakis Oct 23 '20 at 00:04
  • @Vettiyanakan You have probably used the split-per-abi option. Here is explained why that results in **versionCode+1000** and **versionCode+2000**: [Configure APK versions](https://developer.android.com/build/configure-apk-splits#configure-APK-versions) – Sander Roest Jun 08 '23 at 10:14
30

Solution:

Inside pubspec.yaml add this (probably after description, same indentation as of description, name etc...):

version: 2.0.0+2

Then do packages get inside flutter local directory (Do not forget to do this)

Explanation:

Everything before plus is version name and after is version code. So here the version code is 2 and name is 2.0.0. Whenever you give an update to the flutter app make sure to change the version code compulsorily!

Addtional Info:

Whenever android app is built, build.gradle inside android/app/ looks for version code and name. This usually lies in local.properties which is changed every time you change flutter pubspec.yaml

Pushan Gupta
  • 3,697
  • 5
  • 23
  • 39
12

For Android

"X.Y.Z+n" here "x.y.z" represents the VERSION NAME and "n" represents the VERSION NUMBER. The following changes to be made-

  1. In pubspec.yaml change your version number.
  2. Update your local.properties by running flutter pub get command.
  3. Now build your apk or app bundle by running flutter build apk or flutter build appbundle command.
Akhil Shukla
  • 491
  • 5
  • 10
12

In case you already changed the versionCode, it may be because Play Console already accepted your build.

Instead of clicking on upload, click in Choose from library and choose the build that was already sent.

enter image description here

Soon Santos
  • 2,107
  • 22
  • 43
  • This one worked for me... after having already tried to upload with 5 different version numbers. Really silly. – kk_ Aug 09 '21 at 15:30
  • This can work, if you want your old build to be shown to public, which was uploaded previously and accepted by google. But if you have made changes and want a new one you must change the versionCode as mentioned in some answers, and google must not show that warning, then only you are sure of that your new build is uploaded and accepted. – Ajeet Singh Oct 11 '21 at 02:32
10

In my case, i solved the same exact problem by changing two files:

1- in pubspec.yaml:

from:

version: 1.0.0+1

to:

version: 1.0.0+2

2- in android/locale.properties

from:

flutter.versionName=1.0.0
flutter.versionCode=1

to:

flutter.versionName=1.0.0
flutter.versionCode=2

3- Last action:

flutter clean
flutter packages get
Ayoub Boumzebra
  • 3,885
  • 3
  • 21
  • 37
8

Updating the app’s version number The default version number of the app is 1.0.0. To update it, navigate to the pubspec.yaml file and update the following line:

version: 1.0.0+1

The version number is three numbers separated by dots, such as 1.0.0 in the example above, followed by an optional build number such as 1 in the example above, separated by a +.

Both the version and the build number may be overridden in Flutter’s build by specifying --build-name and --build-number, respectively.

In Android, build-name is used as versionName while build-number used as versionCode. For more information, see Version your app in the Android documentation.

  • 2
    Here is the link to the official deployment documentation: [Updating the app’s version number](https://flutter.dev/docs/deployment/android#updating-the-apps-version-number) – AhmadReza Payan Aug 08 '20 at 10:45
8

still someone looking for a Good answer

in pubsec.yaml file

change version: 1.0.0+1 to version: 1.0.0+2

then open your code in android by selecting

File -> Open -> your Flutter Code workspace -> Android icon of project

Now go to build.gradel

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0.0'
}

to

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '2'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0.2'
}

Now last one local.property file

sdk.dir=C:/Users/Admin/AppData/Local/Android/Sdk
flutter.sdk=D:\\flutter_windows\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1

to

sdk.dir=C:/Users/Admin/AppData/Local/Android/Sdk
flutter.sdk=D:\\flutter_windows\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.2
flutter.versionCode=2
CrazyMind
  • 1,006
  • 1
  • 20
  • 22
  • 1
    You should not configure the "local.properties" file manually. This will be overwritten automatically when running the "flutter run" command. Although is important to mention that you should do a "flutter run" before releasing the app bundle, otherwise there won't be any changes. – Rodrigo Molero Jun 07 '22 at 14:46
7

Follow these steps for above flutter 2.10.2 version

Step 1: Change following changes in pubspec.yaml

    //change version 1.0.0+1 to 1.0.0+2
version: 1.0.0+2
    
    environment:
      sdk: ">=2.16.1 <3.0.0"

Step 2: Change following change in android\local.properties

flutter.sdk=C:\\flutter
flutter.buildMode=release

// Change here flutter.versionName=1.0.0 to flutter.versionName 1.0.1
flutter.versionName=1.0.1

 //Change here flutter.versionCode=1 to flutter.versionCode=2
flutter.versionCode=2

flutter.minSdkVersion=21
flutter.targetSdkVersion=31
flutter.compileSdkVersion=31
Rahul Raj
  • 1,010
  • 9
  • 10
6

I don't think anyone has actually answered the question. A lot of suggestions are updating the version in pubspec. But depending on your deployment you might not use those values.

flutter build --build-number=X --build-name=Y

X gets used as your version code Y gets used as your version name

To test just run build and check local.properties

Ali_R
  • 121
  • 2
  • 10
5

Check

android{
//....
  defaultConfig {
  //....
  version code:2
  }
}

on android>app>Build.gradle from your project's root folder

Abhinand V B
  • 51
  • 1
  • 1
3

Docs says the build args should override pubspec.yml:

Both the version and the build number may be overridden in Flutter’s build by specifying --build-name and --build-number, respectively.

https://flutter.dev/docs/deployment/android#updating-the-apps-version-number

Evandro Pomatti
  • 13,341
  • 16
  • 97
  • 165
2

You can still do completely your own thing by overwriting in android/app/build.gradle:

  • def flutterVersionCode
  • def flutterVersionName

to your own values.

0llie
  • 8,758
  • 2
  • 24
  • 13
2

Something that might be helpful to others that land here, the Play Store only looks at the versionCode in isolation. So, if you've updated your versionNumber from, for example, 1.0.0+1 to 1.1.0+1 Play Store will throw an error that the versionCode has not changed. So, regardless of what your versionNumber is, you must also change your versionCode - as in, changing from 1.0.0+1 to 1.1.0+2

jwehrle
  • 4,414
  • 1
  • 17
  • 13
1

First one change flutter version in pubspec.yaml example `version 1.0.3+4

In case of android go to local.properties than change version name and code same like flutter version code and name.

In case of Ios go to generated.xcconfig than chnage FLUTTER_BUILD_NAME=1.0.3 FLUTTER_BUILD_NUMBER=4`

Adam
  • 444
  • 5
  • 18
1

I had the same problem, I solve it by restarting Android Studio.

1
  • in pubspec.yml version: 1.0.0+1
  • change to version: 1.0.0+2
  • flutter build ios --release-name --release-number will update version in ios
  • flutter pub get && flutter run will update version for android (android/local.properties)
sultanmyrza
  • 4,551
  • 1
  • 30
  • 24
1

this works for me! I recognised that first app as Default Version Name 1.0.0 Version Number 1 so this means 1.0.0+1

I updated my app after I wrote as 1.0.0+2 in pubspec.yaml.

mhmd82
  • 11
  • 1
0

Any of the solution did not work for me with App Bundle, I changed to APK and no issues with the version.

Not clear why though.

Juancki
  • 1,793
  • 1
  • 14
  • 21
0

All of these answers mirror the official documentation, and it is how I am setting my versionName and versionCode. But when I upload my build I get the same error as reported by the post author.

My previous version code on the play store shows as 4 (0.0.2) ... I am used to how iOS works so this looked odd to me. The number in the brackets should be the build/code number and the main number is the actual version number. Incrementing the build number when necessary without having to bump the version (because there are no significant changes).

So when I attempted to upload 0.0.3+1 with a new build number to increment for this new version, it complained that the 1 had already been used.

So how does this work on the Play store? I'm confused too.

Lee Probert
  • 10,308
  • 8
  • 43
  • 70
  • I was running into the same issue/confusion. Then I realized as mentioned in the [top answer from Rohan Taneja](https://stackoverflow.com/a/56970752) - after you make the update in pubspec.yaml, 1) run the `pub get`, 2) then run build to completion. Then I see values are updated in `local.properties` and GPlay accepts the upload. I didn't realize at first, this is the *critical detail/step* reiterated several times in the comments for that answer – Gene Bo Oct 12 '21 at 01:16
0

before uploading the app bundle, first write the Release name. I faced the same issue and That's worked for me.

enter image description here

Amina Bekir
  • 220
  • 2
  • 9
0

For example if you to make android version 3 ,

For Android go to pubspec.yaml and edit here

version: 3.0.0

and go to build.gradle and edit here

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '3'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '3.0' 
klinsman Agam
  • 80
  • 1
  • 2
0

Updating it in project/android/app/build.gradle worked for me.

defaultConfig {
    versionCode 2 // this needs to be updated
    versionName "1.0.5"
}

Hope this helps!

Hammad Nasir
  • 2,889
  • 7
  • 52
  • 133
  • This solution should not be used in newer Flutter SDK version, instead update your pubspec.yaml and set versionCode to `versionCode flutterVersionCode.toInteger()` – Alex Rintt Nov 08 '22 at 18:39
-1

I have been doing it like this in the 'app/build.gradle' file

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}else {
    flutterVersionCode = '4'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}else {
    flutterVersionName = '1.3'
}