Skip to content

Commit cdca0be

Browse files
committed
Support RN 0.71.0 (Closes microsoft#2418)
React native now uses react-native-gradle-plugin, which works a bit differently.
1 parent 6b1a599 commit cdca0be

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ We try our best to maintain backwards compatibility of our plugin with previous
7575
| v0.59 | v5.6+ *(RN refactored js bundle loader code)* |
7676
| v0.60-v0.61 | v6.0+ *(RN migrated to Autolinking)* |
7777
| v0.62-v0.64 | v6.2+ *(RN removed LiveReload)* |
78-
| v0.65-v0.69 | v7.2+ *(RN updated iPhone-target-version)* |
78+
| v0.65-v0.70 | v7.0+ *(RN updated iPhone-target-version)* |
79+
| v0.71 | v7.2+ *(RN moved to react-native-gradle-plugin)* |
7980

8081
*NOTE: `react-native-code-push` versions lower than **[v5.7.0](https://github.com/microsoft/react-native-code-push/releases/tag/v5.7.0)** will stop working in the near future. You can find more information in our [documentation](https://github.com/microsoft/code-push/blob/master/migration-notice.md).*
8182

android/codepush.gradle

+25-19
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.nio.file.Paths;
44

5-
def config = project.hasProperty("react") ? project.react : [];
6-
def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
5+
def config = project.extensions.findByName("react") ?: []
6+
def bundleAssetName = config.bundleAssetName.get() ?: "index.android.bundle"
77

88
// because elvis operator
99
def elvisFile(thing) {
@@ -23,11 +23,18 @@ android.buildTypes.each { buildType ->
2323
buildType.resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
2424
}
2525

26-
gradle.projectsEvaluated {
26+
gradle.projectsEvaluated {
27+
def debuggableVariants = config.debuggableVariants.get() ?: ['debug']
28+
2729
android.applicationVariants.all { variant ->
30+
// No code push for debuggable variants
31+
if (debuggableVariants.contains(variant.name)) {
32+
return;
33+
}
34+
2835
def nodeModulesPath;
2936
if (config.root) {
30-
nodeModulesPath = Paths.get(config.root, "/node_modules");
37+
nodeModulesPath = Paths.get(config.root.asFile.get().absolutePath, "/node_modules");
3138
} else if (project.hasProperty('nodeModulesPath')) {
3239
nodeModulesPath = project.nodeModulesPath
3340
} else {
@@ -42,40 +49,38 @@ gradle.projectsEvaluated {
4249
def jsBundleFile;
4350

4451
// Additional node commandline arguments
45-
def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"]
46-
def extraPackagerArgs = config.extraPackagerArgs ?: []
52+
def nodeExecutableAndArgs = config.nodeExecutableAndArgs.get() ?: ["node"]
53+
def extraPackagerArgs = config.extraPackagerArgs.get() ?: []
4754

4855
// Make this task run right after the bundle task
4956
def generateBundledResourcesHash;
5057

51-
if (variant.hasProperty("bundleJsAndAssets")) {
52-
def reactBundleTask = variant.bundleJsAndAssets
53-
jsBundleDir = reactBundleTask.generatedAssetsFolders[0].absolutePath
54-
resourcesDir = reactBundleTask.generatedResFolders[0].absolutePath
58+
def reactBundleTask = tasks.findByName("createBundle${targetName}JsAndAssets")
59+
if (reactBundleTask) {
60+
jsBundleDir = reactBundleTask.property('jsBundleDir').asFile.get()
61+
resourcesDir = reactBundleTask.property('resourcesDir').asFile.get()
5562
jsBundleFile = file("$jsBundleDir/$bundleAssetName")
5663

5764
generateBundledResourcesHash = tasks.create(
5865
name: "generateBundledResourcesHash${targetName}",
5966
type: Exec) {
6067
commandLine (*nodeExecutableAndArgs, "${nodeModulesPath}/react-native-code-push/scripts/generateBundledResourcesHash.js", resourcesDir, jsBundleFile, jsBundleDir)
6168

62-
enabled config."bundleIn${targetName}" ||
63-
config."bundleIn${variant.buildType.name.capitalize()}" ?:
64-
targetName.toLowerCase().contains("release")
69+
enabled !debuggableVariants.contains(variant.name) ?: targetName.toLowerCase().contains("release")
6570
}
66-
71+
6772
runBefore("merge${targetName}Resources", generateBundledResourcesHash)
68-
runBefore("merge${targetName}Assets", generateBundledResourcesHash)
73+
runBefore("merge${targetName}Assets", generateBundledResourcesHash)
6974
} else {
7075
def jsBundleDirConfigName = "jsBundleDir${targetName}"
71-
jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?:
76+
jsBundleDir = elvisFile(config."$jsBundleDirConfigName").get() ?:
7277
file("$buildDir/intermediates/assets/${targetPath}")
7378

7479
def resourcesDirConfigName = "resourcesDir${targetName}"
75-
resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?:
80+
resourcesDir = elvisFile(config."${resourcesDirConfigName}").get() ?:
7681
file("$buildDir/intermediates/res/merged/${targetPath}")
7782

78-
// In case version of 'Android Plugin for Gradle'' is lower than 1.3.0
83+
// In case version of 'Android Plugin for Gradle'' is lower than 1.3.0
7984
// '$buildDir' has slightly different structure - 'merged' folder
8085
// does not exists so '${targetPath}' folder contains directly in 'res' folder.
8186
if (!resourcesDir.exists() && file("$buildDir/intermediates/res/${targetPath}").exists()) {
@@ -107,7 +112,8 @@ gradle.projectsEvaluated {
107112
generateBundledResourcesHash.dependsOn("recordFilesBeforeBundleCommand${targetName}")
108113
}
109114

110-
generateBundledResourcesHash.dependsOn("bundle${targetName}JsAndAssets")
115+
generateBundledResourcesHash.dependsOn("createBundle${targetName}JsAndAssets")
116+
111117
runBefore("processArmeabi-v7a${targetName}Resources", generateBundledResourcesHash)
112118
runBefore("processX86${targetName}Resources", generateBundledResourcesHash)
113119
runBefore("processUniversal${targetName}Resources", generateBundledResourcesHash)

docs/setup-android.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ In order to integrate CodePush into your Android project, please perform the fol
2727
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
2828
```
2929
30-
2. In your `android/app/build.gradle` file, add the `codepush.gradle` file as an additional build task definition underneath `react.gradle`:
30+
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
3232
```gradle
3333
...
34-
apply from: "../../node_modules/react-native/react.gradle"
3534
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
3635
...
3736
```

0 commit comments

Comments
 (0)