I just made a new Android bundle for my React Native app. I manually updated the version code from 90 to 91 in android/app/build.gradle, but now that I am trying to upload to Play Store, the version code is 3145819 (I expected to see 91)
build.gradle:
defaultConfig {
applicationId "com.myapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 91
versionName "4.1.0"
multiDexEnabled true
missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57_5"
resValue "string", "build_config_package", "com.myapp"
}
I use this command to bundle:
./gradlew bundleProdRelease --console plain
Not sure why this is happening, and I definitely prefer a smaller version code (easier for users to read when reporting bugs).
Any idea what's going on here and how to fix it?
Ohhh ok I finally figured it out! No, I haven't been desperately looking for an answer for the past two years... I just somehow stumbled upon it now.
So, in android/app/build.gradle
, there is a script that generates the bundle version code. It's calculated from the version code and the target architecture version code. For example in the RN 0.64x template:
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) {
output.versionCodeOverride = defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}
For me, arm64-v8a
always seems to get used as the default when generating the version code, so I get outputs like:
versionCode 1 => 1003
versionCode 12 => 12003
versionCode 105 => 105003
you get the idea...
The calculation used to involve a much more mysterious number (1048576
🔮🧙♂️, see in the RN 0.59x template), which seemed arbitrary and made it quite tricky to understand how this bundle version code was generated.
Now it makes much more sense!