In my opinion the best option is to use react-native-config.
It supports 12 factor.
I found this package extremely useful. You can set multiple environments, e.g. development, staging, production.
In case of Android, variables are available also in Java classes, gradle, AndroidManifest.xml etc.
In case of iOS, variables are available also in Obj-C classes, Info.plist.
You just create files like
.env.development
.env.staging
.env.production
You fill these files with key, values like
API_URL=https://myapi.com
GOOGLE_MAPS_API_KEY=abcdefgh
and then just use it:
import Config from 'react-native-config'
Config.API_URL // 'https://myapi.com'
Config.GOOGLE_MAPS_API_KEY // 'abcdefgh'
If you want to use different environments, you basically set ENVFILE variable like this:
ENVFILE=.env.staging react-native run-android
or for assembling app for production (android in my case):
cd android && ENVFILE=.env.production ./gradlew assembleRelease