Skip to content

· 13 min read · Nadeera Silva

Mobile

Version Code Has Already Been Used: Flutter Play Fix

Google Play says "Version code has already been used" when a Flutter build repeats a number. Find a free code and stop CI from reusing one.

A hand holding a plain wooden block above a staircase of wooden blocks, the same height as the top step so it can't be the next step, beside a phone with a blurred teal screen

You build a release, drag the .aab into Play Console, and it stops you with "Version code 1 has already been used. Try another version code." The Google Play version code error is one of the most common first-upload problems in Flutter, and it is never about your code. It is about one integer inside the bundle. Here is where Flutter gets that number, how to find the highest one Play has seen, and how to stop CI from reusing one.

Quick answer

Every app bundle or APK you upload to Google Play must have a versionCode the app has never used before, on any track, and newer releases need a higher one. In Flutter the number is the part after + in version: 1.2.3+45 in pubspec.yaml, or the value of --build-number. Raise it above the highest code shown in App bundle explorer, rebuild, and upload the new file.

What this means for your app or business

Nothing is broken in your app. Google Play uses a hidden build number to tell builds apart, and the file you tried to upload carries a number Play has already seen. The fix takes minutes: change one number, rebuild, upload again. It costs real time when it keeps coming back, usually because a build server and a laptop both produce "build 12" during an urgent release. Once one source picks the number, such as the CI run counter or Play itself, the error stops. If a team keeps tripping over it, this is a small piece of setup worth handing to someone who does it often.

Flow from pubspec.yaml version through Flutter build flags, local.properties and build.gradle.kts to the versionCode in the built app bundle, and Google Play's check against every version code already uploaded
How Flutter sets versionCode and where Google Play rejects a reused one

Why does Google Play say the version code has already been used?

Android has two version values: versionName, the text users see (1.2.3), and versionCode, a positive integer Android and Google Play use to decide which build is newer. The Android versioning guide is blunt about it: "You can't upload an APK to the Play Store with a versionCode you have already used for a previous version."

What surprises people is what counts as "used". All tracks share one pool of codes, so a bundle uploaded to internal testing uses its code for every other track too. In a Play community thread about this exact error, the developer had uploaded a bundle, discarded the production release without sending it for review, and hit the error on re-upload. The answer: every upload needs a new, higher build number, whether or not it went to review. Discarding a draft release does not give its number back.

The only documented exception is internal app sharing: Play Console Help says version codes there "don't need to be new or unique".

How does Flutter turn pubspec.yaml into a versionCode?

The Flutter Android release guide explains the mapping, and I confirmed each step with real builds:

  1. version: 1.2.3+45 in pubspec.yaml: 1.2.3 is the build name, 45 is the build number.
  2. flutter build appbundle --build-name 1.2.4 --build-number 46 overrides both values.
  3. The Flutter tool writes the result to android/local.properties as flutter.versionName and flutter.versionCode.
  4. The Gradle plugin reads those values, and the default android/app/build.gradle.kts passes them on with versionCode = flutter.versionCode and versionName = flutter.versionName.

The detail that explains the "Version code 1" wording: if pubspec.yaml has no +N part, Flutter removes flutter.versionCode from local.properties, and the Gradle plugin falls back to "1". I built a project with version: 1.2.3 and bundletool read versionCode 1 from the bundle. Every rebuild of that project uploads as version code 1, so the second upload always fails.

How do I fix "Version code 1 has already been used" in Flutter?

  1. Find the highest version code Play already has (next section).
  2. Set a higher build number in pubspec.yaml, for example version: 1.0.1+2.
  3. Rebuild with flutter build appbundle --release.
  4. Check the number inside the new file before you upload it.
  5. Upload build/app/outputs/bundle/release/app-release.aab, not an older copy from your Downloads folder.

If Play accepts the number but then complains about the signature, that is a different problem; see my post on an app bundle signed with the wrong key.

To check the bundle, use bundletool (1.18.3 is the current release). For an APK, aapt2 from the Android build tools works:

java -jar bundletool-all-1.18.3.jar dump manifest \
  --bundle build/app/outputs/bundle/release/app-release.aab \
  --xpath /manifest/@android:versionCode
# 46

aapt2 dump badging app-release.apk | head -1
# package: name='dev.nxdemo.vcdemo' versionCode='46' versionName='1.2.4' ...

