26

Whenever I run react-native run-android while keeping the emulator running, I get this error. react-native run-ios wroks completely fine.

Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
:ReactNative:Failed to parse React Native CLI configuration: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

The current character read is 'E' with an int value of 69
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
Error: Invalid attribute nameLine: 16Column: 18Char: .    at error (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/sax/lib/sax.js:651:10)    at strictFail (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/sax/lib/sax.js:677:7)    at SAXParser.write (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/sax/lib/sax.js:1313:13)    at new XmlDocument (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/xmldoc/lib/xmldoc.js:261:15)    at readManifest (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/@react-native-community/cli-platform-android/build/config/readManifest.js:38:10)    at Object.projectConfig (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/@react-native-community/cli-platform-android/build/config/index.js:59:46)    at Object.get project [as project] (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/config/index.js:114:50)    at /Users/yashatreya/Desktop/Realyze/Realyze/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/config/config.js:8:452    at Array.forEach (<anonymous>)    at _objectSpread (/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/config/config.js:8:392)
^

FAILURE: Build failed with an exception.

* Where:
Script '/Users/yashatreya/Desktop/Realyze/Realyze/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 201

* What went wrong:
A problem occurred evaluating script.
> Failed to parse React Native CLI configuration. Expected running 'npx --quiet --no-install react-native config' command from '/Users/yashatreya/Desktop/Realyze/Realyze' directory to output valid JSON, but it didn't. This may be caused by npx resolving to a legacy global react-native binary. Please make sure to uninstall any global 'react-native' binaries: 'npm uninstall -g react-native react-native-cli' and try again

* 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

As indicated in the error message, I tried running npm uninstall -g react-native react-native-cli but it didn’t work.

Info about my environment:

System:
    OS: macOS 10.15
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 29.68 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.13.0 - /usr/local/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.12.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5977832
    Xcode: 11.0/11A420a - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: ^0.61.4 => 0.61.4 
  npmGlobalPackages:
    react-native-cli: 2.0.1

android/app/build.gradle below:

apply plugin: "com.android.application"

import com.android.build.OutputFile
project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+' 

def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.realyze"
        minSdkVersion 21 
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }
    // rootProject.ext.minSdkVersion
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }

        }
    }
}

dependencies {
    implementation project(':react-native-push-notification')
    implementation project(':react-native-sound')
    implementation project(':react-native-audio')
    implementation 'com.android.support:multidex:2.0.1'
    implementation project(':react-native-gesture-handler')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation 'com.google.firebase:firebase-auth:19.1.0'
    implementation project(path: ":@react-native-firebase_auth")
    implementation project(path: ":@react-native-firebase_messaging")
    implementation project(path: ":@react-native-firebase_database")
    implementation project(':react-native-datetimepicker')
    implementation project(path: ":@react-native-firebase_firestore")
    implementation project(path: ":@react-native-firebase_functions")
}

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
// }

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'

android/build.gradle below :


buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.4.2"
        classpath 'com.google.gms:google-services:4.3.2'
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

Initially I was getting this error: react-native build error: Could not find method implementation() for arguments [jscFlavor] on project ':app' of type org.gradle.api.Project but now I am getting the above.

halfer
  • 19,824
  • 17
  • 99
  • 186
