5

I upgraded my project with using React Native Upgrade Helper from 0.67.4 to 0.68.0 And I saw that Gradle versions upgraded, too.

When I try to run ./gradlew clean command in ./android file, it gives me that compile error.

A problem occurred evaluating project ':react-native-i18n'. > Could not find method compile() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. 

To check it, I created new react native project with 0.68.2 version. On first run with npm run android command, application worked as expected. But after I install react-native-i18n package;

npm install react-native-i18n --save

and run ./gradlew clean command again, it gave me same error again.

I replaced compile with implementation on ./node_modules folder and it fixed the error. But if I have lots of packages, should I replace all of packages' build.gradle files manually?

Root build.gradle:

... dependencies { classpath("com.android.tools.build:gradle:7.0.4") classpath("com.facebook.react:react-native-gradle-plugin") classpath("de.undercouch:gradle-download-task:4.1.2") // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } ... 

gradle/wrapper/gradle-wrapper.properties file:

distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists 

Package.json:

... "dependencies": { "react": "17.0.2", "react-native": "0.68.2", "react-native-i18n": "^2.0.15" } ... 

Thanks.

2 Answers 2

13

This issue can be fixed by editing the node modules of react-native-i18n package.

  1. Go to node_modules/react-native-i18n/android/build.gradle
  2. Replace compile "com.facebook.react:react-native:+" into implementation "com.facebook.react:react-native:+"
  3. Save the file and run react-native run-android

You can use patch-package to make and persist changes to node modules.

This can be done by first making changes to the package inside node_modules and then running the following command, with being the name of the package you just made changes to.

npx patch-package patch-package will then create a patches folder with a file inside, representing your changes. This file can then be commited to git, and patches can be restored later by running npx patch-package (without any arguments).

Optional step:

Add the following in the script section of your package.json to automatically patch the dependency when you execute "npm install".

"postinstall": "npx patch-package"

Sign up to request clarification or add additional context in comments.

Comments

0
  • Where: Build file '..\node_modules@trackforce\react-native-crypto\android\build.gradle' line: 22

  • What went wrong: A problem occurred evaluating project ':trackforce_react-native-crypto'.

Could not find method compile() for arguments [com.android.support:appcompat-v7:23.0.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Change the code in that file error.

old compile 'com.android.support:appcompat-v7:23.0.1'

new api 'com.android.support:appcompat-v7:23.0.1'

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.