microsoft / react-native-code-push

React Native module for CodePush
http://appcenter.ms
Other
8.98k stars 1.47k forks source link

No signature of method: java.util.ArrayList.get() is applicable for argument types: () values: [] #2470

Closed jvgeee closed 1 year ago

jvgeee commented 1 year ago

Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):

Getting this error when running Android build (in Android Studio) on the latest version of RN Codepush (8.0.0)

Script './node_modules/react-native-code-push/android/codepush.gradle' line: 6

* What went wrong:
A problem occurred evaluating script.
> No signature of method: java.util.ArrayList.get() is applicable for argument types: () values: []
  Possible solutions: get(int), get(int), set(int, java.lang.Object), set(int, java.lang.Object), grep(), grep()

Works fine on V7, assume that either the docs need to be upgraded for v8 or there's a bug somewhere

anhquan291 commented 1 year ago

I'm facing the same issue !

purevsurena commented 1 year ago

This error occurred on the react-native v0.70.4. Problem was here this line. apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

bmaluff commented 1 year ago

This error occurred on the react-native v0.70.4. Problem was here this line. apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

What do you mean @purevsurena? You missed the line? or changed something inside the file?

bmaluff commented 1 year ago

Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):

Getting this error when running Android build (in Android Studio) on the latest version of RN Codepush (8.0.0)

Script './node_modules/react-native-code-push/android/codepush.gradle' line: 6

* What went wrong:
A problem occurred evaluating script.
> No signature of method: java.util.ArrayList.get() is applicable for argument types: () values: []
  Possible solutions: get(int), get(int), set(int, java.lang.Object), set(int, java.lang.Object), grep(), grep()

Works fine on V7, assume that either the docs need to be upgraded for v8 or there's a bug somewhere

The line 5 in codepush.gradle should return a map, and is returning an ArrayList which doesn't support get() method

I just pushed a PR with the solution to this issue #2471

malikzype commented 1 year ago

Facing same issue

vlack-coder commented 1 year ago

I used v8 on a newly created project and it worked fine for both iOS and Android.

But for my old project. it only worked for iOS and gave this error for Android.

As @jvgeee said, I downgraded to v7 and it worked fine

@malikzype downgrade to v7 for a quick fix

Omaressam9500 commented 1 year ago

I am facing same error

malikzype commented 1 year ago

@vlack-coder Yes downgrading to v7 works fine

JB-CHAUVIN commented 1 year ago

Same problem goes for me. I tried the patch mentionned above but I have an other error now :

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

BUILD FAILED in 4s
blueberry6401 commented 1 year ago

v8 only works with react-native 0.71. Nothing is mentioned in the docs.

NguyenQuocAnDev27 commented 1 year ago

i work on react native version 0.66, codepush version 8.0.0 and got this issue too.

RoyalBosS-Ayush commented 1 year ago

Any update? Facing same on rn 0.68.0

shahanshah-cutshort commented 1 year ago

Downgrading to 7..0.0 with RN 0.70.5 is working.

nassimmiled commented 1 year ago

same here for React Native 0.64.2

NguyenQuocAnDev27 commented 1 year ago

Hello. I have solved this issue by doing the following: image In this step, find the first line then insert the second line. The first line is already there. I copied and pasted 2 line at the end build.gradle file so first line is already there so it make file have 2 line have the same code so it cause error. image In this step, delete include ':app' then copy paste this code to there. image This step insert library then find ReactNativeHost then insert this code:

@Override protected String getJSBundleFile() { return CodePush.getJSBundleFile(); }

image In this step, DeploymentKey can be get on web appcenter or use command appcenter codepush deployment list -a / -k

so i have ownerName like nguyenquocan and app name like testApp i will have this command: appcenter codepush deployment list -a nguyenquuocan/testApp -k if you have @gmail.com at the end owner name -> appcenter codepush deployment list -a nguyenquocan-gmail.com/testApp -k

And you want to make update change you must change versionCode in android/app/build.gradle build.gradle will have this object -> android{defaultConfig{versionCode}} change like 1 -> 2. And change versionName don't make update in your app. It is the target you will update. if you have version 1.0.0 and version 1.0.1, it will not update version 1.0.0 to 1.0.1

if you want more details. You can read in this docs. https://learn.microsoft.com/en-us/appcenter/distribution/codepush/rn-get-started#android-setup

And 1 more thing. Version codepush support differnt sdk. So i have sdk version 30 codepush version 8.0.0 seem not support this. So i use version 7.0.4 then it work. Detail of my sdk i use: image

That's all. I hope this will be useful.

RyanPliske commented 1 year ago

same with RN 0.70.5

taongocsontam commented 1 year ago

