react-native-code-push icon indicating copy to clipboard operation
react-native-code-push copied to clipboard

Update codepush.gradle

Open bmaluff opened this issue 1 year ago • 12 comments

config was receiving an ArrayList as a false case, but ArrayLists don't support get() method, so it should receive a Map instance.

bmaluff avatar Mar 28 '23 17:03 bmaluff

Hi @bmaluff,

Throwing the below error. PFA Cannot invoke method get() on a null object Screenshot 2023-03-29 at 11 27 35 PM

sureshbakshi avatar Mar 29 '23 17:03 sureshbakshi

Same error as @sureshbakshi

> Configure project :app
Reading env from: .env

FAILURE: Build failed with an exception.

* Where:
Script '/Users/cegedim/Documents/Cegedim/Code/Mobile/keynote2/packages/mobile-pro/node_modules/react-native-code-push/android/codepush.gradle' line: 6

* What went wrong:
A problem occurred evaluating script.
> Cannot invoke method get() on null object

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings

JB-CHAUVIN avatar Apr 03 '23 06:04 JB-CHAUVIN

Thanks for the reviews!! Updated the code to fix it according to your findings!!!

bmaluff avatar Apr 03 '23 15:04 bmaluff

Hi @bmaluff,

Throwing the below error. PFA Cannot invoke method get() on a null object Screenshot 2023-03-29 at 11 27 35 PM

@sureshbakshi Can you test again, plz?

bmaluff avatar Apr 03 '23 15:04 bmaluff

Hello, right now I patched changes from this pr and it helped to fix the problem. I hope it will be in release soon

pavlobu avatar May 24 '23 08:05 pavlobu

I can confirm that this fixed our issue as well.

We use the following versions: react-native: 0.64.4 react-native-code-push: 8.0.1

If you use patch-package this is the patch:

react-native-code-push+8.0.1.patch
diff --git a/node_modules/react-native-code-push/android/codepush.gradle b/node_modules/react-native-code-push/android/codepush.gradle
index a0f9d27..09a0951 100644
--- a/node_modules/react-native-code-push/android/codepush.gradle
+++ b/node_modules/react-native-code-push/android/codepush.gradle
@@ -1,9 +1,15 @@
 // Adapted from https://raw.githubusercontent.com/facebook/react-native/d16ff3bd8b92fa84a9007bf5ebedd8153e4c089d/react.gradle
 
+/**
+ * A patch was applied to this file to fix an issue with the CodePush plugin
+ * Issue: https://github.com/microsoft/react-native-code-push/issues/2470#issuecomment-1519511406
+ * Patch: https://github.com/microsoft/react-native-code-push/pull/2471
+ */
+
 import java.nio.file.Paths;
 
