Configuring your app for CodePush
Install the CodePush SDK and add the deployment keys and the CodePush Server URL to the app configuration. The process is different for React Native and Expo apps.
The CodePush SDK is an open-source SDK. Bitrise actively participates in its maintenance to make sure it serves our customers' needs.
Configuring CodePush for React Native appsClick to copy link
CodePush for React Native requires installing the SDK and then setting up CodePush for both the iOS and the Android modules.
-
Install the React Native CodePush :
npm install @code-push-next/react-native-code-push -
Set up CodePush for iOS. You can find the most important instructions here: see topic.
Read more in the GitHub repository of the SDK: iOS.
-
Set up CodePush for Android. You can find the most important instructions here: see topic.
Read more in the GitHub repository of the SDK: Android.
iOS setupClick to copy link
-
Make sure the bundle identifier matches the bundle identifier you used when creating the app on Bitrise. You can use
react-native-renameto rename your app with a custom bundle identifier: react-native-rename. -
In
ios/Podfile, look for the lineplatform :ios,min_ios_version_supported. Change it toplatform :ios, 15.5. -
Update
ios/<projectname>/AppDelegate.swift:-
Add an import statement for CodePush headers:
import CodePush -
Find the following line of code:
Bundle.main.url(forResource: "main", withExtension: "jsbundle") -
Replace it with this line:
CodePush.bundleURL() -
Your
bundleURLmethod should look like this:override func bundleURL() -> URL? {#if DEBUGRCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")#elseCodePush.bundleURL()#endif}
-
-
Add the CodePush deployment key and the CodePush Server URL to
ios/<projectname>/Info.plist:You get the deployment key when creating the CodePush deployment on Bitrise.
Workspace slugThe server URL requires the Bitrise workspace slug: Identifying Workspaces and apps with their slugs.
#The CodePush deployment key<key>CodePushDeploymentKey</key><string></string>#The CodePush server URL with the Bitrise workspace slug<key>CodePushServerURL</key><string>https://<workspace-slug>.codepush.bitrise.io</string>
Android setupClick to copy link
-
Add a line at the end of
android/app/build.gradleas an additional build task definition:...apply from: "../../node_modules/@code-push-next/react-native-code-push/android/codepush.gradle"... -
Update
android/app/build.gradle android.defaultConfigto setupversionCodeandversionName:versionCode System.getenv("APP_VERSION_CODE") != null ? System.getenv("APP_VERSION_CODE").toInteger() : 1versionName System.getenv("APP_VERSION_NAME") != null ? System.getenv("APP_VERSION_NAME") : "1.0" -
Update
android/app/src/main/java/…/MainApplication.ktto use CodePush:PackageListPackageList must be instantiated only once in the application's lifetime.
...// 1. Import the plugin class.import com.microsoft.codepush.react.CodePushclass MainApplication : Application(), ReactApplication {override val reactNativeHost: ReactNativeHost =object : DefaultReactNativeHost(this) {override fun getPackages(): List<ReactPackage> = PackageList(this).packages.apply {// Packages that cannot be autolinked yet can be added manually here, for example:// add(MyReactNativePackage())}// 2. Override the getJSBundleFile method in order to let// the CodePush runtime determine where to get the JS// bundle location from on each app startoverride fun getJSBundleFile(): String {return CodePush.getJSBundleFile()}};} -
In
android/app/src/main/res/value/strings.xml, add the CodePush deployment key and the CodePush Server URL.You get the deployment key when creating the CodePush deployment on Bitrise.
Workspace slugThe server URL requires the Bitrise workspace slug: Identifying Workspaces and apps with their slugs.
<string name="CodePushDeploymentKey" translatable="false"><CODE_PUSH_DEPLOYMENT_KEY></string><string name="CodePushServerUrl" translatable="false">https://<workspace-slug>.codepush.bitrise.io</string>
Configuring CodePush for Expo appsClick to copy link
-
Convert
app.jsontoapp.config.jsso that you can use environment variables.For more information, check out the Expo docs on dynamic configuration.
-
Set your
apps ios.bundleIdentifierandandroid.packageinapp.config.js. These should match the values used while creating the apps on Bitrise. -
Install the React Native CodePushNext SDK,
dotenv, andexpo-build-propertiespackages:npm install @code-push-next/react-native-code-push dotenv expo-build-properties -
Setup Expo CodePush Plugin:
-
Include the plugin in
app.config.js.Workspace slugThe server URL requires the Bitrise workspace slug: Identifying Workspaces and apps with their slugs.
plugins: [["@code-push-next/react-native-code-push/expo", // CodePush plugin{ios: {// Use the environment variable for the iOS CodePush Deployment KeyCodePushDeploymentKey: IOS_CODE_PUSH_DEPLOYMENT_KEY,CodePushServerURL: "https://<workspace-slug>.codepush.bitrise.io"},android: {// Use the environment variable for the Android CodePush Deployment KeyCodePushDeploymentKey: ANDROID_CODE_PUSH_DEPLOYMENT_KEY,CodePushServerURL: "https://<workspace-slug>.codepush.bitrise.io"}}],["expo-build-properties",{ios: {deploymentTarget: "15.5"}}]// Add other plugins here if you have more]
-
-
Add the deployment key values to an
.envfile. You get the deployment keys when creating the CodePush deployment on Bitrise.tipAdd the
.envfile to your.gitignoreto keep your keys secret!# .env file# CodePush Deployment KeysIOS_CODE_PUSH_DEPLOYMENT_KEY=""ANDROID_CODE_PUSH_DEPLOYMENT_KEY=""