53
loading...
This website collects cookies to deliver better user experience
yarn
or npm
.#using yarn
yarn add react-native-code-push
#using npm
npm install react-native-code-push
#only for ios app
cd ios && pod install
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')
codepush.gradle
in android/app/build.gradle
.apply from: "../../node_modules/react-native/react.gradle"
// add this line
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 in order 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();
}
};
}
android\app\src\main\res\values\strings.xml
.<resources>
<string name="app_name">OtaExample</string>
<string moduleConfig="true" name="CodePushDeploymentKey">YOUR_KEY</string>
</resources>
import codePush from 'react-native-code-push';
const App = () => {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={styles.scrollView}>
<View style={styles.body}>
<Text>Test</Text>
</View>
</ScrollView>
</SafeAreaView>
</>
);
};
export default codePush(App);
#using yarn
yarn global add appcenter-cli
#using npm
npm install -g appcenter-cli
#will open a dialog to login into appcenter
appcenter login
#to send update OTA
appcenter codepush release-cordova -a <ownerName>/<appName>
const App = () => {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={styles.scrollView}>
<View style={styles.body}>
<Text>Test</Text>
<Text>Testing OTA updates!</Text>
</View>
</ScrollView>
</SafeAreaView>
</>
);
};
<Text>Testing OTA updates!</Text>
to our app. Now let's push this change using the command above! Then we can launch our app (we won't see the changes first) and wait 10-15 seconds. After relaunching our app, we should see this: