This repository was archived by the owner on May 20, 2025. It is now read-only.
Support for React Native AutoLinking #2613
Closed
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Description
This PR aims at reducing native CodePush installation steps:
Plugin Installation and Configuration for React Native 0.60 version and above (Android)
Step 1
android/settings.gradlefile, make the following additions at the end of the file:Step 2
android/app/build.gradlefile, add thecodepush.gradlefile as an additional build task definition to the end of the file:Step 3 [Required]
MainApplication.javafile to use CodePush via the following changes:Step 4
Add the Deployment key to
strings.xml:To let the CodePush runtime know which deployment it should query for updates, open your app's
strings.xmlfile and add a new string namedCodePushDeploymentKey, whose value is the key of the deployment you want to configure this app against (like the key for theStagingdeployment for theFooBarapp). You can retrieve this value by runningappcenter codepush deployment list -a <ownerName>/<appName> -kin the CodePush CLI (the-kflag is necessary since keys aren't displayed by default) and copying the value of theKeycolumn which corresponds to the deployment you want to use (see below). Note that using the deployment's name (like Staging) will not work. The "friendly name" is intended only for authenticated management usage from the CLI, and not for public consumption within your app.In order to effectively make use of the
StagingandProductiondeployments that were created along with your CodePush app, refer to the multi-deployment testing docs below before actually moving your app's usage of CodePush into production.Your
strings.xmlshould looks like this:Step 5 [JS side]
Note: If you need to dynamically use a different deployment, you can also override your deployment key in JS code using Code-Push optionsPlugin Installation and Configuration for React Native 0.60 version and above (iOS)
Step 1 - 4 [Required]
Run
cd ios && pod install && cd ..to install all the necessary CocoaPods dependencies.Open up the
AppDelegate.m`file, and add an import statement for the CodePush headers:Find the following line of code, which sets the source URL for bridge for production releases:
Replace it with this line:
This change configures your app to always load the most recent version of your app's JS bundle. On the first launch, this will correspond to the file that was compiled with the app. However, after an update has been pushed via CodePush, this will return the location of the most recently installed update.
NOTE: The
bundleURLmethod assumes your app's JS bundle is namedmain.jsbundle. If you have configured your app to use a different file name, simply call thebundleURLForResource:method (which assumes you're using the.jsbundleextension) orbundleURLForResource:withExtension:method instead, in order to overwrite that default behaviorTypically, you're only going to want to use CodePush to resolve your JS bundle location within release builds, and therefore, we recommend using the
DEBUGpre-processor macro to dynamically switch between using the packager server and CodePush, depending on whether you are debugging or not. This will make it much simpler to ensure you get the right behavior you want in production, while still being able to use the Chrome Dev Tools, live reload, etc. at debug-time.Your
sourceURLForBridgemethod should look like this:Step 5
Add the Deployment key to
Info.plist:To let the CodePush runtime know which deployment it should query for updates against, open your app's
Info.plistfile and add a new entry namedCodePushDeploymentKey, whose value is the key of the deployment you want to configure this app against (like the key for theStagingdeployment for theFooBarapp). You can retrieve this value by runningappcenter codepush deployment list -a <ownerName>/<appName> -kin the AppCenter CLI (the-kflag is necessary since keys aren't displayed by default) and copying the value of theKeycolumn which corresponds to the deployment you want to use (see below). Note that using the deployment's name (like Staging) will not work. That "friendly name" is intended only for authenticated management usage from the CLI, and not for public consumption within your app.In order to effectively make use of the
StagingandProductiondeployments that were created along with your CodePush app, refer to the multi-deployment testing docs below before actually moving your app's usage of CodePush into production.Step 6 [JS side]
As per the note, we can set CodePush Deployment Keys using codePushOptions from React Native's side.
Note: If you need to dynamically use a different deployment, you can also override your deployment key in JS code using Code-Push optionsChanges Made
mv -f android/app/* android/In
android/build.gradlefile, add thecodepush.gradlefile as an additional build task definition to the end of the file:Resource String for seamless compilation:
Testing
Add
CodePush.getJSBundleFile()and[CodePush bundleURL].