'APK version code conflict despite Google Play Store showing otherwise
I am using fastlane to automatically increment my version code and deploy my app. I am getting the error apkNotificationMessageKeyUpgradeVersionConflict: APK specifies a version code that has already been used. - APK specifies a version code that has already been used
despite the highest versionCode of my releases is 3.
Lanebump_version_code
executing
[03:47:41]: ------------------------------
[03:47:41]: Driving the lane 'android alpha' 🚀
[03:47:42]: ------------------------------------------------------
[03:47:42]: --- Step: Switch to android bump_version_code lane ---
[03:47:42]: ------------------------------------------------------
[03:47:42]: Cruising over to lane 'android bump_version_code' 🚖
[03:47:42]: ---------------------------------------------
[03:47:42]: --- Step: google_play_track_version_codes ---
[03:47:42]: ---------------------------------------------
[03:47:43]: Found '1' version codes in track 'production'
[03:47:43]: ---------------------------------------------
[03:47:43]: --- Step: google_play_track_version_codes ---
[03:47:43]: ---------------------------------------------
[03:47:45]: Found '1' version codes in track 'beta'
[03:47:45]: ---------------------------------------------
[03:47:45]: --- Step: google_play_track_version_codes ---
[03:47:45]: ---------------------------------------------
[03:47:46]: Found '3' version codes in track 'alpha'
[03:47:46]: ------------------------------------
[03:47:46]: --- Step: increment_version_code ---
[03:47:46]: ------------------------------------
[03:47:46]: The get_version_code plugin is looking inside your project folder (./app)!
[03:47:46]: ☝️ Version code has been changed to 4
[03:47:46]: Cruising back to lane 'android alpha' 🚘
Lane context and error
+-------------------------------------+-------------------------------------------------------------------------------------------------------------------+
| DEFAULT_PLATFORM | android |
| PLATFORM_NAME | android |
| LANE_NAME | android alpha |
| VERSION_CODE | 4 |
| GRADLE_BUILD_TYPE | Release |
| GRADLE_ALL_APK_OUTPUT_PATHS | ["/Users/runner/runners/2.165.2/work/myapp/myapp/client/android/app/build/outputs/apk/release/app-release.apk"] |
| GRADLE_ALL_AAB_OUTPUT_PATHS | [] |
| GRADLE_ALL_OUTPUT_JSON_OUTPUT_PATHS | ["/Users/runner/runners/2.165.2/work/myapp/myapp/client/android/app/build/outputs/apk/release/output.json"] |
| GRADLE_ALL_MAPPING_TXT_OUTPUT_PATHS | [] |
| GRADLE_APK_OUTPUT_PATH | /Users/runner/runners/2.165.2/work/myapp/myapp/client/android/app/build/outputs/apk/release/app-release.apk |
| GRADLE_OUTPUT_JSON_OUTPUT_PATH | /Users/runner/runners/2.165.2/work/myapp/myapp/client/android/app/build/outputs/apk/release/output.json |
+-------------------------------------+-------------------------------------------------------------------------------------------------------------------+
[03:49:53]: Google Api Error: apkNotificationMessageKeyUpgradeVersionConflict: APK specifies a version code that has already been used. - APK specifies a version code that has already been used.
+------+------------------------------------------+-------------+
| fastlane summary |
+------+------------------------------------------+-------------+
| Step | Action | Time (in s) |
[!] Google Api Error: apkNotificationMessageKeyUpgradeVersionConflict: APK specifies a version code that has already been used. - APK specifies a version code that has already been used.
+------+------------------------------------------+-------------+
| 1 | default_platform | 0 |
| 2 | Switch to android bump_version_code lane | 0 |
| 3 | google_play_track_version_codes | 1 |
| 4 | google_play_track_version_codes | 1 |
| 5 | google_play_track_version_codes | 1 |
| 6 | increment_version_code | 0 |
| 7 | clean | 47 |
| 8 | assembleRelease | 73 |
| 💥 | upload_to_play_store | 5 |
+------+------------------------------------------+-------------+
Fastfile
lane :bump_version_code do
g = google_play_track_version_codes
gb = google_play_track_version_codes(track: 'beta')
ga = google_play_track_version_codes(track: 'alpha')
max_value = [g[0].to_i, gb[0].to_i, ga[0].to_i].max
version_updated = max_value + 1
increment_version_code(
app_folder_name: "./app",
version_code: version_updated.to_i
)
end
desc "Submit a new Alpha Build to Google Play"
lane :alpha do
bump_version_code
gradle(task: 'clean')
gradle(
task: 'assemble',
build_type: 'Release',
properties: {
"android.injected.signing.store.file" => ENV["ANDROID_KEYSTORE"],
"android.injected.signing.store.password" => ENV["ANDROID_KEYSTORE_PASSWORD"],
"android.injected.signing.key.alias" => ENV["ANDROID_KEY_ALIAS"],
"android.injected.signing.key.password" => ENV["ANDROID_KEY_PASSWORD"],
}
)
upload_to_play_store(track: 'alpha')
end
Archive library
Solution 1:[1]
Go to Google Play Console
- "App bundle explorer" in the sidebar
- top right corner, click on the "App version: *** ?"
- you should see all the uploaded bundle. Delete the one that have the version code you want to use.
Explanation: this happened to me while playing with Fastlane. I uploaded a bunch of .aab files and the versionCode was updated all the time (I was toying with increment_version_code plugin so this make sense). I ended up pushing a build by hand because I got an error (that has nothing to do with versionCode). After a few days, I tried to continue working on that and wanted to upload my build "3" (versionCode: 3, as I only pushed 2 bundles in testing, the others where unused)... But during my previous days, I upload three builds 3, 4 and 5, that were causing the issue. Deleting them allowed me to push a new build with versionCode 3.
Solution 2:[2]
This is because you have some artifact uploaded on the artifact library that has been uploaded manually. If you delete it it will work. You can find the Artifact Library on the left menu, inside release management.
Probably there will be some draft binaries uploaded with a code version bigger than the ones on the active ones.
Solution 3:[3]
The error you got is due to after updating version code through increment_version_code, it again looks for "app/build.gradle" and picks version code from there which conflicts and then gives error.
You can solve this by 2 methods.
- Add another lane below 'bump_version_code'.
lane :gitpush do
git add
git commit(path: '*', message: 'Version')
push_to_git_remote
Note:- If you build your app using CI workflows, add Git authentication step in your CI.yml
name: Deploy
on:
push:
branch: [ master ]
jobs:
distribute:
run-on: Ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Build App
run: npm run build
- name: Git Config
run: |
git config user.name "xyz"
git config user.email "[email protected]"
git config user.password "xyz123"
- name: Deploy
run: fastlane alpha
- Another method is to properly config google_play_track_version_code which is better way to do it.
lane :increment_version_code do
version_code = google_play_track_version_codes(
package_name: "your package name", #e.g. com.xyz.app
track: "track-name", #e.g. alpha
json_key: "json key file path",
)
version_code_play_store = version_code[0].to_i
update_version_code = version_code_play_store + 1
increment_version_code(
gradle_file_path: "your gradle file path",
version_code: update_version_code.to_i
)
end
Hope this will help :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | MoOx |
Solution 2 | |
Solution 3 | sahil sharma |