Skip to content

Commit

Permalink
Making Android versionCodeOverride for new apps using the template hu…
Browse files Browse the repository at this point in the history
…man-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
  • Loading branch information
gedeagas authored and facebook-github-bot committed Sep 21, 2020
1 parent 22b5f32 commit e1bf515
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion template/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ android {
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}

}
Expand Down

0 comments on commit e1bf515

Please sign in to comment.