How do I see the highest version code already used on Google Play?

In Play Console, open your app and go to Test and release > Latest releases and bundles > All app versions > App bundle explorer, the path given in Play Console Help. The version filter at the top right opens a table of the versions Play has for the app. Take the highest number and add one.

For scripts and CI, the Google Play Developer API gives you the same data. Reads happen inside an "edit", so the script below opens one, collects version codes from edits.bundles.list, edits.apks.list (older apps that still have APKs) and every release in edits.tracks.list, then deletes the edit. I check all three because track-based lookups only see codes that are in a release, while edits.bundles.list is documented as listing "all current Android App Bundles" of the app.

// Usage: node max-version-code.mjs com.example.app
// Auth: GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
import { GoogleAuth } from 'google-auth-library';

const pkg = process.argv[2];
if (!pkg) throw new Error('Pass the package name, for example com.example.app');

const root = process.env.PLAY_API_ROOT ?? 'https://androidpublisher.googleapis.com';
const base = `${root}/androidpublisher/v3/applications/${pkg}`;
const auth = new GoogleAuth({
  scopes: ['https://www.googleapis.com/auth/androidpublisher'],
});
const client = await auth.getClient();
const call = async (method, path) =>
  (await client.request({ url: base + path, method })).data;

// Every read in the Play Developer API happens inside an edit.
const edit = await call('POST', '/edits');
try {
  const [bundles, apks, tracks] = await Promise.all([
    call('GET', `/edits/${edit.id}/bundles`),
    call('GET', `/edits/${edit.id}/apks`),
    call('GET', `/edits/${edit.id}/tracks`),
  ]);
  const codes = [
    ...(bundles.bundles ?? []).map((b) => Number(b.versionCode)),
    ...(apks.apks ?? []).map((a) => Number(a.versionCode)),
    ...(tracks.tracks ?? []).flatMap((t) =>
      (t.releases ?? []).flatMap((r) => (r.versionCodes ?? []).map(Number)),
    ),
  ];
  const max = codes.length ? Math.max(...codes) : 0;
  console.log(JSON.stringify({ max, next: max + 1 }));
} finally {
  // Throw the edit away: we only read from it.
  await call('DELETE', `/edits/${edit.id}`);
}

Run it with a service account JSON that has access to the app in Play Console. If you get a 403, my post on the caller does not have permission error covers the access setup.

npm install google-auth-library
GOOGLE_APPLICATION_CREDENTIALS=play.json node max-version-code.mjs com.example.app
# {"max":45,"next":46}

I tested it against a mocked OAuth endpoint and a mocked Play API with nock 15.0.7 on Node 24 (Google's v3 discovery document, revision 20261126, for the request and response shapes):

✔ takes the highest code across bundles, APKs and track releases
✔ a bundle on no track still counts
✔ legacy split APK codes count too
✔ new app with nothing uploaded returns next = 1
ℹ tests 4
ℹ pass 4
ℹ fail 0

How do I stop CI from reusing version codes?

One source of truth for the build number, and it only goes up. Three ways to do that:

GitHub Actions: run_number plus an offset

github.run_number starts at 1 for a workflow's first run and goes up with every new run, and it does not change when you re-run a run. So re-running a run that already uploaded will hit the error; start a new run instead. Add an offset equal to the highest code you have already uploaded so the first CI build doesn't collide with manual ones:

name: Android release

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      # Highest version code already on Play when this workflow was added.
      VERSION_CODE_OFFSET: 100
    steps:
      - uses: actions/checkout@v7

      - uses: actions/setup-java@v6
        with:
          distribution: temurin
          java-version: '17'

      - uses: subosito/flutter-action@v2
        with:
          channel: stable

      - name: Pick the version code
        id: vc
        run: echo "code=$(( ${{ github.run_number }} + VERSION_CODE_OFFSET ))" >> "$GITHUB_OUTPUT"

      - name: Build the app bundle
        run: |
          flutter build appbundle --release \
            --build-number=${{ steps.vc.outputs.code }}

      - uses: actions/upload-artifact@v7
        with:
          name: app-release-${{ steps.vc.outputs.code }}
          path: build/app/outputs/bundle/release/app-release.aab

Both workflow files in this post passed actionlint 1.7.12. If anyone still uploads local builds by hand, you are back to two sources. Stop doing that, or let CI ask Play: commit the script as tool/max-version-code.mjs and replace the "Pick the version code" step with this one:

- name: Ask Google Play for the next version code
  id: vc
  env:
    PLAY_JSON: ${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}
  run: |
    printf '%s' "$PLAY_JSON" > "$RUNNER_TEMP/play.json"
    export GOOGLE_APPLICATION_CREDENTIALS="$RUNNER_TEMP/play.json"
    npm install --no-save google-auth-library
    next=$(node tool/max-version-code.mjs com.example.app | jq .next)
    echo "code=$next" >> "$GITHUB_OUTPUT"

For a wider look at the pipeline, see my solo SaaS CI/CD pipeline notes.

fastlane: google_play_track_version_codes

fastlane's google_play_track_version_codes action returns the version codes for one track, default production. Loop over the tracks you use and take the maximum. Code in a Fastfile runs inside the fastlane folder, so the lane goes up two levels before calling Flutter:

# android/fastlane/Fastfile
default_platform(:android)

platform :android do
  lane :release_bundle do
    codes = %w[internal alpha beta production].flat_map do |track|
      google_play_track_version_codes(track: track)
    rescue StandardError => e
      UI.important("Skipping #{track}: #{e.message}")
      []
    end
    next_code = (codes.max || 0) + 1
    UI.message("Highest code on Play tracks: #{codes.max.inspect}, building #{next_code}")

    # Fastfile code runs inside android/fastlane, so go up two levels.
    sh("cd ../.. && flutter build appbundle --release --build-number=#{next_code}")
  end
end

I ran this lane with fastlane 2.242.0, with the Play lookup replaced by a local stub returning 45 for internal and 44 for production. It printed "building 46" and called Flutter from the project root. Remember it only sees codes in track releases; a bundle that is only in the library will be missed, so keep a margin or use the API script.

Codemagic: google-play get-latest-build-number

Codemagic's CLI tools include google-play get-latest-build-number, which by default returns the highest build number across all tracks (internal, alpha, beta, production and custom tracks), according to the Codemagic build versioning docs. Since codemagic-cli-tools 0.73.0 (25 Nov 2026) there is also --include-uploaded-builds, which adds every uploaded bundle and APK, including ones on no track. Its source calls the same edits.bundles and edits.apks list methods as my script. If your build machine has an older version, run pip install --upgrade codemagic-cli-tools first. The built-in BUILD_NUMBER variable (builds of this workflow) works as a fallback:

LATEST=$(google-play get-latest-build-number --package-name "$PACKAGE_NAME" --include-uploaded-builds)
if [ -z "$LATEST" ]; then NEXT=$BUILD_NUMBER; else NEXT=$((LATEST + 1)); fi
flutter build appbundle --release --build-number="$NEXT"

The command reads the service account JSON from the GOOGLE_PLAY_SERVICE_ACCOUNT_CREDENTIALS environment variable.

Do split APKs change the version code?

Only for APKs built with flutter build apk --split-per-abi, where Flutter adds 1000 times an ABI number so each APK gets its own code (Flutter docs). With --build-number 46 I got 1046 for armeabi-v7a, 2046 for arm64-v8a and 4046 for x86_64 (the x86 slot, 3, is no longer used). You can turn this off with -P force-version-code-ignoring-abi=true. App bundles are not affected; my bundle built with --build-number 46 stayed at 46. If you ever uploaded split APKs, remember your next bundle must be higher than 4046, not 47.

Can I delete an uploaded bundle and reuse its version code?

Don't plan on it. Play Console Help documents discarding a release, and only the latest release on a track, but it doesn't describe a way to free a version code, and discarding a release leaves its bundle and its code behind. Developers on Stack Overflow report that App bundle explorer offers a delete option only for bundles never released (after removing them from any draft release), and released bundles stay forever. Raising the build number is faster and safer, so I treat every uploaded code as spent.

What does "superseded by another release" mean?

It is a related message, not an upload error. Play Console Help says a track is superseded when all its active bundles are "completely shadowed by active app bundles with higher version codes on its fallback track". In plain terms: production (or another track your testers can also get) has a higher version code than your test release, so testers get the production build and nobody receives the test build. Ship the test build with a code higher than production's.

Summary table

SituationversionCode Play seesWhat to do
pubspec has version: 1.2.3 with no +N1Add +N higher than the last upload
Rebuilt without changing +NSame as last uploadRaise +N or pass --build-number
Same build wanted on another trackAlready uploadedUse Add from library, don't upload again
Code used by a discarded draftStill usedPick a higher code
CI and laptop both build releasesDuplicatesLet one source pick the number (CI counter or Play API)
Split APKs uploaded before1000 x ABI + N, for example 4046Next bundle must be higher than the largest
Number above 2,100,000,000RejectedKeep codes small and steady

How do I check the version of an app already installed?

On a test device, adb shell dumpsys package com.example.app | grep version prints both values. Inside Flutter, package_info_plus returns them as version and buildNumber. On iOS, App Store Connect runs a similar check on the build number (CFBundleVersion, see Apple's CFBundleVersion reference), and Flutter fills it from the same +N.

Checklist before every Play upload

  • pubspec.yaml has a +N build number, or CI passes --build-number.
  • The number is higher than the highest code in App bundle explorer.
  • bundletool shows the expected versionCode in the exact file you will upload.
  • Promoting a build to another track uses Add from library, not a fresh upload.
  • Only one system (CI counter, Play lookup, or a person) chooses build numbers.
  • If you ever shipped split APKs, the next code is above the largest ABI code.
  • Codes grow by small steps and stay far below 2,100,000,000.

Frequently asked questions

What does "Version code 1 has already been used" mean on Google Play?

The bundle you uploaded has versionCode 1, and Play already has a bundle with that code for this app. Every upload needs a version code the app has never used, so raise the number and rebuild.

Why does my Flutter app always build version code 1?

Your pubspec.yaml version has no build number after a plus sign, for example version: 1.0.0. Flutter then falls back to versionCode 1. Use a value such as 1.0.0+2 or pass --build-number.

Does a discarded or draft release still use its version code?

Yes. Uploading the bundle is what uses the code, not publishing it, so a discarded draft still blocks that number. Pick a higher code for the next upload.

How do I change the version code in a Flutter app?

Change the number after the plus sign in the version line of pubspec.yaml, or build with flutter build appbundle --build-number followed by the new number. The flag overrides pubspec.yaml.

How can I check the version code of an Android app bundle?

Run bundletool dump manifest with --xpath /manifest/@android:versionCode on the .aab file. For an APK, aapt2 dump badging prints versionCode and versionName on the first line.

Can I reuse a version code on a different testing track?

No. All tracks of one app share the same version codes. To move a build to another track, use Add from library when creating the release instead of uploading it again.

What is the maximum version code on Google Play?

2,100,000,000. An app that reaches it can no longer upload updates, so increase codes in small steps and avoid timestamps as build numbers.

How do I get the latest Google Play version code on Codemagic?

Run google-play get-latest-build-number with your package name and add one. Since codemagic-cli-tools 0.73.0 the --include-uploaded-builds option also counts bundles that are not on any track.

Sources

  1. Version your app (Android Developers, 2025-08-20)
  2. Version codes (Play Console Help)
  3. Prepare and roll out a release (Play Console Help)
  4. Inspect app versions on the Latest releases and bundles page (Play Console Help)
  5. Set up an open, closed, or internal test (Play Console Help)
  6. Share app bundles and APKs internally (Play Console Help)
  7. Error: version code 1 has already been used (Google Play Developer Community, 2024-03-22)
  8. Method: edits.bundles.list (Google for Developers, 2025-05-21)
  9. REST Resource: edits.tracks (Google for Developers)
  10. Build and release an Android app (Flutter)
  11. Flutter 3.50.1 FlutterPlugin.kt (versionCode fallback and ABI codes) (Flutter on GitHub)
  12. google_play_track_version_codes (fastlane docs, 2026-11-27)
  13. fastlane directory behavior (fastlane docs)
  14. Automatic build versioning (Codemagic)
  15. codemagic-cli-tools changelog (0.73.0 adds --include-uploaded-builds) (Codemagic on GitHub, 2026-11-25)
  16. Contexts reference (github.run_number) (GitHub Docs)
  17. bundletool 1.18.3 (Google on GitHub, 2025-12-15)
  18. How do I delete an artifact build from the new dev console on Google Play? (Stack Overflow)
  19. CFBundleVersion (Apple Developer)
  20. package_info_plus 10.2.2 (pub.dev, 2026-10-01)
SharePost on XLinkedIn

Comments

Share a question or note about this article.

Loading comments…