Programming/React Native

[ReactNative] CodePush 셋팅

통통만두 2021. 8. 3. 10:21
반응형

2021.07.20 - [Programming/React Native] - [ReactNative] Code push를 위한 App center 연동

appcenter login

➜  marsland git:(master) ✗ appcenter login
Opening your browser... 
? Visit https://appcenter.ms/cli-login?hostname=marsland-ui-MacBookPro.local and enter the code:
? Access code from browser:  ${token}
Logged in as marsland

appcenter login 명령어를 입력하면 브라우저 새로운 탭으로 아래와 같이 하나 열린다. 그 화면에 보이는 token을 복사해서 terminal에 붙여넣으면 된다.

appcenter app list

➜  marsland git:(master) ✗ appcenter apps list
  marsland/myapp-android
  marsland/myapp-ios

플러그인 설치

android/settings.gradle

include ':app', ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')

android/app/build.gradle

...
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
...

MainApplication.java

...
// 1. Import the plugin class.
import com.microsoft.codepush.react.CodePush;
public class MainApplication extends Application implements ReactApplication {
    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        ...
        // 2. Override the getJSBundleFile method to let
        // the CodePush runtime determine where to get the JS
        // bundle location from on each app start
        @Override
        protected String getJSBundleFile() {
            return CodePush.getJSBundleFile();
        }
    };
}

strings.xml

appcenter codepush deployment list -a <ownerName>/<appName> -k

strings.xml

<string moduleConfig="true" name="CodePushDeploymentKey">${Deployment Key}</string>

app.js

import codePush from 'react-native-code-push';

const codePushOptions = {
    checkFrequency: codePush.CheckFrequency.ON_APP_RESUME
}

export default codePush(codePushOptions)(App);
반응형