react-native build failed, 'native_modules.gradle' line: 182

Viewed 6861

I init a new project using react native 0.61.2 , using react-native init proj command, after that when I try to react-native run-android, the build fails with this error :

FAILURE: Build failed with an exception.

  • Where:Script '..\node_modules@react-native-community\cli-platform-android\native_modules.gradle' line: 182

  • What went wrong: A problem occurred evaluating script. Unable to determine the current character, it is not a string, number, array, or object

    The current character read is 'D' with an int value of 68 Unable to determine the current character, it is not a string, number, array, or object line number 1 index number 0 as i mentioned, it's a fresh project. any idea how to fix this ?

4 Answers

I ran into the same issue today and noticed that react recently released new versions to react-native and react.

I downgraded to versions i know work properly which are:

"react": "~16.8.0",
"react-native": "~0.60.0"

cleared all cache and the project loads correctly.

in order to do so change the dependencies in your package.json file

then delete your node_modules directory, package.lock file and run npm cache clean

finally run npm i

perhaps there are still issues in the new releases.

I am aslo facing the same issue. Downgrading works, however i have two other projects that r working fine and they are react native 0.61.2

Only new projects are giving this error. I read in some blogs that removing react community cli from global and trying again might do the trick.

Will try that tomorrow and post my findings.

Look for mistakes in your AndroidManifest.xml!!!

For me, I solved this by replacing the character ā€ with " (And also read some people telling that unclosed tags did that too) As dumb as it looks, I got to this error from following a tutorial.

(tip: VS code would often show these quotes in different colors, unless you have installed another XML files extension)

I ran into the same issue in a fresh project with RN 0.64.0. The project was created inside a monorepo that was using Yarn workspaces. In my case, Yarn had moved or "hoisted" the @react-native-community/cli-platform-android/native_modules.gradle file to the root node_modules directory.

The Android project's settings.gradle and build.gradle files are expecting the @react-native-community/cli-platform-android/native_modules.gradle file to be in the RN project's node_modules directory and not the repo's root node_modules directory.

Try updating line 2 of settings.gradle to something like:

apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

And line 222 of build.gradle to something like:

apply from: file("../../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

Obviously, you will need to adjust how many leading ../ you add to the path depending on how nested your project is.

You could also look into using the nohoist options available with Yarn to keep packages from moving around.

Related