Skip to content

Commit ccfb0e3

Browse files
andreidubovLakshminarasimhan ks
authored andcommitted
Add compatibility with react-native v0.62 (microsoft#1829)
1 parent 50b93e9 commit ccfb0e3

File tree

2 files changed

+114
-104
lines changed

2 files changed

+114
-104
lines changed

docs/setup-android.md

Lines changed: 108 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
11
## Android Setup
22

3-
* [Plugin Installation and Configuration for React Native 0.60 version and above](#plugin-installation-and-configuration-for-react-native-060-version-and-above-android)
4-
* [Plugin Installation for React Native lower than 0.60 (Android)](#plugin-installation-for-react-native-lower-than-060-android)
5-
* [Plugin Installation (Android - RNPM)](#plugin-installation-android---rnpm)
6-
* [Plugin Installation (Android - Manual)](#plugin-installation-android---manual)
7-
* [Plugin Configuration for React Native lower than 0.60 (Android)](#plugin-configuration-for-react-native-lower-than-060-android)
8-
* [For React Native v0.29 - v0.59](#for-react-native-v029---v059)
9-
* [For newly created React Native application](#for-newly-created-react-native-application)
10-
* [For existing native application](#for-existing-native-application)
11-
* [For React Native v0.19 - v0.28](#for-react-native-v019---v028)
12-
* [Background React Instances](#background-react-instances)
13-
* [For React Native >= v0.29 (Background React Instances)](#for-react-native--v029-background-react-instances)
14-
* [For React Native v0.19 - v0.28 (Background React Instances)](#for-react-native-v019---v028-background-react-instances)
15-
* [WIX React Native Navigation applications (ver 1.x)](#wix-react-native-navigation-applications)
16-
* [Code Signing setup](#code-signing-setup)
3+
- [Plugin Installation and Configuration for React Native 0.60 version and above](#plugin-installation-and-configuration-for-react-native-060-version-and-above-android)
4+
- [Plugin Installation for React Native lower than 0.60 (Android)](#plugin-installation-for-react-native-lower-than-060-android)
5+
- [Plugin Installation (Android - RNPM)](#plugin-installation-android---rnpm)
6+
- [Plugin Installation (Android - Manual)](#plugin-installation-android---manual)
7+
- [Plugin Configuration for React Native lower than 0.60 (Android)](#plugin-configuration-for-react-native-lower-than-060-android)
8+
- [For React Native v0.29 - v0.59](#for-react-native-v029---v059)
9+
- [For newly created React Native application](#for-newly-created-react-native-application)
10+
- [For existing native application](#for-existing-native-application)
11+
- [For React Native v0.19 - v0.28](#for-react-native-v019---v028)
12+
- [Background React Instances](#background-react-instances)
13+
- [For React Native >= v0.29 (Background React Instances)](#for-react-native--v029-background-react-instances)
14+
- [For React Native v0.19 - v0.28 (Background React Instances)](#for-react-native-v019---v028-background-react-instances)
15+
- [WIX React Native Navigation applications (ver 1.x)](#wix-react-native-navigation-applications)
16+
- [Code Signing setup](#code-signing-setup)
1717

1818
In order to integrate CodePush into your Android project, please perform the following steps:
1919

2020
### Plugin Installation and Configuration for React Native 0.60 version and above (Android)
2121

2222
1. In your `android/settings.gradle` file, make the following additions at the end of the file:
2323

24-
```gradle
25-
...
26-
include ':app', ':react-native-code-push'
27-
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
28-
```
29-
24+
```gradle
25+
...
26+
include ':app', ':react-native-code-push'
27+
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
28+
```
29+
3030
2. In your `android/app/build.gradle` file, add the `codepush.gradle` file as an additional build task definition to the end of the file:
3131

32-
```gradle
33-
...
34-
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
35-
...
36-
```
32+
```gradle
33+
...
34+
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
35+
...
36+
```
3737

3838
3. Update the `MainApplication` file to use CodePush via the following changes:
3939

40-
For React Native 0.73 and above: update the `MainApplication.kt`
40+
For React Native 0.73 and above: update the `MainApplication.kt`
4141

42-
```kotlin
43-
...
44-
// 1. Import the plugin class.
45-
import com.microsoft.codepush.react.CodePush
42+
```kotlin
43+
...
44+
// 1. Import the plugin class.
45+
import com.microsoft.codepush.react.CodePush
4646

47-
class MainApplication : Application(), ReactApplication {
47+
class MainApplication : Application(), ReactApplication {
4848

49-
override val reactNativeHost: ReactNativeHost =
50-
object : DefaultReactNativeHost(this) {
51-
...
49+
override val reactNativeHost: ReactNativeHost =
50+
object : DefaultReactNativeHost(this) {
51+
...
5252

53-
// 2. Override the getJSBundleFile method in order to let
54-
// the CodePush runtime determine where to get the JS
55-
// bundle location from on each app start
56-
override fun getJSBundleFile(): String {
57-
return CodePush.getJSBundleFile()
58-
}
59-
};
60-
}
61-
```
53+
// 2. Override the getJSBundleFile method in order to let
54+
// the CodePush runtime determine where to get the JS
55+
// bundle location from on each app start
56+
override fun getJSBundleFile(): String {
57+
return CodePush.getJSBundleFile()
58+
}
59+
};
60+
}
61+
```
6262

63-
For React Native 0.72 and below: update the `MainApplication.java`
63+
For React Native 0.72 and below: update the `MainApplication.java`
6464

65-
```java
66-
...
67-
// 1. Import the plugin class.
68-
import com.microsoft.codepush.react.CodePush;
65+
```java
66+
...
67+
// 1. Import the plugin class.
68+
import com.microsoft.codepush.react.CodePush;
6969

70-
public class MainApplication extends Application implements ReactApplication {
70+
public class MainApplication extends Application implements ReactApplication {
7171

72-
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
73-
...
72+
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
73+
...
7474

75-
// 2. Override the getJSBundleFile method in order to let
76-
// the CodePush runtime determine where to get the JS
77-
// bundle location from on each app start
78-
@Override
79-
protected String getJSBundleFile() {
80-
return CodePush.getJSBundleFile();
81-
}
82-
};
83-
}
84-
```
75+
// 2. Override the getJSBundleFile method in order to let
76+
// the CodePush runtime determine where to get the JS
77+
// bundle location from on each app start
78+
@Override
79+
protected String getJSBundleFile() {
80+
return CodePush.getJSBundleFile();
81+
}
82+
};
83+
}
84+
```
8585

8686
4. Add the Deployment key to `strings.xml`:
8787

@@ -98,9 +98,9 @@ In order to integrate CodePush into your Android project, please perform the fol
9898
<string name="app_name">AppName</string>
9999
<string moduleConfig="true" name="CodePushDeploymentKey">DeploymentKey</string>
100100
</resources>
101-
```
101+
```
102102

103-
*Note: If you need to dynamically use a different deployment, you can also override your deployment key in JS code using [Code-Push options](./api-js.md#CodePushOptions)*
103+
_Note: If you need to dynamically use a different deployment, you can also override your deployment key in JS code using [Code-Push options](./api-js.md#CodePushOptions)_
104104

105105
### Plugin Installation for React Native lower than 0.60 (Android)
106106

@@ -110,21 +110,23 @@ In order to accommodate as many developer preferences as possible, the CodePush
110110

111111
2. [**"Manual"**](#plugin-installation-android---manual) - If you don't want to depend on any additional tools or are fine with a few extra installation steps (it's a one-time thing), then go with this approach.
112112

113-
*Note: Due to a code change from the React Native repository, if your installed React Native version ranges from 0.29 to 0.32, we recommend following the manual steps to set up correctly. *
113+
_Note: Due to a code change from the React Native repository, if your installed React Native version ranges from 0.29 to 0.32, we recommend following the manual steps to set up correctly. _
114114

115115
#### Plugin Installation (Android - RNPM)
116116

117117
1. As of v0.27 of React Native, `rnpm link` has already been merged into the React Native CLI. Simply run:
118-
```
119-
react-native link react-native-code-push
120-
```
121118

122-
If your app uses a version of React Native that is lower than v0.27, run the following:
123-
```
124-
rnpm link react-native-code-push
125-
```
119+
```
120+
react-native link react-native-code-push
121+
```
122+
123+
If your app uses a version of React Native that is lower than v0.27, run the following:
126124

127-
*Note: If you don't already have RNPM installed, you can do so by simply running `npm i -g rnpm` and then executing the above command.*
125+
```
126+
rnpm link react-native-code-push
127+
```
128+
129+
_Note: If you don't already have RNPM installed, you can do so by simply running `npm i -g rnpm` and then executing the above command._
128130

129131
2. If you're using RNPM >=1.6.0, you will be prompted for the deployment key you'd like to use. If you don't already have it, you can retrieve this value by running `appcenter codepush deployment list -a <ownerName>/<appName> -k`, or you can choose to ignore it (by simply hitting `<ENTER>`) and add it in later. To get started, we would recommend just using your `Staging` deployment key, so that you can test out the CodePush end-to-end.
130132

@@ -134,33 +136,33 @@ And that's it for installation using RNPM! Continue below to the [Plugin Configu
134136

135137
1. In your `android/settings.gradle` file, make the following additions:
136138

137-
```gradle
138-
include ':app', ':react-native-code-push'
139-
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
140-
```
139+
```gradle
140+
include ':app', ':react-native-code-push'
141+
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
142+
```
141143

142144
2. In your `android/app/build.gradle` file, add the `:react-native-code-push` project as a compile-time dependency:
143145

144-
```gradle
145-
...
146-
dependencies {
147-
...
148-
compile project(':react-native-code-push')
149-
}
150-
```
146+
```gradle
147+
...
148+
dependencies {
149+
...
150+
compile project(':react-native-code-push')
151+
}
152+
```
151153

152154
3. In your `android/app/build.gradle` file, add the `codepush.gradle` file as an additional build task definition underneath `react.gradle`:
153155

154-
```gradle
155-
...
156-
apply from: "../../node_modules/react-native/react.gradle"
157-
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
158-
...
159-
```
156+
```gradle
157+
...
158+
apply from: "../../node_modules/react-native/react.gradle"
159+
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
160+
...
161+
```
160162

161163
### Plugin Configuration for React Native lower than 0.60 (Android)
162164

163-
*NOTE: If you used RNPM or `react-native link` to automatically link the plugin, these steps have already been done for you so you may skip this section.*
165+
_NOTE: If you used RNPM or `react-native link` to automatically link the plugin, these steps have already been done for you so you may skip this section._
164166

165167
After installing the plugin and syncing your Android Studio project with Gradle, you need to configure your app to consult CodePush for the location of your JS bundle, since it will "take control" of managing the current and all future versions. To do this:
166168

@@ -203,7 +205,8 @@ public class MainApplication extends Application implements ReactApplication {
203205
}
204206
```
205207

206-
*NOTE: For React Native v0.49+ please be sure that `getJSMainModuleName` function in the `MainApplication.java` file determines correct URL to fetch JS bundle (used when dev support is enabled, see [this](https://github.com/facebook/react-native/blob/c7f37074ac89f7e568ca26a6bad3bdb02812c39f/ReactAndroid/src/main/java/com/facebook/react/ReactNativeHost.java#L124) for more details) e.g.*
208+
_NOTE: For React Native v0.49+ please be sure that `getJSMainModuleName` function in the `MainApplication.java` file determines correct URL to fetch JS bundle (used when dev support is enabled, see [this](https://github.com/facebook/react-native/blob/c7f37074ac89f7e568ca26a6bad3bdb02812c39f/ReactAndroid/src/main/java/com/facebook/react/ReactNativeHost.java#L124) for more details) e.g._
209+
207210
```
208211
@Override
209212
protected String getJSMainModuleName() {
@@ -236,7 +239,7 @@ public class MyReactActivity extends Activity {
236239
// Get the JS Bundle File via Code Push
237240
.setJSBundleFile(CodePush.getJSBundleFile())
238241
// ...
239-
242+
240243
.build();
241244
mReactRootView.startReactApplication(mReactInstanceManager, "MyReactNativeApp", null);
242245

@@ -283,7 +286,7 @@ public class MainActivity extends ReactActivity {
283286

284287
#### Background React Instances
285288

286-
*This section is only necessary if you're <b>explicitly</b> launching a React Native instance without an `Activity` (for example, from within a native push notification receiver). For these situations, CodePush must be told how to find your React Native instance.*
289+
_This section is only necessary if you're <b>explicitly</b> launching a React Native instance without an `Activity` (for example, from within a native push notification receiver). For these situations, CodePush must be told how to find your React Native instance._
287290

288291
In order to update/restart your React Native instance, CodePush must be configured with a `ReactInstanceHolder` before attempting to restart an instance in the background. This is done in your `Application` implementation.
289292

@@ -397,6 +400,7 @@ public class MainApplication extends NavigationApplication implements ReactInsta
397400
}
398401
}
399402
```
403+
400404
If you are using [WIX React Native Navigation **version 2.x**](https://github.com/wix/react-native-navigation/tree/v2) based application, please do the following steps to integrate CodePush:
401405

402406
1. As per React Native Navigation's documentation, `MainActivity.java` should extend `NavigationActivity`, no changes required to incorporate CodePush:
@@ -433,7 +437,7 @@ public class MainApplication extends NavigationApplication {
433437
protected String getJSBundleFile() {
434438
return CodePush.getJSBundleFile();
435439
}
436-
440+
437441
};
438442
return new ReactGateway(this, isDebug(), host);
439443
}
@@ -451,12 +455,12 @@ public class MainApplication extends NavigationApplication {
451455

452456
Starting with CLI version **2.1.0** you can self sign bundles during release and verify its signature before installation of update. For more info about Code Signing please refer to [relevant code-push documentation section](https://github.com/microsoft/code-push/tree/v3.0.1/cli#code-signing). In order to use Public Key for Code Signing you need to do following steps:
453457

454-
Add `CodePushPublicKey` string item to `/path_to_your_app/android/app/src/main/res/values/strings.xml`. It may looks like this:
458+
Add `CodePushPublicKey` string item to `/path_to_your_app/android/app/src/main/res/values/strings.xml`. It may looks like this:
455459

456-
```xml
457-
<resources>
458-
<string name="app_name">my_app</string>
459-
<string name="CodePushPublicKey">-----BEGIN PUBLIC KEY-----
460+
```xml
461+
<resources>
462+
<string name="app_name">my_app</string>
463+
<string name="CodePushPublicKey">-----BEGIN PUBLIC KEY-----
460464
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtPSR9lkGzZ4FR0lxF+ZA
461465
P6jJ8+Xi5L601BPN4QESoRVSrJM08roOCVrs4qoYqYJy3Of2cQWvNBEh8ti3FhHu
462466
tiuLFpNdfzM4DjAw0Ti5hOTfTixqVBXTJPYpSjDh7K6tUvp9MV0l5q/Ps3se1vud
@@ -466,7 +470,7 @@ OTw3sz9ceaci7z2r8SZdsfjyjiDJrq69eWtvKVUpredy9HtyALtNuLjDITahdh8A
466470
zwIDAQAB
467471
-----END PUBLIC KEY-----</string>
468472
</resources>
469-
```
473+
```
470474

471475
#### For React Native <= v0.60 you should configure the `CodePush` instance to use this parameter using one of the following approaches
472476

@@ -482,9 +486,9 @@ new CodePush(
482486

483487
##### Using builder
484488

485-
```java
489+
```java
486490
new CodePushBuilder("deployment-key-here",getApplicationContext())
487-
.setIsDebugMode(BuildConfig.DEBUG)
488-
.setPublicKeyResourceDescriptor(R.string.CodePushPublicKey)
489-
.build()
491+
.setIsDebugMode(BuildConfig.DEBUG)
492+
.setPublicKeyResourceDescriptor(R.string.CodePushPublicKey)
493+
.build()
490494
```

test/test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ class RNAndroid extends Platform.Android implements RNPlatform {
9494
"include ':app'",
9595
"include ':app', ':react-native-code-push'\nproject(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')");
9696

97+
// Add CodePush to android/settings.gradle
98+
const settingsGradle = path.join(innerprojectDirectory, "android", "settings.gradle");
99+
TestUtil.replaceString(settingsGradle,
100+
"include ':app'",
101+
"include ':app', ':react-native-code-push'\nproject(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')");
102+
97103
//// Set the app version to 1.0.0 instead of 1.0
98104
// Set the app version to 1.0.0 in android/app/build.gradle
99105
TestUtil.replaceString(buildGradle, "versionName \"1.0\"", "versionName \"1.0.0\"");

0 commit comments

Comments
 (0)