【发布时间】:2023-04-11 07:38:02
【问题描述】:
本地社区!
我正在尝试运行一个应用程序,但我不断收到这个神秘的错误:
com.facebook.react.common.JavascriptException: undefined is not an object (evalating 'Sn[e]'),
当我使用类 Run 按钮尝试在我的手机上构建应用程序时,我在 Android Studio 中遇到了这个错误(是的,它已连接并被识别),当我使用终端来构建应用程序时,我也遇到了这个错误运行react-native run-android。
当我运行/构建应用程序时,它会在我的手机上安装 apk,但每次启动时都会立即崩溃。
在终端中使用adb logcat *:E 时,我发现此错误至少出现 6 次:
我在 Android Studio 中单击“运行”时多次发现此错误。
我之前只见过一两个类似的问题,比如 SO 上的here,或者
我也从this SO question 尝试了react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/,但它对我也不起作用。
这是我的主要 gradle 文件:
android/build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
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")
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
jcenter()
}
}
android/app/build.gradle:
apply plugin: "com.android.application"
import com.android.build.OutputFile
def useIntlJsc = false
project.ext.react = [ entryFile: 'index.android.js', enableHermes: false ]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.my.app.id"
minSdkVersion 16
targetSdkVersion 26
multiDexEnabled true
versionCode 9
versionName "2.0.6"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
// 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:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
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-linear-gradient')
implementation project(':react-native-google-analytics-bridge')
implementation project(':react-native-mapbox-gl') {
implementation ('com.squareup.okhttp3:okhttp:3.6.0') {
force = true
}
}
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.multidex:multidex:2.0.0'
implementation "androidx.appcompat:appcompat:1.0.2"
implementation "com.google.android.material:material:1.0.0"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation(project(':react-native-geolocation-service')) {
exclude group: 'com.google.android.gms', module: 'play-services-location'
}
implementation 'com.google.android.gms:play-services-location:17.0.0'
if (useIntlJsc) {
implementation 'org.webkit:android-jsc-intl:+'
} else {
implementation 'org.webkit:android-jsc:+'
}
}
// 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'
}
还有我的package.json,如果有帮助的话:
{
"name": "pkg",
"version": "0.0.1",
"private": true,
"scripts": {
"run:android": "./gradlew installDebug && npm run start:android",
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"@turf/buffer": "^5.1.5",
"@turf/collect": "^5.1.5",
"@turf/turf": "^5.1.6",
"react": "^16.9.0",
"react-native": "^0.60.5",
"react-native-geolocation-service": "^3.0.0",
"react-native-google-analytics-bridge": "^5.3.3",
"react-native-indicators": "^0.13.0",
"react-native-lightbox": "^0.7.0",
"react-native-linear-gradient": "^2.5.6",
"react-native-permissions": "^1.1.1",
"react-native-phone-call": "^1.0.4",
"react-native-progress": "^3.4.0",
"react-native-search-bar": "^3.0.0",
"react-navigation": "^3.11.0",
"react-redux": "^7.1.0",
"redux": "^4.0.4",
"redux-actions": "^2.0.3",
"redux-logger": "^3.0.6",
"redux-persist": "^5.10.0",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/preset-flow": "^7.0.0",
"babel-eslint": "^10.0.2",
"babel-jest": "^24.1.0",
"babel-plugin-module-resolver": "^3.2.0",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-config-import": "^0.13.0",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-jsx-a11y": "^5.0.3",
"eslint-plugin-react": "^7.0.1",
"eslint-plugin-react-native": "^2.3.2",
"jest": "24.1.0",
"metro-react-native-babel-preset": "^0.56.0",
"react-native-htmlview": "^0.14.0",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
}
【问题讨论】:
标签: android react-native android-gradle-plugin