Skip to content

Commit e1bf515

Browse files
gedeagasfacebook-github-bot
authored andcommitted
Making Android versionCodeOverride for new apps using the template human-readable (#29808)
Summary: The current calculation on versionCodeOverride is not human-readable. Imagine if we have an android app with **versionName** `4.0` and **version code** `4`. In the current implementation, the result of **versionCode** `4` for `armeabi-v7a` will be the seemingly arbitrary **1048580**. This makes the version code to be seemingly arbitrary and hard to read for humans. This PR proposes to change this calculation closer to google implementation of build number in Flutter (`abiVersionCode * 1000 + variant.versionCode`). https://github.com/flutter/flutter/blob/39d7a019c150ca421b980426e85b254a0ec63ebd/packages/flutter_tools/gradle/flutter.gradle#L643-L647 With this change, our app with `versionCode 4 versionName "4.0"` for `armeabi-v7a` will have **1004** as the version code instead of the seemingly arbitrary **1048580**. As you can see adopting the flutter style implementation make the version code easier to read and debug. **1004** **1** - The ABI Type `["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]` **004** - Our versionCode. Hopefully, this can prevent future issues like this #29790. ## Changelog [Android] [Changed] - Making Android versionCodeOverride for new apps using the template human-readable Pull Request resolved: #29808 Reviewed By: sammy-SC Differential Revision: D23804632 Pulled By: fkgozali fbshipit-source-id: 89b2c196b3bfe01fa608dfb595db6d3314ca1d63
1 parent 22b5f32 commit e1bf515

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

template/android/app/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,12 @@ android {
171171
variant.outputs.each { output ->
172172
// For each separate APK per architecture, set a unique version code as described here:
173173
// https://developer.android.com/studio/build/configure-apk-splits.html
174+
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
174175
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
175176
def abi = output.getFilter(OutputFile.ABI)
176177
if (abi != null) { // null for the universal-debug, universal-release variants
177178
output.versionCodeOverride =
178-
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
179+
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
179180
}
180181

181182
}

0 commit comments

Comments
 (0)