Skip to content

Latest commit

 

History

History
12 lines (11 loc) · 3.08 KB

react-native-config-migration-guide.md

File metadata and controls

12 lines (11 loc) · 3.08 KB

Migration from react-native-config

react-native-config react-native-keys
.env.development

BASE_URL=https://www.example.com
APP_NAME=Example
GOOGLE_API=ABCDEF
BRANCH_API=ABCDEF
PACKAGE_ID=com.example.rnkeys.dev
keys.development.json

{
  "secure": {
    "GOOGLE_API": "ABCD",
    "BRANCH_API": "ABCDEF"
  },
  "public": {
   "APP_NAME": "dev RNKEYS",
    "PACKAGE_ID": "com.example.rnkeys.dev"
  }
}
Android: apply a plugin to your app, from android/app/build.gradle:

apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
Android: apply a plugin to your app, from android/app/build.gradle:

apply from: project(':react-native-keys').projectDir.getPath() + "/RNKeys.gradle"
Android (build.gradle):
project.ext.envConfigFiles = [
debug: ".env.development",
release: ".env.production",
anothercustombuild: ".env",
]
Android (build.gradle):
project.ext.keyFiles = [
debug: "keys.development.json",
release: "keys.staging.json",
release: "keys.json",
]
Android (.Java File):
BuildConfig.GOOGLE_MAPS_API_KEY
BuildConfig.PACKAGE_ID
Android (.Java File):
import static com.reactnativekeysjsi.KeysModule.getSecureFor;

getSecureFor("GOOGLE_MAPS_API_KEY")

BuildConfig.PACKAGE_ID
Android: You can also read them from your Gradle configuration:
defaultConfig {
applicationId project.env.get("APP_ID")
}
Android: You can also read them from your Gradle configuration:
defaultConfig {
applicationId project.keys.get("APP_ID")
}
import Config from "react-native-config";

Config.GOOGLE_MAPS_API_KEY;
Config.PACKAGE_ID;
import Keys from 'react-native-keys';

Keys.secureFor('GOOGLE_MAPS_API_KEY');
Keys.PACKAGE_ID;
IOS
#import "RNCConfig.h"

NSString *googleMapApiKey = [RNCConfig envFor:@"GOOGLE_MAPS_API_KEY"];
NSString *appName = [RNCConfig envFor:@"APP_NAME"];
IOS
#import "Keys.h"

NSString *googleMapApiKey = [Keys secureFor:@"GOOGLE_MAPS_API_KEY"];
NSString *appName = [Keys publicFor:@"APP_NAME"];
IOS

Go to Edit scheme... -> Build -> Pre-actions,
click + and select New Run Script Action

"${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb"
"${SRCROOT}/.." "${SRCROOT}/tmp.xcconfig"
IOS

Go to Edit scheme... -> Build -> Pre-actions,
click + and select New Run Script Action

export KEYSFILE=keys.development.json
"${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"