'How to assign different versionCode for multiple architecture apks built with flutter
My pubspec.yaml has version code 11.
Building a fat apk with flutter build apk gives an apk with versionCode 11 as expected. But building an armeabi-v7a-release apk gives an apk with versionCode 1011 instead of 11.
I would like to change the behaviour of incrementing 1000 to the versionCode of armeabi-v7a as mentioned in android's documentation (Thanks to @Varun Kumar for pointing it). I want the armeabi-v7a apk to have the versionCode corresponding to that mentioned in pubspec.yaml. How do I edit this build.gradle to achieve the same?
Solution 1:[1]
Figured that it's possible to override the output .apk file's versionCode by adding code to the build.gradle(:app) as mentioned in android's documentation that allows us to explicitly modify the logic followed to assign versionCode for each abi.
For avoiding the 1000 increment made to armeabi-v7a alone, I modified the logic of the inner if block to the following:
if (baseAbiVersionCode != null ) {
output.versionCodeOverride =
baseAbiVersionCode * 1000 + variant.versionCode
if (baseAbiVersionCode == 1) { // Matches armeabi-v7a in ext.abiCodes
// Uses the default versionCode for armeabi-v7a APKs.
output.versionCodeOverride = variant.versionCode
}
}
NOTE: This part is a little hacky as you might end up having the same versionCode for both the fat apk and the armeabi-v7a ABIs. I would recommend using this only if you want to target one ABI exclusively.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ashwin |
