728x90
반응형
디버그 / 릴리즈 모드에 따른 api를 __DEV__ 로 분리하곤 했는데,
이번에 회사에서 요구한 샘플앱에는 env 파일로 적용했다.
먼저
yarn add react-native-config
로 react-native-config 세팅을 해준다.
docs에 나온것 처럼
project/android/app/build.gradle
에
project.ext.envConfigFiles = [
debug: ".env.debug",
release: ".env",
anothercustombuild: ".env.staging",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" // 추가
defaultConfig {
resValue "string", "build_config_package", "AndroidManifest파일 packageName입력" // 추가
...
}
등을 추가해준다.
해당 파일을 설치해주고,
파일별로
BASE_URL="base url";
을 추가해준뒤
import Config from 'react-native-config';
console.log('Config.BASE_URL ::::::' + Config.BASE_URL);
로
yarn android
react-native run-android --variant=release
로 dev일때, release일때 확인해보면 된다.
728x90
반응형
'ReactNative' 카테고리의 다른 글
[ React Native ] react-native-config ios 세팅하기 (0) | 2023.06.19 |
---|---|
[ React Native ] yarn ios 빌드중 Debug-iphoneos/YogaKit/YogaKit.modulemap not found 에러 (0) | 2023.06.16 |
[ React Native ] VScode cannot use JSX unless the '--jsx' flag is provided (0) | 2023.06.04 |
[ React Native ] Mobx로 상태 관리하기 (1) | 2023.06.03 |
[ React Native ] typescript template 으로 프로젝트 만들기 (0) | 2023.05.30 |