Installation & Configuration
Set up AppsOnAir CodePush in your React Native app, including installation, configuration, and integration of the deployment key and server URL.
1. Install CodePush SDK
Run the following command to install react-native-code-push in your React Native project:
Old Architecture
- NPM
- Yarn
Terminal
npm install react-native-code-push
Terminal
yarn add react-native-code-push
New Architecture
- NPM
- Yarn
Terminal
npm install @code-push-next/react-native-code-push
Terminal
yarn add @code-push-next/react-native-code-push
for IOS
Don't forgot to install pods! (for iOS)
2. Configure Android
Update android/settings.gradle
(Only required in Old Architecture)
Add the following lines to include the CodePush module:
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')
Update android/app/build.gradle
Apply the CodePush Gradle script by adding this line:
build.gradle (Old Architecture)
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
build.gradle (New Architecture)
apply from: "../../node_modules/@code-push-next/react-native-code-push/android/codepush.gradle"
Modify MainApplication.java
or MainApplication.kt
Find your MainApplication
file and update it as follows:
- Java
- Kotlin
MainApplication.java
// 1. Import the CodePush package.
import com.microsoft.codepush.react.CodePush;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
// 2. Override getJSBundleFile() to let CodePush handle the bundle location.
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
};
}
MainApplication.kt
// 1. Import the CodePush package.
import com.microsoft.codepush.react.CodePush
class MainApplication : Application(), ReactApplication {
private val mReactNativeHost: ReactNativeHost = object : ReactNativeHost(this) {
// 2. Override getJSBundleFile() to let CodePush handle the bundle location.
override fun getJSBundleFile(): String {
return CodePush.getJSBundleFile()
}
}
}
Update android/app/src/main/res/values/strings.xml
Add your Deployment Key and CodePush Server URL inside <resources>
:
strings.xml
<resources>
<string name="app_name">MyApp</string>
<string name="CodePushDeploymentKey">DEPLOYMENT_KEY</string>
<string name="CodePushServerUrl">CODE_PUSH_SERVER_URL</string>
</resources>
3. Configure iOS
Modify AppDelegate.mm
Import CodePush at the top, then modify sourceURLForBridge
to use CodePush in release mode:
- Objective-C
- Swift
AppDelegate.mm
// 1. Import the CodePush package.
#import <CodePush/CodePush.h>
// 2. Override sourceURLForBridge() to let CodePush handle the bundle location.
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [CodePush bundleURL];
#endif
}
AppDelegate.swift
// 1. Import the CodePush package.
import CodePush
// 2. Override sourceURLForBridge() to let CodePush handle the bundle location.
override func sourceURL(for bridge: RCTBridge) -> URL? {
self.bundleURL()
}
override func bundleURL() -> URL? {
#if DEBUG
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
#else
return CodePush.bundleURL()
#endif
}
Modify ios/MyApp/Info.plist
Add your Deployment Key and CodePush Server URL inside the <dict>
block:
Info.plist
<key>CodePushDeploymentKey</key>
<string>DEPLOYMENT_KEY</string>
<key>CodePushServerUrl</key>
<string>CODE_PUSH_SERVER_URL</string>