SoldierCorp
SoldierCorp

Reputation: 7700

React Native: Version code too big for Android using enableSeparateBuildPerCPUArchitecture

I was compiling my React Native App for Android having enableSeparateBuildPerCPUArchitecture to false but since I read if I set to true, then the app will reduce like 4mb and it's true.

So my current version code was 9 so I set to 10 the new one and when I created a new release with that option to true I uploaded it to my Google Play dashboard and I realised the new version code is not 10 but is 1048586 :/

Fortunately I don't published that version and I just removed it but I'm wondering what happened and if that's normal and if I create a new version after that, the number will increate just 1 unit like 1048586 to 1048587?

Thanks!

EDIT

I found the line of code that set the version code

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        // For each separate APK per architecture, set a unique version code as described here:
        // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
        def versionCodes = ["armeabi-v7a":1, "x86":2]
        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
        }
    }
}

But still I couldn't find the real reason about why it's necessary to increase the version code to a big number

Upvotes: 5

Views: 3720

Answers (3)

Deepak Yadav
Deepak Yadav

Reputation: 1

change - def enableSeparateBuildPerCPUArchitecture from true to false after that whenever you create a build it should be increment with +1 only.

Upvotes: 0

Prakhar Agrawal
Prakhar Agrawal

Reputation: 1022

Let's assume you multiplied with a small number .... like say 2.

So apk version codes for ["armeabi-v7a":1, "x86":2] will be

When you set the android: default version code to be 1:

  • armeabi-v7a: 1 * 2 + 1 = 3
  • x86: 2 * 2 + 1 = 5

Let's say you have another release now and decide to to use default version code to be 2. Hence version codes for architectures:

  • armeabi-v7a: 1 * 2 + 2 = 4
  • x86: 2 * 2 + 2 = 6

Now in the next release when you use default version code of 3, you'll notice that we run into issues. Here, version codes for architectures:

  • armeabi-v7a: 1 * 2 + 3 = 5 (CONFLICTS with x86 version code for 1st release)
  • x86: 2 * 2 + 3 = 7

PS: The above answer is solely based on my understanding/interpretation and the original authors could very well have had an entirely different reason.

Upvotes: 0

pstanton
pstanton

Reputation: 36640

"We need this because each APK in the ABI requires a separate version code which goes up each time the app updates. This code block adds a different constant for each architecture to your base version code. Each APK then get their own distinct values which are unlikely to overlap. For more details take a look at the Android documentation for ABI splits."

https://reactnative.thenativebits.com/courses/upgrading-react-native/upgrade-to-react-native-0.59/

Therefore you need to "give up control" of your versionCode to the build system and rely on the versionName instead.

Upvotes: 1

Related Questions