React Native on Android: Unable to determine the current character, it is not a string, number, array, or object
Asked Answered
I

9

7

I create a new application and insert a old code, when i build the application this error appears:

Script 'C:\Users\nameuser\Desktop\nameapp\node_modules@react-native-community\cli-platform-android\native_modules.gradle' line: 191

What went wrong:

A problem occurred evaluating settings 'nameapp'.

Unable to determine the current character, it is not a string, number, array, or object

The current character read is 'i' with an int value of 105
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
info Run "react-native --help" to see a list of all available commands.

With react-native info command I have the current situation:

info
  React Native Environment Info:
    System:
      OS: Windows 10
      CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
      Memory: 6.46 GB / 15.85 GB
    Binaries:
      Yarn: 1.15.2 - C:\laragon\bin\nodejs\node-v11\yarn.CMD
      npm: 6.12.0 - C:\Program Files\nodejs\npm.CMD
    IDEs:
      Android Studio: Version  3.5.0.0 AI-191.8026.42.35.5900203

And on the package.json:

{
  "name": "nameapp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-community/cli-platform-android": "^2.9.0",
    "axios": "^0.18.0",
    "haversine": "^1.1.0",
    "moment": "^2.22.2",
    "react": "16.6.3",
    "react-native": "^0.59.8",
    "react-native-actionsheet": "^2.4.2",
    "react-native-auto-height-image": "^1.1.0",
    "react-native-cached-image": "^1.4.3",
    "react-native-cli": "^2.0.1",
    "react-native-fbsdk": "^0.8.0",
    "react-native-global-font": "^1.0.2",
    "react-native-google-places": "^3.0.5",
    "react-native-image-crop-picker": "^0.24.1",
    "react-native-image-pan-zoom": "^2.1.10",
    "react-native-image-placeholder": "^1.0.14",
    "react-native-iphone-x-helper": "^1.2.0",
    "react-native-keyboard-manager": "^4.0.13-10",
    "react-native-maps": "github:react-community/react-native-maps",
    "react-native-maps-super-cluster": "^1.4.1",
    "react-native-modal-datetime-picker": "^5.1.0",
    "react-native-open-maps": "^0.3.3",
    "react-native-progress": "^3.4.0",
    "react-native-push-notification": "^3.1.2",
    "react-native-router-flux": "^4.0.6",
    "react-native-share": "^1.2.1",
    "react-native-snap-carousel": "^3.7.4",
    "react-native-swiper": "^1.5.13",
    "react-native-vector-icons": "^4.6.0",
    "react-native-view-shot": "^2.5.0",
    "react-redux": "^5.0.7",
    "redux": "^3.7.2",
    "redux-persist": "^4.10.1",
    "redux-persist-transform-filter": "0.0.15",
    "redux-thunk": "^2.2.0"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
  },
  "jest": {
    "preset": "react-native"
  },
  "rnpm": {
    "assets": [
      "./src/fonts"
    ]
  }
}

Thank for the help.

Isocracy answered 15/10, 2019 at 13:8 Comment(3)
will need more context. when did the error show up? Was it during the android build?Bananas
@Bananas exactly!Isocracy
I have entered further information.Isocracy
G
2

The build process executes:

npx --quiet react-native config or npx.cmd --quiet react-native config

That command, if you execute in the root directory of your project, will produce JSON output (if everything is configured correctly).

Then the JSON output is parsed within the gradle script you had referenced. When things are not configured correctly, th npx --quiet react-native config will produce nothing, or invalid output. So, JSON parsing (on line 191) will fail.

That whole machinery of invoking 'npx --quiet react-native config', is used in latest version of react-native, so that it will automatically 'bind' all the react native packages you have in your package.json, into your Android java app. (it basically injects at compile time of your app, all those packages names).

--

Unfortunately, there is not a single 'workaround' that will help you to fix this problem. You may have a missmatch (or incorrectly configured)

  • app/build.gradle
  • settings.gradle
  • build.gradle
  • versions of @react-native/community/cli in your package.json
  • versions of react-native that work with specific version of community-cli
  • react-native.config.js

