
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
inapp.json
under theandroid
section. - Example:
{ "expo": { "android": { "versionCode": 2 } } }
I hope this quick fix helps you avoid the same confusion I had. Happy coding!