How to get a versionName in react-native app on Android?

I've successfully used the React Native Device Info component to get the build details as specified in the Gradle config.

Once installed you can use:

DeviceInfo.getVersion()

To output the version, and:

DeviceInfo.getBuildNumber()

To get the build number.


If you want the version number in your package.json, you can also do:

var pkg = require('./package.json');
console.log(pkg.version);

import { version } from './package.json';

I couldn't get the package react-native-device-info to work. Ran into this issue Might need some gradle and java changes to make it fly.

Anyhow I got what I needed react-native-version-number. And I am happy with it.

import VersionNumber from 'react-native-version-number';

console.log('appVersion:', VersionNumber.appVersion)

Oh, and as it relates to gleaning the version from package.json. It feels wrong to me. I mean I had to try it just to see if it would work. I didn't realize that resource would be available at runtime on the device. It does work, but I also have some buildTypes debug foo going on in my build.gradle I learned here. So its nice to be getting the versionName like 0.1.7-debug straight from the horses mouth.