【问题标题】:Error: Unable to determine the current character, it is not a string, number, array, or object in react-native for android错误:无法确定当前字符,它不是 android react-native 中的字符串、数字、数组或对象
【发布时间】:2020-03-16 01:34:44
【问题描述】:

每当我在保持模拟器运行的同时运行 react-native run-android 时,都会出现此错误。 react-native run-ios 运行良好。

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

如错误消息所示,我尝试运行npm uninstall -g react-native react-native-cli,但没有成功。

关于我的环境的信息:

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 下面:

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 下面:


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' }
    }
}

最初我收到此错误:react-native build error: Could not find method implementation() for arguments [jscFlavor] on project ':app' of type org.gradle.api.Project 但现在我收到上述错误。

【问题讨论】:

  • 您使用的是什么操作系统?我发现我的问题是由 android 构建文件夹中的文件权限引起的 - 不知道发生了什么,但在我的 Windows 10 机器上,我必须确保我以提升的权限启动了所有应用程序(Android Studio、VS Code、Windows 命令)(运行作为管理员)。
  • 我使用的是 MacOS
  • 我使用 CLI 重新创建了项目并开始工作:-(
  • @TahirKhalid 意思是你使用 react-native init 开始了一个全新的项目?能详细说明一下吗,谢谢
  • 是的,我重新创建了项目,但这次我确保权限正确。我会使用 MacOS 控制台并 chmod 文件夹和文件以确保正确的读/写访问

标签: javascript java android node.js react-native


【解决方案1】:

解决方案 1(为我工作)

我的解决方案是删除以下行

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

请务必在任何地方删除它。我在 build.gradle (app)settings.gradle 中有这一行。

之后,再次运行npx react-native run-android控制台会显示真正的错误,修复错误并放回你删除的行。

在我的情况下,发生错误是因为我一直在使用较旧的 Node 版本,第二次发生了我需要再次同步我的项目


解决方案 2

删除它发现错误为“当前读取的字符是'E',int值为69”的文件

删除

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

也为其他人工作过。


解决方案 3

@react-native-community/cli 更新到最新版本。

编码不错!

【讨论】:

  • 直接在 MacOS 上从 nodejs 安装也对我有用,谢谢!进行 brew 安装,即使使用卸载和重新链接步骤也不起作用。建议将您的答案直接突出显示 nodejs 下载,然后使用以下解决方法。
  • 原来我还是有这个问题。解决方法帮助我在android/app/src/main/AndroidManifest.xml 文件中看到了一个微小的语法错误。现在修复了这个问题,我可以重新打开其他线路。
  • 感谢分享。我会更新答案以使其更清楚!
  • @Kelton.Temby,您可以编辑我的答案,以便您提到的其他用户更清楚。
【解决方案2】:

我认为这个问题只在较新的版本(0.61)我有同样的问题,我只是使用旧版本(0.60.0)

 npx react-native init AwesomeProject --version 0.60.0

【讨论】:

    【解决方案3】:

    刚刚删除了 android 中的 build 文件夹并转到 android 文件夹,然后在 powershell 中输入./gradlew clean 然后cd.. => npx react-native run-android

    【讨论】:

      【解决方案4】:

      请确保 AndroidManifest.xml 数据使用正确的引号“”而不是“”。这通常发生在我们配置 firebase 并复制粘贴依赖项时。

      【讨论】:

      • 该死的人,我从我的 xml 中的某个网站复制粘贴它,我没有注意到非常感谢
      【解决方案5】:

      删除 android/app/release 对我有用。

      【讨论】:

        【解决方案6】:

        检查您的androidmanifest.xml,该文件中会有一些问题..

        就我而言,我编辑了我的androidmanifest.xml,这就是为什么我收到该错误并通过将androidmanifest.xml 的编辑代码放在前面来解决该错误。

        谢谢你:)

        【讨论】:

          【解决方案7】:

          删除node_modules 文件夹并再次运行npm install 对我有用

          【讨论】:

            【解决方案8】:

            在项目文件夹中按照以下步骤操作

            1. cd android
            2. ./gradlew clean
            3. cd ..
            4. npm install
            5. react-native run-android

            【讨论】:

              【解决方案9】:

              首先,您应该尝试关闭模拟器。在 Windows 中,当我尝试使用运行此错误的模拟器进行构建时。

              【讨论】:

                【解决方案10】:

                也许您的 npm(节点)服务器正在启动。 如果服务器开始关闭它。

                【讨论】:

                  【解决方案11】:

                  删除node_modules 文件夹并再次运行npm install,它对我有用!

                  【讨论】:

                    【解决方案12】:

                    对我来说,在 Cygwin 下,问题原来是应用程序顶层目录中名为 app 的符号链接(android 上方,node_modules 旁边),它指向它所在的完整路径居住(例如/cygdrive/c/files/app)。它是在我开始构建的时候创建的。删除后问题就解决了。

                    【讨论】:

                      猜你喜欢
                      • 2020-02-12
                      • 1970-01-01
                      • 2012-01-03
                      • 2012-03-19
                      • 1970-01-01
                      • 2019-11-21
                      • 1970-01-01
                      • 1970-01-01
                      • 2012-10-23
                      相关资源
                      最近更新 更多