Build error : APK specifies a version code that has already been used

When trying to build and deploy , I get the following error :
[13:44:42]: Google Api Error: forbidden: 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) |
±-----±-------------------------±------------+
| 1 | default_platform | 0 |
| 2 | build_summary | 0 |
| 3 | add_git_credentials | 0 |
| 4 | detect_native_type | 0 |
| 5 | get_web_dir | 0 |
| 6 | modify_cap_web_config | 0 |
| 7 | download_credential | 1 |
| 8 | build_pro_app | 101 |
| 9 | cap_sync | 10 |
| 10 | cap_custom_deploy | 0 |
| 11 | build_android_capacitor | 89 |
| 12 | get_filename_apk | 0 |
| :boom: | upload_apk_to_play_store | 4 |
±-----±-------------------------±------------+

[!] Google Api Error: forbidden: APK specifies a version code that has already been used. - APK specifies a version code that has already been used.
[13:44:42]: fastlane finished with errors
Running after script…
$ run “clean-up”
ERROR: Job failed: command terminated with exit code 1

I have first created manually a version 1 in Google Play Console, I have then changed my config.xml to add the android version like this :

…widget android-versionCode=“2” android-versionName=“1.0.1” id=“com.xxx.xxx” version=“1.0.1” xmlns=“http://www.w3.org/ns/widgets” xmlns:cdv=“http://cordova.apache.org/ns/1.0”…

But still getting this error.

Could anyone help please ?

I am having some difficulty while deploying the apk to playstore. Currently we manually update the version code and version name before triggering the build. Despite the version update I always get
Failed to upload apk, error: googleapi: Error 403: APK specifies a version code that has already been used., apkUpgradeVersionConflict

Configuration

 google-play-deploy@1.4.1:
        inputs:
        - mapping_file: android/app/build/outputs/mapping/release/mapping.txt
        - package_name: com.iota.packagename
        - apk_path: "$BITRISE_SIGNED_APK_PATH"
        - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_URL"

I’m really not sure how I can further debug but I do have the versions upgraded in the appropriate files.

I would greatly appreciate any help regarding this.

Cordova does some arithmetic to create a version code based on the version name. If you’ve ever submitted a build where cordova managed the value it’s likely much higher than 2. versionCode just needs to be an integer value higher than any previous release.

You should be able to check the Play console to see the version code for your latest release. Just be aware that once you override the cordova generated value you’ll want to continue to do so going forward.