Best thing I could recommend at this point is upgrade to whatever latest React release you can afford, and then use

https://github.com/react-native-community/rn-diff-purge

to figure out all the changes you need to make the above config files between the version where it worked, and version of RN where it stopped working.


If all fails try to debug native_modules.gradle. Go there, and insert:

 this.logger.warn("cmd: ${command}, result: ${reactNativeConfigOutput}");

somewhere, after a statement that initializes reactNativeConfigOutput string variable.

This log statement will print out the command and the output of that command that's executed by this autolinking machinery.

So when you run gradlew build
you should see some output.

In my case the command (cmd) was:

npx.cmd --quiet react-native config

and reactNativeConfigOutput was:

 info Run "react-native --help" to see a list of all available commands

you can see that the ouptut was not a valid json, and the first character was 'i' , and the JSON output parse (that's used in native_modules.gradle) threw the error that complained about 'i' not being a valid character

Glaudia answered 16/10, 2019 at 13:34 Comment(0)
K
2

I had to delete app\build\intermediates\signing_config\debug\out\signing-config.json and now it works.

Reference: https://gitmemory.com/issue/facebook/react-native/25936/517993846

Kelleykelli answered 23/12, 2019 at 15:56 Comment(0)
O
2

In my case after upgrading the grade plugin in Android Studio, I noticed that the package in AndroidManifest.xml was removed. Putting it back solved it.

Before Upgrading:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
  package="com.example">

After Upgrading:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android">

Just Add the package name in the upgraded version:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example">
Orban answered 17/4, 2023 at 9:9 Comment(0)
G
1

I spent a while on this. I ended up just removing the following 2 files, clean and rebuild.

app\build\intermediates\signing_config\debug\out\signing-config.json
app\build\intermediates\signing_config\release\out\signing-config.json
Gametophyte answered 14/11, 2019 at 14:12 Comment(0)
R
0

I had a similar problem just after dumping code from GitHub. What I have found out there was a merging conflict in android/app/src/AndroidManifest.xml file.

So whenever I was trying to rebuild Android app, there was parsing error with some weird new characters.

Rugg answered 3/12, 2019 at 8:54 Comment(0)
V
0

In my case when I removed the package react-native-firebase, this problem was popping up. I removed the dependency from my react-native-config.js, so if this happens while removing a package make sure you remove everything related to this package from your folders

Vivianna answered 4/8, 2022 at 11:26 Comment(0)
G
0

I had the same issue and the solution was to execute the command npx --quiet react-native config at the project root.

The response was an error that pointed me to app/[variant_name]/release/[app-name].apk folder.

So in my case was a broken and unpacked build that somehow was loaded during gradle initialization. When the folder has been removed the issue disappeared.

Giulia answered 7/7, 2023 at 15:0 Comment(0)
L
0

I encountered an issue while using the React Native Camera Roll library, which resulted in a missing package attribute in the AndroidManifest.xml file.

The problem was located within the file at node_modules/@react-native-camera-roll/camera-roll/android/src/main/java/AndroidManifest.xml.

The absence of this attribute was causing complications during the build process.

The original content of the AndroidManifest.xml file appeared as follows:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

I added the missing package attribute to the manifest element as shown below:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.reactnativecommunity.cameraroll">

Implementing this change effectively resolved the problem I was facing. It's essential to note that this modification may revert to its original state or be removed during subsequent builds, as it resides within the node_modules directory.

Lonesome answered 5/11, 2023 at 23:19 Comment(2)
Generally, it is not a good idea to modify existing packages for the reason you stated: "this modification may revert to its original state or be removed during subsequent builds".Labanna
Yes, correct it's not a good idea to modify packages unless necessary or other hacks are not working!Lonesome
M
-1

The issue is that react-native-community@^2.0.0 is only compatible with react-native@^0.59.0. (doc)

You have to upgrade react-native or downgrade react-native-community

Metamerism answered 12/11, 2019 at 10:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.