错误:无法确定当前字符,它不是字符串、数字、数组或对象在react-native for android中。
错误:无法确定当前字符,它不是字符串、数字、数组或对象在react-native for android中。
每当我在保持模拟器运行的同时运行`react-native run-android`时,我会遇到这个错误。`react-native run-ios`没有问题。
错误信息中指出,我尝试运行`npm uninstall -g react-native react-native-cli`,但没有起作用。
关于我的环境信息:
系统:
操作系统:macOS 10.15
CPU:(4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
内存:29.68 MB / 8.00 GB
Shell:3.2.57 - /bin/bash
二进制文件:
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
SDK:
iOS SDK:
平台:iOS 13.0,DriverKit 19.0,macOS 10.15,tvOS 13.0,watchOS 6.0
IDE:
Android Studio:3.5 AI-191.8026.42.35.5977832
Xcode:11.0/11A420a - /usr/bin/xcodebuild
npm包:
react:16.9.0 => 16.9.0
react-native:^0.61.4 => 0.61.4
npm全局包:
react-native-cli:2.0.1
android/app/build.gradle如下:
应用插件:"com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js",
enableHermes: false, // 如果更改,请清除并重新构建
]
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
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // 如果为真,还会生成通用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 {
// 注意!在生产环境中,您需要生成自己的密钥库文件。
// 参见https://facebook.github.io/react-native/docs/signed-apk-android。
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) {
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:+" // 从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
}
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 {
url("$rootDir/../node_modules/react-native/android")
}
maven {
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,但现在我遇到了上述错误。