3

Question

Is it possible to either add things to the default props of the index.android.js from the build.gradle or any file at runtime?

OR

Grab the versionCode from the build.gradle file from within my react-native code?

Problem

I'm trying to programmatically have a version number in my application based on the version, build and git sha. The format is essentially version-gitsha-jenkinsBuildNumber (for example 1.0.0-abc1234-83). I was able to get this to work on iOS by using a bash script to add it to the Info.plist and then followed How to read Info.Plist at run-time in react-native iOS app? in order to add them to my default props in my index.ios.js. I cannot find a way to do this in the build.gradle.

What I've Tried

Right now, I'm replacing the versionName string in the defaultConfig with the git sha using something similar to what I found here: How to update version number of react native app

Then grabbing it inside react native with react-native-device-info. I'm also pulling the version number 1.0.0 from the package.json. Lastly I wanted to add the jenkins build number to the versionCode of the defaultConfig but I have no way of getting it out with react-native-device-info.

Any help would be much appreciated!

Community
  • 1
  • 1
Robby Kim
  • 454
  • 5
  • 20

1 Answers1

2

I ended up running a script at build time that will cat the version number and etc into a version.json file. Then on runtime, the .js file will import that json file and read it from there. It was the least complicated and cleanest way I thought of and it works well!

Robby Kim
  • 454
  • 5
  • 20