Read app.json (or exp.json) programmatically

Viewed 10995

Is there a way to read the contents of app.json programmatically from within you app, so you could for example get the current version number and show it within an About screen?

6 Answers

For Expo SDK 35, I did this:

expo install expo-constants

in your .js:

import Constants from "expo-constants";

<Text> {Constants.manifest.description} </Text>

For expo SDK 33 use:

 import Constants from "expo-constants";
 {`v${Constants.manifest.version}`}

npm:

npm install expo-constants

OR

expo:

expo install expo-constants

About.js

import Constants from "expo-constants";

<Text>Version {Constants.manifest.version} </Text>

When trying to use this line

import { Constants } from 'expo-constants';

Constants was showing up as undefined when logged to the console.

However, this code worked to display the app's version:

<template>
  <text>version: {{ appVersion }}</text>
</template>

<script>

import * as Constants from 'expo-constants';

export default {
  data() {
    return {
      appVersion: Constants['default']['manifest']['version']
    }
  }
}
</script>
Related