Flutter: upgrade the version code for play store

121,881

Solution 1

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

Solution 2

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

Solution 3

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

Solution 4

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

Just change that version to (As per your need )

version: 1.0.1+2

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

After updating the version number in the pubspec file, run flutter pub get from the top of the project, or use the Pub get button in your IDE. This updates the versionName and versionCode in the local.properties file, which are later updated in the build.gradle file when you rebuild the Flutter app.

Solution 5

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

Share:
121,881

Related videos on Youtube

Pondikpa Tchabao
Author by

Pondikpa Tchabao

Updated on April 29, 2022

Comments

  • Pondikpa Tchabao
    Pondikpa Tchabao about 2 years

    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.

  • Tokenyet
    Tokenyet almost 5 years
    I cannot believe this is not provided in the official delpoyment documentation. It's so frustrating to find the answer here...
  • Daniel Allen
    Daniel Allen over 4 years
    This is the correct answer, and should be the accepted answer.
  • Daniel Allen
    Daniel Allen over 4 years
    The strategy here is correct, but the integer after the + is the versionCode, not the versionName.
  • Alex Semeniuk
    Alex Semeniuk over 4 years
    As @DanielAllen said before: versionName is before the + and versionCode is after the +
  • Dika
    Dika over 4 years
    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
  • Chuck K
    Chuck K over 4 years
    so at some later point in time, an app can look like 5.1.3+201 right?
  • Renan Coelho
    Renan Coelho over 4 years
    The 1.0.2 is the versionName and +2 is the versionCode. Thnk you! This helped me a lot!
  • Marcel Hofgesang
    Marcel Hofgesang about 4 years
    no need to change in local.properties and generated.config
  • Ahmad Payan
    Ahmad Payan over 3 years
    Here is the link to the official deployment documentation: Updating the app’s version number
  • Vettiyanakan
    Vettiyanakan over 3 years
    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
  • akfaisel
    akfaisel over 3 years
    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
  • Rohan Taneja
    Rohan Taneja over 3 years
    @ChuckK Correct.
  • Filippos Zofakis
    Filippos Zofakis over 3 years
    You only need to update the version code, version name is not necessary
  • kk_
    kk_ over 2 years
    This one worked for me... after having already tried to upload with 5 different version numbers. Really silly.
  • Neail
    Neail over 2 years
    @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?
  • Rohan Taneja
    Rohan Taneja over 2 years
    @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.
  • Ajeet Singh
    Ajeet Singh over 2 years
    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.
  • Gene Bo
    Gene Bo over 2 years
    I was running into the same issue/confusion. Then I realized as mentioned in the top answer from Rohan Taneja - 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
  • Johnathan Awma
    Johnathan Awma over 2 years
    Extra point, just flutter pub get doesn't fix. Nice catch.
  • 68060
    68060 about 2 years
    tried all of this but its still the same version code.. grr
  • Rohan Taneja
    Rohan Taneja about 2 years
    @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.
  • withoutOne
    withoutOne about 2 years
    How can I use a string value for version name?
  • Rohan Taneja
    Rohan Taneja about 2 years
    version: any-string-here+1 should work
  • Rodrigo Molero
    Rodrigo Molero almost 2 years
    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.