apple m1 react-native 셋업

버들비·2021년 12월 1일
0

dev, stag, prod 환경변수 설정

https://velog.io/@heumheum2/React-Native-Multiple-Environments

android

/android/app/build.gradle 에 아래 내용을 추가 (이름 바꾸지 말고 그대로 쓰자)

project.ext.envConfigFiles = [
   productiondebug: ".env.production",
   productionrelease: ".env.production",
   developmentrelease: ".env.development",
   developmentdebug: ".env.development",
   stagingrelease: ".env.staging",
   stagingdebug: ".env.staging"
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

또한 buildTypes {debug{}} 안에 matchingFallbacks = ['debug', 'release'] 를 추가

 debug {
            signingConfig signingConfigs.debug
            matchingFallbacks = ['debug', 'release']
            if (nativeArchitectures) {
                ndk {
                    abiFilters nativeArchitectures.split(',')
                }
            }
        }

buildTypes 바로 아래에

flavorDimensions "default"
  productFlavors {
    production {}
    staging {
      // 여기서 빌드별 구성을 할 수 있습니다.
    }
    development {}
  }

그리고 package.json 에 스크립트를 추가해주자

    "and-stag": "react-native run-android --variant=stagingdebug",
    "and-stag-release": "react-native run-android --variant=stagingrelease",
    "and-dev": "react-native run-android --variant=developmentdebug",
    "and-dev-release": "react-native run-android --variant=developmentrelease",
    "and-prod": "react-native run-android --variant=productiondebug",
    "and-prod-release": "react-native run-android --variant=productionrelease",

ios

cp "${PROJECT_DIR}/../.env.development" "${PROJECT_DIR}/../.env"
echo ".env.development" > /tmp/envfile

처음에는 cp 명령어를 이용해 .env.development를 .env로 복사했지만 문제가 development의 환경 값을 계속 가지고 있는 이슈가 있었다.

/tmp/envfile에 환경 값을 지정해버리는 방식으로 문제를 해결했다.

android 실물 기기로 테스트

npx react-native start 를 통해 metro 서버를 실행시키고 안드로이드 스튜디오에서 빌드한후 adb reverse tcp:8081 tcp:8081 를 터미널에 입력

0개의 댓글