Skip to content

Commit e4195ce

Browse files
authored
Add compatibility with react-native v0.62 (#1829)
1 parent 65ff8d0 commit e4195ce

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

Examples/create-app.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Requirements:
1010
Usage: node create-app.js <appName> <reactNativeVersion> <reactNativeCodePushVersion>
1111
1. node create-app.js
1212
2. node create-app.js myapp
13-
3. node create-app.js myapp react-native@0.61.5 react-native-code-push@6.0.0
13+
3. node create-app.js myapp react-native@0.62 react-native-code-push@6.1.0
1414
4. node create-app.js myapp react-native@latest Microsoft/react-native-code-push
1515
1616
Parameters:
@@ -225,6 +225,7 @@ function isReactNativeVersionLowerThan(version) {
225225
// Configuring android applications for react-native version higher than 0.60
226226
function androidSetup() {
227227
const buildGradlePath = path.join('android', 'app', 'build.gradle');
228+
const settingsGradlePath = path.join('android', 'settings.gradle');
228229
const mainApplicationPath = path.join('android', 'app', 'src', 'main', 'java', 'com', appName, 'MainApplication.java');
229230
const stringsResourcesPath = path.join('android', 'app', 'src', 'main', 'res', 'values', 'strings.xml');
230231

@@ -241,6 +242,13 @@ function androidSetup() {
241242
`${reactGradleLink}${codePushGradleLink}`);
242243
fs.writeFileSync(buildGradlePath, buildGradleContents);
243244

245+
let settingsGradleContents = fs.readFileSync(settingsGradlePath, "utf8");
246+
const settingsGradleInclude = "include \':app\'";
247+
const codePushProjectImport= `':react-native-code-push'\nproject(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')`;
248+
settingsGradleContents = settingsGradleContents.replace(settingsGradleInclude,
249+
`${settingsGradleInclude}, ${codePushProjectImport}`);
250+
fs.writeFileSync(settingsGradlePath, settingsGradleContents);
251+
244252
const getJSBundleFileOverride = `
245253
@Override
246254
protected String getJSBundleFile(){

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.File;
2121
import java.util.ArrayList;
2222
import java.util.List;
23+
import java.lang.reflect.Method;
2324

2425
public class CodePush implements ReactPackage {
2526

@@ -145,20 +146,31 @@ private String getCustomPropertyFromStringsIfExist(String propertyName) {
145146
return null;
146147
}
147148

148-
public void clearDebugCacheIfNeeded(ReactInstanceManager instanceManager) {
149-
boolean isLiveReloadEnabled = false;
150-
149+
private boolean isLiveReloadEnabled(ReactInstanceManager instanceManager) {
151150
// Use instanceManager for checking if we use LiveReload mode. In this case we should not remove ReactNativeDevBundle.js file
152151
// because we get error with trying to get this after reloading. Issue: https://github.com/Microsoft/react-native-code-push/issues/1272
153152
if (instanceManager != null) {
154153
DevSupportManager devSupportManager = instanceManager.getDevSupportManager();
155154
if (devSupportManager != null) {
156155
DevInternalSettings devInternalSettings = (DevInternalSettings)devSupportManager.getDevSettings();
157-
isLiveReloadEnabled = devInternalSettings.isReloadOnJSChangeEnabled();
156+
Method[] methods = devInternalSettings.getClass().getMethods();
157+
for (Method m : methods) {
158+
if (m.getName().equals("isReloadOnJSChangeEnabled")) {
159+
try {
160+
return (boolean) m.invoke(devInternalSettings);
161+
} catch (Exception x) {
162+
return false;
163+
}
164+
}
165+
}
158166
}
159167
}
160168

161-
if (mIsDebugMode && mSettingsManager.isPendingUpdate(null) && !isLiveReloadEnabled) {
169+
return false;
170+
}
171+
172+
public void clearDebugCacheIfNeeded(ReactInstanceManager instanceManager) {
173+
if (mIsDebugMode && mSettingsManager.isPendingUpdate(null) && !isLiveReloadEnabled(instanceManager)) {
162174
// This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78
163175
File cachedDevBundle = new File(mContext.getFilesDir(), "ReactNativeDevBundle.js");
164176
if (cachedDevBundle.exists()) {

docs/setup-android.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,23 @@ In order to integrate CodePush into your Android project, please perform the fol
1919

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

22-
1. In your `android/app/build.gradle` file, add the `codepush.gradle` file as an additional build task definition underneath `react.gradle`:
22+
1. In your `android/settings.gradle` file, make the following additions:
23+
24+
```gradle
25+
include ':app', ':react-native-code-push'
26+
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
27+
```
28+
29+
2. In your `android/app/build.gradle` file, add the `codepush.gradle` file as an additional build task definition underneath `react.gradle`:
2330
2431
```gradle
2532
...
2633
apply from: "../../node_modules/react-native/react.gradle"
2734
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
2835
...
2936
```
30-
2. Update the `MainApplication.java` file to use CodePush via the following changes:
37+
38+
3. Update the `MainApplication.java` file to use CodePush via the following changes:
3139
3240
```java
3341
...
@@ -50,7 +58,7 @@ In order to integrate CodePush into your Android project, please perform the fol
5058
}
5159
```
5260
53-
3. Add the Deployment key to `strings.xml`:
61+
4. Add the Deployment key to `strings.xml`:
5462
5563
To let the CodePush runtime know which deployment it should query for updates, open your app's `strings.xml` file and add a new string named `CodePushDeploymentKey`, whose value is the key of the deployment you want to configure this app against (like the key for the `Staging` deployment for the `FooBar` app). You can retrieve this value by running `code-push deployment ls <appName> -k` in the CodePush CLI (the `-k` flag is necessary since keys aren't displayed by default) and copying the value of the `Deployment Key` column 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.
5664

test/test.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ class RNAndroid extends Platform.Android implements RNPlatform {
8787
"apply from: \"../../node_modules/react-native/react.gradle\"",
8888
"apply from: \"../../node_modules/react-native/react.gradle\"\napply from: \"" + gradleContent + "\"");
8989

90+
// Add CodePush to android/settings.gradle
91+
const settingsGradle = path.join(innerprojectDirectory, "android", "settings.gradle");
92+
TestUtil.replaceString(settingsGradle,
93+
"include ':app'",
94+
"include ':app', ':react-native-code-push'\nproject(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')");
95+
9096
//// Set the app version to 1.0.0 instead of 1.0
9197
// Set the app version to 1.0.0 in android/app/build.gradle
9298
TestUtil.replaceString(buildGradle, "versionName \"1.0\"", "versionName \"1.0.0\"");
@@ -227,7 +233,7 @@ class RNIOS extends Platform.IOS implements RNPlatform {
227233
const hashWithParen = targetEmulator.match(hashRegEx)[0];
228234
const hash = hashWithParen.substr(1, hashWithParen.length - 2);
229235
return TestUtil.getProcessOutput("xcodebuild -workspace " + path.join(iOSProject, TestConfig.TestAppName) + ".xcworkspace -scheme " + TestConfig.TestAppName +
230-
" -configuration Release -destination \"platform=iOS Simulator,id=" + hash + "\" -derivedDataPath build", { cwd: iOSProject, maxBuffer: 1024 * 1000 * 10, noLogStdOut: true });
236+
" -configuration Release -destination \"platform=iOS Simulator,id=" + hash + "\" -derivedDataPath build", { cwd: iOSProject, maxBuffer: 1024 * 1024 * 20, noLogStdOut: true });
231237
})
232238
.then<void>(
233239
() => { return null; },

0 commit comments

Comments
 (0)