react-native-config 설치 및 사용법

Hong·2022년 4월 6일
0
post-custom-banner

설치하기

$ yarn add react-native-config

세팅하기

$ react-native link react-native-config
(cd ios; pod install)

IOS

  1. Xcode에서 project's name -> Libraries -> Add Files to [your project's name] -> ReactNativeConfig.xcodeproj 추가

    ReactNativeConfig.xcodeproj 경로: 프로젝트 -> node_modules -> react-native-config -> ios

  2. Build Phases -> Link Binary With Libraries -> libReactNativeConfig.a 추가(+버튼 클릭)

  3. Build Setting -> Header Search Paths -> $(SRCROOT)/../node_modules/react-native-config/ios/** (non-recursive)

Android

android/settings.gradle

+ include ':react-native-config'
+ project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')

android/app/build.gradle

dependencies {
	implementation "com.facebook.react:react-native:+"  // From node_modules
+	implementation project(':react-native-config')
}

MainApplication.java

+ import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;

@Override
protected List<ReactPackage> getPackages() {
	   return Arrays.asList(
       		new MainReactPackage()
+      		new ReactNativeConfigPackage()
    );
}

사용방법

.env

API_URL=https://myapi.com
GOOGLE_MAPS_API_KEY=abcdefgh

index.js

import Config from "react-native-config";

Config.API_URL; // 'https://myapi.com'
Config.GOOGLE_MAPS_API_KEY; // 'abcdefgh'
profile
코딩 배우기
post-custom-banner

0개의 댓글