yashatreya
  • 782
  • 1
  • 9
  • 32
  • 1
    What operating system are you using? I found my issue was caused by file permissions inside the android build folders - no idea what happened but on my Windows 10 machine I had to make sure I started all my apps (Android Studio, VS Code, Windows Command) with elevated rights (Run as administrator). – Trevor Nov 20 '19 at 15:57
  • I’m using MacOS – yashatreya Nov 20 '19 at 15:58
  • I recreated the project using the CLI and it started working :-( – Trevor Nov 21 '19 at 10:51
  • @TahirKhalid Meaning you started a whole new project using react-native init? Can you please elaborate a bit, thanks – yashatreya Nov 21 '19 at 10:55
  • Yes I recreated the project but this time I made sure permissions were correct. I would use the MacOS console and chmod the folders and files to ensure correct read/write access – Trevor Nov 24 '19 at 21:30
  • I think this bug report seems related. https://github.com/react-native-community/cli/issues/863 – pasine Nov 26 '19 at 11:53

14 Answers14

56

SOLUTION 1 (worked for me)

The solution for me was removing the following line

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

Be sure to remove it everywhere. I had this line in build.gradle (app) and also in settings.gradle.

After that, run again npx react-native run-android the console will display the real error, fix the error and put back the lines you had removed.

In my case the error happened because I have been using an older Node version and the second time It happened I needed to sync my project again


SOLUTION 2

Delete the files it was finding error as "The current character read is 'E' with an int value of 69"

Deleting

app\build\intermediates\signing_config\debug\out\signing-config.json

worked for others too.


SOLUTION 3

Update the @react-native-community/cli to the latest version.

Good coding!

Faustino Gagneten
  • 2,564
  • 2
  • 28
  • 54
  • Installing from nodejs directly on MacOS also worked for me too, thank you! Doing brew installs, even with the uninstall and re-linking steps did not work. Suggest framing your answer to highlight the nodejs download directly, and then having the workaround below. – Kelton Temby Jan 06 '20 at 01:29
  • 2
    Turned out I still had the problem. The workaround helped me see a tiny syntax error in my `android/app/src/main/AndroidManifest.xml` file. With that now fixed, I was able to turn the other lines back on. – Kelton Temby Jan 06 '20 at 01:46
  • 1
    Thanks for sharing. I'll update the answer to make it more clear! – Faustino Gagneten Jan 06 '20 at 01:49
  • @Kelton.Temby, you can edit my answer to make it more clear for other users as you mentioned. – Faustino Gagneten Jan 07 '20 at 20:32
  • Solution 1 works. But what could be the side effect? What could go wrong? I imagine that removing that line could cause some issues. What does that line even do? – Justice Mba Dec 03 '22 at 01:49
  • Okay, I figured it. Solution 1 breaks auto-linking. https://github.com/react-native-community/cli/blob/main/docs/autolinking.md – Justice Mba Dec 03 '22 at 14:57
  • As I said in the comment,"After that, run again npx react-native run-android the console will display the real error, fix the error and put back the lines you had removed." Removing the line is just to see the real error, then you should put that line back when fix the real issue – Faustino Gagneten Dec 04 '22 at 14:07
18

That worked for me: Inside my_flavor/AndroidManifest.xml, inside manifest tag just add package="com.my_package_name":

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.my_package_name" // <<added
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission
...
</manifest>

Sher Mi
  • 548
  • 2
  • 5
  • 14
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 13 '22 at 12:03
  • Wow, this one worked for me as well! – gildniy Nov 13 '22 at 15:29
4

Deleting android/app/release worked for me.

Moses Gitau
  • 947
  • 8
  • 7
3

I think this problem is only in the newer version (0.61) I had the same issue and I just used the older version (0.60.0)

 npx react-native init AwesomeProject --version 0.60.0
Ali Mohammad
  • 794
  • 9
  • 16
3

Just removed the build folder inside android and go to android folder and then in powershell typed ./gradlew clean and then cd.. => npx react-native run-android

Irfan wani
  • 4,084
  • 2
  • 19
  • 34
2

Please ensure the AndroidManifest.xml data is in proper quotes "" not “”. This usually happens when we are configuring the firebase and copy pasting the dependencies.

vinny
  • 360
  • 3
  • 10
1

Deleting the node_modules folder and running npm install again worked for me

k26dr
  • 1,229
  • 18
  • 15
1

Check your androidmanifest.xml there are some issue will be there in that file..

In my case, I edited my androidmanifest.xml that's why I am getting that error and resolved that error by placing before edited code of androidmanifest.xml.

thank you:)

zr0gravity7
  • 2,917
  • 1
  • 12
  • 33
0

Follow the steps below in project folder

  1. cd android
  2. ./gradlew clean
  3. cd ..
  4. npm install
  5. react-native run-android
David Buck
  • 3,752
  • 35
  • 31
  • 35
Pawan
  • 11
  • 1
0

At first, you should try closing the emulator. In windows, when I tried to build with an emulator running this error occurred.

Shawon Barua
  • 61
  • 10
0

Maybe your npm (node) server is starting. if the server is starting close it.

Mitesh K
  • 694
  • 1
  • 11
  • 24
0

Deleting node_modules folder and running npm install again, it work for me!

ductridev
  • 99
  • 1
  • 7
0

For me, under Cygwin, the problem turned out to be a symbolic link named app in the application's top level directory (above android, beside node_modules), which was pointing to the full path where it was residing (e.g. /cygdrive/c/files/app). It got created around the time I started the build. After deleting it, the problem was solved.

Diomidis Spinellis
  • 18,734
  • 5
  • 61
  • 83
0

For the problem was that my AndroidManifest had erros. There were two "aplication" tags. By fixing the Manifest I was able to solved this issue.