Google play console upload new version for internal testing [duplicate] - android
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.
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
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:
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
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.
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-
In pubspec.yaml change your version number.
Update your local.properties by running flutter pub get command.
Now build your apk or app bundle by running flutter build apk or flutter build appbundle command.
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.
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
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
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
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
Check
android{
//....
defaultConfig {
//....
version code:2
}
}
on android>app>Build.gradle from your project's root folder
You can still do completely your own thing by overwriting in android/app/build.gradle:
def flutterVersionCode
def flutterVersionName
to your own values.
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
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`
I had the same problem, I solve it by restarting Android Studio.
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)
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.
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
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.
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.
before uploading the app bundle, first write the Release name.
I faced the same issue and That's worked for me.
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'
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!
you can update the local.properties file,
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'
}
Related
Flutter Application publish Version code 1 has already been used. Try another version code
I wont to upload my update number 12 code version to correct some bugs and I test many Solutions but always When I upload my appbundels Google play console return this messages "Version code 1 has already been used. Try another version code." Last App bundle uploaded 11 (1.0.0) pubspec.yaml version: 1.0.2+2 android/app/build.gradle `def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '2' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0.2' }` android/local.proprieety flutter.versionCode=2 flutter.versionName=1.0.2 I change many time my version code to 1.0.0+13 I run pub get I restar my computer and my IDE I run App before build bundels
Update version:1.0.2+3 in pubspec.yaml. and save it and run these commands : flutter clean flutter pub get flutter build appbundle
Version code 1 has already been used. Try another version code
I am uploading new app bundle to play console and it is saying after uploading Version code 1 has already been used. Try another version code. I have changed version number in pubspec.yaml from version number: 1.0.0+1 to 2.0.0+1 even though it is saying the same error
You have two ways to solve this, if you released your bundle already, then you have to update your version code like in Len_X's answer, If you're still developing and pushed app bundle for say, testing, and then you delete it, this bundle is saved as a draft with that version code. Therefore, it says that you can't use the same version because it already sees another one with the same version name. Here's how you fix it: Go to the release section go to app bundle explorer, in the top right you should see a dropdown button for you app version, click on it. A bottomsheet will show containing all the previous app bundles you uploaded it. Delete the one with clashing bundle version and you're good to go. Hope that solves your problem.
You can do it manually by going to "app_name/android/app/build.gradle" file. In defaultConfig section change version code to a higher number defaultConfig { applicationId "com.my.app" minSdkVersion 23 targetSdkVersion 30 versionCode 1 // Change to a higher number versionName "1.0.1" // Change to a higher number testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { arguments = ["room.schemaLocation": "$projectDir/schemas".toString()] } } }
First go to the app/build.gradle change versionCode and versionName like this (+1) I think this will be helpful for someone ✌😊
For Flutter only: Goto Pubspec.yaml file and find version key and Change the value after the + sign. For Example: In your pubspec.yaml file, if your version is like this version: 1.0.0+1 then change it to version: 1.0.0+2
You have to increment the +1, it should be +2 to indicate build number
if you remove apk then upload same version apk so you get Error Version code 1 has already been used. Try another version code in this situation you should remove version from App bundle explorer then upload same version apk.
If you're running into app bundle approval issues inside of the Google Play store with an Expo/React Native project, here are some tips: Google Play versioning is actually checking your AndroidManifest.xml file for versioning (/android/app/src/). This should get updated from Expo's app.json file (/app.json) during build, per their instructions. app.json example section, where I've bumped my app up to a v2.0 - note the versionCode inside of the Android settings object AND the version at the settings object root both need to be adjusted: { "name": "app-name", "displayName": "App Name", "expo": { "android": { "package": "app.here", "permissions": [], "versionCode": 2 } }, "version": "2.0.0" } If your Android version isn't updating (possibly if you have a detached Expo app), you have to go directly into the AndroidManifest.xml file and make the modification there (/android/app/src/): Example of AndroidManifest.xml (note your modifications happen on the <manifest> tag, using the android:versionCode and android:versionName: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.aganashapp" android:versionCode="2" android:versionName="2.0" > <uses-permission android:name="android.permission.INTERNET"/> <application android:name=".MainApplication" android:label="#string/app_name" android:icon="#mipmap/ic_launcher" android:allowBackup="false" android:theme="#style/AppTheme" > <meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://exp.host/#username/app-name" /> <meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="42.0.0" /> <meta-data android:name="expo.modules.updates.EXPO_RELEASE_CHANNEL" android:value="default" /> <activity android:name=".MainActivity" android:label="#string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="#style/Theme.App.SplashScreen" > <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/> </application> </manifest> If you're still having issues, remember that Android versionCode and versionName are two different things. Android does not seem to recognize semver standards. versionCode increments as whole numbers (ie, if you went from semver v1.0.0 to v1.1.0 that is versionCode 1 to 2.
with my flutter project building a release for android i faced the same issue. all was doing is change version code in Pubspec.yaml but did not seem to change my android version... so i went to Android folder and added version code manually in local.properties file : /project/android/local.properties flutter.versionName=1.1.0 flutter.versionCode= from 1 to 4
I always used to increment version code in my android/app/build.gradle file, and it always used to work. Then, after a recent update in Android Studio, it suddenly didn't anymore, and I got this error! I never cared to dig into the build.gradle code, but now, I did. Here, at the "TODO", is where I used to change the version code number: def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '19' // TODO: ---Count up with each release } But that only works if the version code from the local.properties file comes back as "null"!... I just realized. So probably, all this time, my compiler never managed to get values from local properties, but now all of a sudden, it does! So I found the android/local.properties file and tried changing the version code there: sdk.dir=C:\\Users\\karol\\AppData\\Local\\Android\\sdk flutter.sdk=C:\\src\\flutter flutter.buildMode=release flutter.versionName=1.0.0 flutter.versionCode=1 //Change this to 19 (my current version code number) But that didn't work, because the moment I ran flutter build appbundle, this file changed itself back to the original values... I then tried adding version code values to my AndroidManifest.xml file, according to serraosays' answer, but that didn't help me either. Functioning work-around In the end, I did this in the android/app/build.gradle file: def flutterVersionCode = localProperties.getProperty('flutter.versionCode') //if (flutterVersionCode == null) { flutterVersionCode = '19' // TODO: ---Count up with each release //} That is, I commented out the condition. Now, my setting would over-write any value retrieved from the local.properties file. If anyone can tell me the proper way to increment the version code number, I'm all ears! 🙂 But in the meantime, this worked for me, and hopefully for someone else as well.
If you get the above error in the google play console, please change the version: in pubspec.yaml. Reference. How to set build and version number of Flutter app and me works
The first step change the version code The second step go to the other settings and change the bundle version code as well
There are two reasons for this error: First, is common given in other answers: you must increase the version number to send an update to Play Console. Eg. previous app version: 1.0.5+5 and next update must contain 1.1.2+6. The +6 must be next to the previous update present on your play console. Second reason for this error is you have skipped some numbers in between. Eg. Previous released version: 1.0.5+5 but the new version you are trying to release is 1.0.6+8. The +8 is not allowed directly, you must put +6 then +7 and then next numbers.
In unreal engine you can change this in project settings. Steps are as follows. (Me I'm using UE4.27.2) Step 1: Open Project Settings Step 2: Click all settings and in the top search bar type in "version" Without Quotes. Step 3: Scroll down to >Platforms>Android>apk packaging Step 4: Change the store Version for each +1 what you already have APK PAckaging (You do not need to change version display name but you can if you want to this can be edited later on in google console)
change version code here please check the imageenter image description here
Versioning works the other way around. Do not update the pubspec.yaml manually. See the default comment in the pubspec.yaml: # Both the version and the builder number may be overridden in flutter # build by specifying --build-name and --build-number, respectively. So you should run flutter build appbundle --build-name 2.0.0 --build-number 2 This updates the pubspec.yaml for you.
For hybrid apps/JavaScript based frameworks like Ionic or Flutter updating package.json is not enough you sometimes, can directly edit build.gradle file in the build folder. versionCode 2 versionName "2.0" This is not a good practice
Change versionCode of an App created in a gradle script
in an Android app I did not develop, but I have to edit, I found this gradle script: buildscript { repositories { jcenter() } dependencies { classpath 'org.ajoberstar:grgit:1.5.0' } } import org.ajoberstar.grgit.Grgit ext { git = Grgit.open(currentDir: projectDir) gitVersionName = git.describe() gitVersionCode = git.tag.list().size() gitVersionCodeTime = git.head().time } task printVersion() { println("Version Name: $gitVersionName") println("Version Code: $gitVersionCode") println("Version Code Time: $gitVersionCodeTime") } The "gitVersionCode" variable is used as "versionCode" of the app in the build.gradle file. This is the build.gradle file: // gradle script apply from: "$project.rootDir/tools/script-git-version.gradle" //... defaultConfig { applicationId "..." minSdkVersion 17 targetSdkVersion 25 versionCode gitVersionCode versionName gitVersionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } When I generate signed APK and try to add to beta version, I get the google error that "Version code already exists", but I do not know how to edit the version code of the app. My questions are: what this code actually does? how to edit the version code of the app?
Git is a version control system. Your project appears to be stored in a Git repository. Grgit is a Groovy library that works with Git. Your Gradle script is loading this library. git is an instance of Grgit. git.tag.list() returns a list of the Git tags used in this repository. git.tag.list().size() returns the number of tags in that list. So, this Gradle script is setting the versionCode to be the number of Git tags used in the project's Git repository. how to edit the version code of the app? Either: Create another Git tag, such as by tagging the version that you are trying to release, or Change versionCode gitVersionCode to stop using gitVersionCode and use some other numbering system
It appears to be using this library to query git, in order to generate the version name and version code. In terms of the version code, it looks like it's setting it depending on the number of git tags it finds. So, to bump the version code, do a git tag on your release commit. If that doesn't suit, you could just do it manually and replace versionCode gitVersionCode with versionCode 99 replacing "99" with whatever your version code should be.
Android Gradle 'versionCode' not read from environment variable
I have an Android that I deploy to a Google Play alpha track trough a CI server. For the Android versionCode I make use of the CI build number that I inject into the Gradle script through an environment variable. This used to work fine; but currently Google Play is not accepting any builds. When I manually trigger a alpha upload build (using the gradle-play-publisher plugin) for Gradle I eventually end up with the following error: APK has an invalid version code. So when looking (using aapt dump badging apk-path) at the generated APK I see an empty value for the version code (versionCode=''). The relevant code from the build script: def appVersionCode = System.getenv("BUILD_NUMBER") as Integer ?: 0 defaultConfig { ... versionCode appVersionCode ... } It seems the variable is not read correctly; however it reads System.getenv("KEY_PASS") correctly to use for signing. The variable is also set: ❯ echo $BUILD_NUMBER 1234 Does anyone have an idea why this specific variable doesn't seem to be read (anymore)? Gradle version: 3.5 with Android Gradle plugin 2.3.1.
Try to change your code to this: def appVersionCode = Integer.valueOf(System.env.BUILD_NUMBER ?: 0) defaultConfig { ... versionCode appVersionCode ... }
In Flutter pubspec.yaml file updated the version to 1.1.0+3 but on uploading to playConsole, still error version code 1
I've tried to upload an updated aab to the playConsole for my application but have got the following error: Upload failed You need to use a different version code for your APK or Android App Bundle because you already have one with version code 1. I've tried to update the version code to 3 in the pubspec.yaml but I'm still getting the same version after uploading the latest generated aab/apk.
Did you try to do a flutter clean before building the second time? The previous build might have been cached. Other then that, check your android/app/build.gradle file there should be something like this there that sets the version: def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' }
Finally resolved it! The issue was with the android/local.properties file which was not getting updated. I manually updated the version code here and got around the problem.