Version code 4 has already been used. PlayStore Error

This is yet another error that ended up wasting several hours of my time. The error message itself was pretty straightforward:

“Version code 4 has already been used. Try another version code.”

At first, I assumed that simply updating the version on the Play Store would resolve itβ€”but that didn’t work. I kept running into the same issue every time I tried to upload a new app bundle.

After digging through forums and trying various fixes, I finally discovered that the problem required more than just a Play Store update. You actually need to manually increment the version code in your project files.

The key files that need to be updated are:

  • pubspec.yaml β€” Update the version number here, especially the build number after the + sign.
  • build.gradle β€” Check and update the versionCode and versionName inside the defaultConfig block.
  • local.properties β€” This may cache certain values; update only if the other two changes don’t solve the issue.

Here’s what I recommend doing, in order:

  1. Start by modifying the version in pubspec.yaml.
  2. If that doesn’t fix it, move on to updating build.gradle.
  3. If you’re still stuck, then try updating local.properties.

Once you’ve made the necessary changes, make sure to run the following commands to clean up and rebuild your app:

flutter clean
flutter pub get
flutter build appbundle

This fixed the problem for me after hours of frustration. I’ve also included an image below for reference.

pubsec.yaml
build.gradle
local.properties flutter