React Native SDK Setup
This guide covers the supported setup for bare React Native apps using @srcpush/react-native-code-push.
Install the package
npm install --save @srcpush/react-native-code-push
Or:
yarn add @srcpush/react-native-code-push
What the integration includes
A correct bare React Native setup has three parts:
- JavaScript runtime configuration with the CodePush HOC or manual
sync() - Android native wiring in
build.gradle,strings.xml, andMainApplication - iOS native wiring in
Podfile,AppDelegate, andInfo.plist
Do not hardcode real deployment keys in tracked files. Commit placeholders and inject real values through CI or local environment-specific tooling.
JavaScript runtime
Wrap your root component with the SrcPush HOC:
import codePush from "@srcpush/react-native-code-push";
const codePushOptions = {
checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
installMode: codePush.InstallMode.ON_NEXT_RESTART,
mandatoryInstallMode: codePush.InstallMode.IMMEDIATE,
updateDialog: false,
};
function App() {
return null;
}
export default codePush(codePushOptions)(App);
If your app needs a custom modal, progress bar, or a user-controlled update flow, use codePush.checkForUpdate() and codePush.sync() manually instead of relying only on the default HOC behavior.
Android setup
Touch these files in a bare React Native app:
android/app/build.gradleandroid/app/src/main/res/values/strings.xmlandroid/app/src/main/java/.../MainApplication.(kt|java)
1. Add the Gradle helper
Add this near your other apply from: lines:
apply from: "../../node_modules/@srcpush/react-native-code-push/android/codepush.gradle"
2. Configure deployment placeholders
You can keep CodePushDeploymentKey in either build.gradle or strings.xml, but keep a single source of truth.
Example using build.gradle placeholders:
buildTypes {
debug {
resValue "string", "CodePushDeploymentKey", '"YOUR_ANDROID_STAGING_KEY"'
}
release {
resValue "string", "CodePushDeploymentKey", '"YOUR_ANDROID_PRODUCTION_KEY"'
}
}
Example using strings.xml:
<string name="CodePushDeploymentKey">YOUR_ANDROID_DEPLOYMENT_KEY</string>
<string name="CodePushServerUrl">https://api.srcpush.com</string>
<string name="CodePushPublicKey">YOUR_PUBLIC_KEY</string>
CodePushServerUrl and CodePushPublicKey are optional unless your backend setup requires them.
3. Override getJSBundleFile()
Import CodePush and return the SrcPush bundle from your application host:
import com.microsoft.codepush.react.CodePush
override fun getJSBundleFile(): String {
return CodePush.getJSBundleFile()
}
Preserve the current host pattern used by your React Native version and only add the override where it belongs.
iOS setup
Touch these files in a bare React Native app:
ios/Podfileios/<AppTarget>/AppDelegate.mmorAppDelegate.mios/<AppTarget>/Info.plist
1. Add the pod
pod 'CodePush', :path => '../node_modules/@srcpush/react-native-code-push'
Then run:
cd ios && pod install
2. Return the SrcPush bundle in release builds
In AppDelegate, import the header and keep React Native's default dev bundle while switching release builds to CodePush:
#import <CodePush/CodePush.h>
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [CodePush bundleURL];
#endif
}
If your app already customizes sourceURLForBridge, preserve the existing behavior and only replace the release bundle location.
3. Add placeholders to Info.plist
<key>CodePushDeploymentKey</key>
<string>YOUR_IOS_DEPLOYMENT_KEY</string>
<key>CodePushServerURL</key>
<string>https://api.srcpush.com</string>
<key>CodePushPublicKey</key>
<string>YOUR_PUBLIC_KEY</string>
CodePushServerURL and CodePushPublicKey are optional. Do not add ATS exceptions unless your deployment endpoint actually requires them.
Releasing safely
Prefer explicit platform and environment scripts such as:
srcpush:android:stagingsrcpush:android:prodsrcpush:ios:stagingsrcpush:ios:prod
Keep access keys, signing keys, and real deployment keys out of git. If tracked native files contain placeholders, inject real values in CI before releasing.