-def config = project.extensions.findByName("react") ?: []
-def bundleAssetName = config.bundleAssetName.get() ?: "index.android.bundle"
+def config = project.extensions.findByName("react") ?: [:]
+def bundleAssetName = config.bundleAssetName ? config.bundleAssetName.get() : "index.android.bundle"
 
 // because elvis operator
 def elvisFile(thing) {
@@ -24,7 +30,7 @@ android.buildTypes.each { buildType ->
 }
 
 gradle.projectsEvaluated {
-    def debuggableVariants = config.debuggableVariants.get() ?: ['debug']
+    def debuggableVariants = config.debuggableVariants ? config.debuggableVariants.get() : ['debug']
 
     android.applicationVariants.all { variant ->
         // No code push for debuggable variants
@@ -49,8 +55,8 @@ gradle.projectsEvaluated {
         def jsBundleFile;
 
         // Additional node commandline arguments
-        def nodeExecutableAndArgs = config.nodeExecutableAndArgs.get() ?: ["node"]
-        def extraPackagerArgs = config.extraPackagerArgs.get() ?: []
+        def nodeExecutableAndArgs = config.nodeExecutableAndArgs ? config.nodeExecutableAndArgs.get(): ["node"]
+        def extraPackagerArgs = config.extraPackagerArgs ? config.extraPackagerArgs.get() : []
 
         // Make this task run right after the bundle task
         def generateBundledResourcesHash;
@@ -73,11 +79,11 @@ gradle.projectsEvaluated {
             runBefore("merge${targetName}Assets", generateBundledResourcesHash)
         } else {
             def jsBundleDirConfigName = "jsBundleDir${targetName}"
-            jsBundleDir = elvisFile(config."$jsBundleDirConfigName").get() ?:
+            jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ? elvisFile(config."$jsBundleDirConfigName").get():
                     file("$buildDir/intermediates/assets/${targetPath}")
 
             def resourcesDirConfigName = "resourcesDir${targetName}"
-            resourcesDir = elvisFile(config."${resourcesDirConfigName}").get() ?:
+            resourcesDir = elvisFile(config."${resourcesDirConfigName}") ? elvisFile(config."${resourcesDirConfigName}").get():
                     file("$buildDir/intermediates/res/merged/${targetPath}")
 
             // In case version of 'Android Plugin for Gradle'' is lower than 1.3.0

Gamote avatar May 30 '23 14:05 Gamote

I can confirm that this fixed our issue as well.

We use the following versions: react-native: 0.64.4 react-native-code-push: 8.0.1

If you use patch-package this is the patch:

react-native-code-push+8.0.1.patch

diff --git a/node_modules/react-native-code-push/android/codepush.gradle b/node_modules/react-native-code-push/android/codepush.gradle
index a0f9d27..09a0951 100644
--- a/node_modules/react-native-code-push/android/codepush.gradle
+++ b/node_modules/react-native-code-push/android/codepush.gradle
@@ -1,9 +1,15 @@
 // Adapted from https://raw.githubusercontent.com/facebook/react-native/d16ff3bd8b92fa84a9007bf5ebedd8153e4c089d/react.gradle
 
+/**
+ * A patch was applied to this file to fix an issue with the CodePush plugin
+ * Issue: https://github.com/microsoft/react-native-code-push/issues/2470#issuecomment-1519511406
+ * Patch: https://github.com/microsoft/react-native-code-push/pull/2471
+ */
+
 import java.nio.file.Paths;
 
-def config = project.extensions.findByName("react") ?: []
-def bundleAssetName = config.bundleAssetName.get() ?: "index.android.bundle"
+def config = project.extensions.findByName("react") ?: [:]
+def bundleAssetName = config.bundleAssetName ? config.bundleAssetName.get() : "index.android.bundle"
 
 // because elvis operator
 def elvisFile(thing) {
@@ -24,7 +30,7 @@ android.buildTypes.each { buildType ->
 }
 
 gradle.projectsEvaluated {
-    def debuggableVariants = config.debuggableVariants.get() ?: ['debug']
+    def debuggableVariants = config.debuggableVariants ? config.debuggableVariants.get() : ['debug']
 
     android.applicationVariants.all { variant ->
         // No code push for debuggable variants
@@ -49,8 +55,8 @@ gradle.projectsEvaluated {
         def jsBundleFile;
 
         // Additional node commandline arguments
-        def nodeExecutableAndArgs = config.nodeExecutableAndArgs.get() ?: ["node"]
-        def extraPackagerArgs = config.extraPackagerArgs.get() ?: []
+        def nodeExecutableAndArgs = config.nodeExecutableAndArgs ? config.nodeExecutableAndArgs.get(): ["node"]
+        def extraPackagerArgs = config.extraPackagerArgs ? config.extraPackagerArgs.get() : []
 
         // Make this task run right after the bundle task
         def generateBundledResourcesHash;
@@ -73,11 +79,11 @@ gradle.projectsEvaluated {
             runBefore("merge${targetName}Assets", generateBundledResourcesHash)
         } else {
             def jsBundleDirConfigName = "jsBundleDir${targetName}"
-            jsBundleDir = elvisFile(config."$jsBundleDirConfigName").get() ?:
+            jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ? elvisFile(config."$jsBundleDirConfigName").get():
                     file("$buildDir/intermediates/assets/${targetPath}")
 
             def resourcesDirConfigName = "resourcesDir${targetName}"
-            resourcesDir = elvisFile(config."${resourcesDirConfigName}").get() ?:
+            resourcesDir = elvisFile(config."${resourcesDirConfigName}") ? elvisFile(config."${resourcesDirConfigName}").get():
                     file("$buildDir/intermediates/res/merged/${targetPath}")
 
             // In case version of 'Android Plugin for Gradle'' is lower than 1.3.0

Using this patch fixed the build error for rn 0.72 🚀

MateusAndrade avatar Jun 26 '23 14:06 MateusAndrade

@DmitriyKirakosyan Can you review this PR so the fix can be available for everyone, plz??

bmaluff avatar Jun 26 '23 17:06 bmaluff

@MateusAndrade Please provide steps how to use this patch package

vishpatil1999 avatar Jul 03 '23 12:07 vishpatil1999

@MateusAndrade Please provide steps how to use this patch package

Checkout patch-package for steps on how to install it.

Then create a file out of the code block, call it react-native-code-push+8.0.1.patch and put it into the patches folder.

Gamote avatar Jul 03 '23 15:07 Gamote

@bmaluff Can you please post steps on how to reproduce the issue?

velimir-jankovic avatar Nov 08 '23 14:11 velimir-jankovic

Anyone knows why the react extension is not found in extensions and why does config file fallback to empty array?

project.extensions.findByName("react")

I get that this PR fixes wrongly accessed type, but why does it even comes to that?

EDIT: Reverting to v7 fixed the issue

mnikolaus avatar Nov 09 '23 14:11 mnikolaus