Flutter: upgrade the version code for play store
Solution 1
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.
Related videos on Youtube
Pondikpa Tchabao
Updated on April 29, 2022Comments
-
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 almost 5 yearsI cannot believe this is not provided in the official delpoyment documentation. It's so frustrating to find the answer here...
-
Daniel Allen over 4 yearsThis is the correct answer, and should be the accepted answer.
-
Daniel Allen over 4 yearsThe strategy here is correct, but the integer after the + is the versionCode, not the versionName.
-
Alex Semeniuk over 4 yearsAs @DanielAllen said before: versionName is before the + and versionCode is after the +
-
Dika over 4 yearsthank 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 over 4 yearsso at some later point in time, an app can look like
5.1.3+201
right? -
Renan Coelho over 4 yearsThe 1.0.2 is the versionName and +2 is the versionCode. Thnk you! This helped me a lot!
-
Marcel Hofgesang about 4 yearsno need to change in local.properties and generated.config
-
Ahmad Payan over 3 yearsHere is the link to the official deployment documentation: Updating the app’s version number
-
Vettiyanakan over 3 yearsI 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 over 3 yearsFor 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 over 3 years@ChuckK Correct.
-
Filippos Zofakis over 3 yearsYou only need to update the version code, version name is not necessary
-
kk_ over 2 yearsThis one worked for me... after having already tried to upload with 5 different version numbers. Really silly.
-
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 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 over 2 yearsThis 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 over 2 yearsI 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 inlocal.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 over 2 yearsExtra point, just flutter pub get doesn't fix. Nice catch.
-
68060 about 2 yearstried all of this but its still the same version code.. grr
-
Rohan Taneja about 2 years@68060 Even after a
flutter clean
? If you're running on Android, checklocal.properties
. If the newversionCode
doesn't show up there, it'll not show up on the app too. -
withoutOne about 2 yearsHow can I use a string value for version name?
-
Rohan Taneja about 2 yearsversion: any-string-here+1 should work
-
Rodrigo Molero almost 2 yearsYou 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.