AppCenter 설정이 끝나면 다중 배포 테스트를 포함한 React Native 클라이언트 SDK 설정을 해주어야 한다. 이 부분은 적용하는데 시간이 조금 걸렸다. 다중 배포 테스트란 코드푸시를 효과적으로 테스트하기 위해 배포 단계를 Staging과 Production으로 활용하여 테스트하는 것을 말한다. 자세한 설명은 설정이 끝난 후에 하도록 하겠다.
npm install --save react-native-code-push
cd ios && pod install && cd ..
#import <CodePush/CodePush.h>
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; // 이 부분을
return [CodePush bundleURL]; // 이 코드로 바꿔준다.
<key>CodePushDeploymentKey</key>
<string>$(CODEPUSH_KEY)</string>
include ':app', ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
import com.microsoft.codepush.react.CodePush;
그리고 new ReactNativeHost(this) 코드를 찾아서 블록({}) 안에 다음 내용을 삽입해준다.
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
<resources>
<string name="app_name">AppName</string>
<string moduleConfig="true" name="CodePushDeploymentKey">DeploymentKey</string>
</resources>
4번 같은 경우 우리는 빌드 배포 자동 동기화를 진행하기 때문에 필요한 작업은 아니지만 빌드 배포 자동 동기화를 진행하지 않는다면 작업해주어야 하는 부분이다.
여기까지는 React Native 클라이언트 SDK 설치를 위한 작업이고 이제 앱을 빌드하거나 실행할 때 빌드와 배포 단계를 자동으로 동기화되도록 구성하는 설정이 필요하다. 쉽게 말하자면 앱의 Staging 빌드가 코드푸시의 Staging 배포와 자동으로 동기화되고 Release 빌드가 Production 배포화 동기화되도록 하는 작업이다. 아직 갈길이 멀다..
# Release
$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
# Staging
$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)
모든 작업이 끝났다면 IOS 설정은 완료되었다!
buildTypes {
debug {
...
// Note: CodePush updates shouldn't be tested in Debug mode as they're overriden by the RN packager. However, because CodePush checks for updates in all modes, we must supply a key.
resValue "string", "CodePushDeploymentKey", '""'
...
}
releaseStaging {
...
resValue "string", "CodePushDeploymentKey", '"<INSERT_STAGING_KEY>"'
// Note: It's a good idea to provide matchingFallbacks for the new buildType you create to prevent build issues
// Add the following line if not already there
matchingFallbacks = ['release']
...
}
release {
...
resValue "string", "CodePushDeploymentKey", '"<INSERT_PRODUCTION_KEY>"'
...
}
}
안드로이드는 상대적으로 IOS 보다 간단한 작업이었다. 이제! 드디어! IOS와 안드로이드 모든 설정이 끝났다. 이제 다중 배포 테스트도 가능하다. 다중 배포 테스트는 Production과 Staging을 활용하여 효과적인 Workflow를 달성하는 것인데 그 워크플로는 다음과 같다.
이렇게 하면 앱 배포를 하기 전에 안전하고 효과적인 테스트가 가능하다.
이제 코드푸시 코드 작업을 진행하면 된다!