A React Native app is composed of JavaScript files and any accompanying images, which are bundled together by the packager and distributed as part of a platform-specific binary (i.e. an .ipa or .apk file). Once the app is released, updating either the JavaScript code (e.g. making bug fixes, adding new features) or image assets, requires you to recompile and redistribute the entire binary, which of course, includes any review time associated with the store(s) you are publishing to.
CodePush allows to rebuild and push only the modified JS code.
Pros:
Faster builds
Easier to update: no need to download the whole app again on HockeyApp
See deployment history and statistics
Easy rollbacks
If you enable it in production, you can install updates silently and automatically
Cons:
You rely on Microsoft Azure's servers
Here's an example, where we enabled it on staging in order to speed up development (at the bottom of the screen).
Steps
1. Install the AppCenter cli (~1 min)
CHECK
appcenter -v should give you a version.
2. Login into AppCenter (~4 min)
Login with your GitHub or Google account:
CHECK
You should see your profile info with appcenter profile list.
3. Configure CodePush on AppCenter's servers (~5 min)
CHECK
Check: you have written down the deployment keys in a temporary file.
react-native link command adds a pod in your Podfile.
If you don't already have React in your Podfile, it is recommended to remove the added line, commit, and follow the Microsoft tutorial here, paragraph Plugin Installation (iOS - Manual).
If you already have React in your Podfile, make sure to bundle exec pod install in order to update Podfile.lock
CHECK
Check: your app builds on both Android and iOS, in debug and release mode.
5. Update your code (~35 min)
Update App.js (~10 min)
CHECK
Check: Manually set "ENV" to staging and check the logs on iOS and Android. You shouldn't see any warning for CodePush.
Add CodePushUpdateButton.js (~5 min)
You can put the update process on any page you like, or even check if an update is available with a long press somewhere... It is up to you and your PO.
Add this CodePushUpdateButton somewhere in your app.
CHECK
On the simulator, you should see an update button if you force the env to staging.
yarn global add appcenter-cli
# or npm install -g appcenter-cli
appcenter login
# Create the apps
# You can also do it via https://appcenter.ms
appcenter apps create -d <MyApp>-Android -o Android -p React-Native
appcenter apps create -d <MyApp>-iOS -o iOS -p React-Native
# Invite your team members to the apps
open https://appcenter.ms/users/<owner>/apps/<MyApp>-Android/settings/collaborators
open https://appcenter.ms/users/<owner>/apps/<MyApp>-iOS/settings/collaborators
# Configure the CodePush Staging deployment
appcenter codepush deployment add -a <owner>/<MyApp>-Android Staging
appcenter codepush deployment add -a <owner>/<MyApp>-iOS Staging
# Save the Staging tokens for later use
appcenter codepush deployment list -a <owner>/<MyApp>-Android
appcenter codepush deployment list -a <owner>/<MyApp>-iOS
# Add the npm dependency
yarn add react-native-code-push@<your.version>
# Link the native modules. Paste your Staging tokens when prompted.
react-native link react-native-code-push