Skip to main content

How I Fixed the “Version Code Already Used” Error in My React Native Expo App

I Get the Error: “Google Api Error: Invalid request — Version code 1 has already been used”

As I was submitting my React Native Expo app to the Google Play Store, I encountered an error that stopped me in my tracks:

Google Api Error: Invalid request - Version code 1 has already been used

I’ve submitted updates to the Play Store before, so I didn’t expect this issue. Everything seemed to be working fine, and I hadn’t made any changes to the versioning (or so I thought!). But this time, the build process failed due to a version code conflict.


What Is the “Version Code” in Android Apps?

When you submit an Android app to the Google Play Store, each version of your app must have a unique version code. This version code is an integer that must be incremented with every new release of your app, regardless of whether the version name (e.g., 1.0.0) stays the same.

For example, the version code is a simple number like 1, 2, 3, etc., and each time you submit a new build, this number must be higher than the previous version code.

The Solution: Updating the Version Code

After digging into the issue, I realized that I had forgotten to update the version code in my app’s configuration file. The error was triggered because I was trying to upload a new build with a version code that had already been used.

Here’s how I fixed it.


Step-by-Step Fix for the Version Code Error

In my case, I needed to update my app.json file to increase the version code for Android.

1. Open app.json

First, locate the app.json file in the root directory of your React Native Expo project. This file is used to configure your app’s build settings.

2. Update the Android Version Code

Inside the android section of app.json, I added "versionCode": 2. This ensures the new build has a unique version code that hasn’t been used before.

Here’s the updated portion of my app.json:

{
"expo": {
"android": {
"versionCode": 2,
...
},
...
}
}

You can set the versionCode to any integer that’s greater than your last submission. In my case, the previous submission used versionCode: 1, so I simply bumped it to 2.

3. Rebuild and Resubmit

After updating the version code, I rebuilt the app using Expo’s eas build and submitted it to the Google Play Store again.


Why You Should Pay Attention to Version Code in Android

The version code is not visible to users, but it’s critical for managing app updates on the Google Play Store. Here’s why:

  • Internal Tracking: Google Play uses the version code to track the latest version of your app. It ensures that users receive the correct updates.
  • Upgrade Path: The version code ensures that users can upgrade from an older version of the app to a newer one without issues.
  • Avoiding Conflicts: If you try to upload a build with the same version code as a previous release, Google Play will reject it. This is why you must increment the version code for every new release.

Conclusion

If you’re submitting an Android app to the Play Store and encounter the error “Google Api Error: Invalid request — Version code 1 has already been used”, the fix is simple: increase the versionCode in your app.json file.

This small mistake can easily slip through the cracks, but now that I know how it works, I’ll be sure to update the version code for every new release moving forward. So, the next time you update your React Native Expo app, remember to bump that version code!


TL;DR

  • Error: Google Api Error: Invalid request - Version code 1 has already been used
  • Fix: Increase the versionCode in app.json under the android section.
  • Example:
{   "expo": {     "android": {       "versionCode": 2     }   } }

I hope this quick fix helps you avoid the same confusion I had. Happy coding!

    Popular posts from this blog

    Xcode and iOS Version Mismatch: Troubleshooting "Incompatible Build Number" Errors

    Have you ever encountered a frustrating error while trying to run your iOS app in Xcode, leaving you scratching your head? A common issue arises when your device's iOS version is too new for the Xcode version you're using. This often manifests as an "incompatible build number" error, and looks like this: DVTDeviceOperation: Encountered a build number "" that is incompatible with DVTBuildVersion. This usually happens when you are testing with beta versions of either iOS or Xcode, and can prevent Xcode from properly compiling your storyboards. Let's explore why this occurs and what you can do to resolve it. Why This Error Occurs The core problem lies in the mismatch between the iOS version on your test device and the Software Development Kit (SDK) supported by your Xcode installation. Xcode uses the SDK to understand how to build and run apps for specific iOS versions. When your device runs a newer iOS version than Xcode anticipates, Xcode mi...

    How to Fix the “Invariant Violation: TurboModuleRegistry.getEnforcing(…): ‘RNCWebView’ Could Not Be Found” Error in React Native

    When working with React Native, especially when integrating additional libraries like react-native-signature-canvas , encountering errors can be frustrating. One such error is: Invariant Violation: TurboModuleRegistry. getEnforcing (...): 'RNCWebView' could not be found This error often occurs when the necessary dependencies for a module are not properly linked or when the environment you’re using doesn’t support the required native modules. Here’s a breakdown of how I encountered and resolved this issue. The Problem I was working on a React Native project where I needed to add the react-native-signature-canvas library to capture user signatures. The installation process seemed straightforward: Installed the package: npm install react-native-signature- canvas 2. Since react-native-signature-canvas depends on react-native-webview , I also installed the WebView package: npm install react- native -webview 3. I navigated to the iOS directory and ran: cd ios pod install Everythi...

    Fixing FirebaseMessagingError: Requested entity was not found.

    If you’re working with Firebase Cloud Messaging (FCM) and encounter the error: FirebaseMessagingError: Requested entity was not found. with the error code: messaging/registration-token-not-registered this means that the FCM registration token is invalid, expired, or unregistered . This issue can prevent push notifications from being delivered to users. ๐Ÿ” Possible Causes & Solutions 1️⃣ Invalid or Expired FCM Token FCM tokens are not permanent and may expire over time. If you’re storing tokens in your database, some might be outdated. ✅ Solution: Remove invalid tokens from your database when sending push notifications. Refresh and store the latest FCM token when the app starts. Example: Automatically Refresh Token firebase. messaging (). onTokenRefresh ( ( newToken ) => { // Send newToken to your backend and update the stored token }); 2️⃣ Token Unregistered on Client Device A token might become unregistered if: The app is uninstalled on the user’s device. ...