I'm find resolve here: #2471 https://github.com/microsoft/react-native-code-push/pull/2471/commits/dbbc0df43351ebee9eff7a7ae05bb3443a65304d

prashantsoni-ai commented 1 year ago

For anyone who is still facing the issue. follow these steps with library "react-native-code-push": "^7.0.1" , "react-native": "0.70.5" Codepush - appcenter - OTA - Autoupdate Install library - react-native-code-push

Install appcenter CLI - npm install -g appcenter-cli

Login to app center - appcenter login

Create a new app - appcenter apps create -d <AppName> -o <OS> -p React-Native

PS: Replace app name and os to your requirements.

Create Production and Staging keys using -

appcenter codepush deployment add -a <ownerName>/<appName> Production

 appcenter codepush deployment add -a <ownerName>/<appName> Staging

PS: Replace ownerName and appName to your ownerName and appName

Once the app is set up, verify it with the appcenter.

Changes in React Native codebase. //Add this code to MainApplication.java

import com.microsoft.codepush.react.CodePush;  //import this library
@Override //Add this code to the ReactNativeHost function. 
protected String getJSBundleFile() {
    return CodePush.getJSBundleFile();
}

<string moduleConfig="true" name="CodePushDeploymentKey">ProductionKey</string> PS: Replace the production key to you production/staging keys obtained in step 5

apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

include ':app', ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app') 

PS: Dont enter the above code in the If block.

PS: this code creates a codepush wrapper class and we wrap the App component in this class

import codePush from "react-native-code-push"; 
const codePushOptions = { 
checkFrequency: codePush.CheckFrequency.ON_APP_RESUME, 
installMode: codePush.InstallMode.IMMEDIATE,
};

export default App = codePush(codePushOptions)(App);

Once all of the above steps are completed, run the following command to create the deployment. appcenter codepush deployment create -a <app_name> -d <deployment_name>

And run the following command to update your deployment.

appcenter codepush release-react -a <app_name> -d <deployment_name>

PS: Replace the app_name and deployment_name to your app’s name and Staging/Production respectively.

Note: Codepush might have some issues with some versions of ReactNative So make sure you have “react-native-code-push” → “7.0.1” if using “react-native" → “^0.70.0” References → Auto Update``

Azhar456 commented 1 year ago

i solved this solved issue

"react-native": "0.68.2", "react-native-code-push": "8.0.1",

I didn't import the import com.microsoft.codepush.react.CodePush; in MainApplication.java

Note! You might have the following error.

Cannot add task 'bundleDebugJsAndAssets' as a task with that name already exists. Please double-check whether you have a duplicate code in root/android/app/build.gradle .

savaskalkan commented 1 year ago

I solved this guys. I just downgrade codepush version from 8.0.1 to 7.0.4 There is an issue that needs to be fixed by codepush team

harish92 commented 1 year ago

+1 I'm also facing same issue.

Azhar456 commented 1 year ago

+1 I'm also facing same issue.

please recheck the if you follow all the steps correctly or not

harish92 commented 1 year ago

yes followed all the steps still facing same issue.

Azhar456 commented 1 year ago

yes followed all the steps still facing same issue.

show your code or if you want help then will connect

FrontendTerminator commented 1 year ago

Just got the same error. But I solved it by downgrading from 8.0.1 to 7.0.1 code push version. My react native version 0.64.4

jvgeee commented 1 year ago

Upgraded React Native to 0.71.4 and V8 of rn-code-push no longer causes this error in Android.

If you're on an earlier version of React Native, the solution is to use v7 of this plugin, e.g. yarn add react-native-code-push@7.

Gamote commented 1 year ago

If you want to make it work with a 0.6x React Native use this patch.

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 ```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 ```
locht commented 1 year ago

downgrade v7.0.4 working for me

MateusAndrade commented 1 year ago

Same issue with:

        "react-native": "^0.72.0",
        "react-native-code-push": "^8.0.2",
jesus-castro3 commented 1 year ago

For anyone reading this, fyi react-native-code-push v8.0.0+ is incompatible with versions 0.65-0.70+ , took me a while to figure that out. Either you upgrade to RN 71 to use codepush v8 or you still with v7 for now.

kigh143 commented 1 year ago

Downgrading helped me but then faced this error : The CodePush module doesn't appear to be properly installed.

ranavikrantsingh07 commented 8 months ago

Iam Still facing the same issue downgraded the Codepush version to 7 still the same currently Iam using RN@0.70.0 `FAILURE: Build completed with 2 failures. So without codepush it works fine once I installed this I faced this issue

1: Task failed with an exception.

2: Task failed with an exception.

vanqui123 commented 5 months ago

use patch package and change file codepush.gradle

react-native-code-push+8.2.2.patch