HostObject::get 中的异常:<unknown> - React Native Build Android

Fel*_*ipe 5 android react-native

将我的 React Native 应用程序更新到 React Native 0.59 后,当我尝试在调试模式(react-native run-android)或生成包并安装到设备中运行我的应用程序时,我开始遇到问题。

\n

以下是有关我的问题的信息:

\n

我的环境:

\n
React Native Environment Info:\nSystem:\n  OS: macOS 10.14.3\n  CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\n  Memory: 479.23 MB / 8.00 GB\n  Shell: 3.2.57 - /bin/bash\nBinaries:\n  Node: 8.11.3 - /usr/local/bin/node\n  Yarn: 1.9.4 - /usr/local/bin/yarn\n  npm: 5.6.0 - /usr/local/bin/npm\n  Watchman: 4.9.0 - /usr/local/bin/watchman\nSDKs:\n  iOS SDK:\n    Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1\n  Android SDK:\n    API Levels: 26, 27, 28\n    Build Tools: 26.0.2, 28.0.2, 28.0.3\nIDEs:\n  Xcode: 10.1/10B61 - /usr/bin/xcodebuild\nnpmPackages:\n  react: 16.8.3 => 16.8.3 \n  react-native: 0.59.1 => 0.59.1 \nnpmGlobalPackages:\n  create-react-native-app: 1.0.0\n  react-native-cli: 2.0.1\n  react-native-git-upgrade: 0.2.7\n
Run Code Online (Sandbox Code Playgroud)\n

React Native 错误屏幕中出现错误:

\n

错误画面

\n

我的 bugsnag 上捕获的错误

\n
Error \xc2\xb7 Module AppRegistry is not a registered callable module (calling runApplication)\nhttp://localhost:8081/index.delta?platform=android&dev=true&minify=false:3954:26invariant   \nhttp://localhost:8081/index.delta?platform=android&dev=true&minify=false:4674:18__callFunction  \nhttp://localhost:8081/index.delta?platform=android&dev=true&minify=false:4433:31    \nhttp://localhost:8081/index.delta?platform=android&dev=true&minify=false:4630:15__guard \nhttp://localhost:8081/index.delta?platform=android&dev=true&minify=false:4432:21callFunctionReturnFlushedQueue  \n[native code]callFunctionReturnFlushedQueue\n
Run Code Online (Sandbox Code Playgroud)\n

我的 build.gradle 文件

\n
buildscript {\n    ext {\n         buildToolsVersion = "28.0.3"\n        minSdkVersion = 16\n        compileSdkVersion = 28\n        targetSdkVersion = 28\n        supportLibVersion = "28.0.0"\n    }\n    repositories {\n        google()\n        jcenter()\n        maven {\n            url \'https://maven.fabric.io/public\'\n        }\n    }\n    dependencies {\n        classpath \'com.android.tools.build:gradle:3.3.2\'\n        classpath \'com.google.gms:google-services:4.2.0\'\n        classpath \'com.google.firebase:firebase-plugins:1.1.5\'\n        classpath \'io.fabric.tools:gradle:1.26.0\'\n    }\n}\n\nallprojects {\n    repositories {\n        mavenLocal()\n        google()\n        jcenter()\n        maven {\n            url "$rootDir/../node_modules/react-native/android"\n        }\n    }\n}\n\ntask wrapper(type: Wrapper) {\n    gradleVersion = \'4.10.2\'\n    distributionUrl = distributionUrl.replace("bin", "all")\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我的 app/build.gradle 文件

\n
apply plugin: "com.android.application"\napply plugin: "com.google.firebase.firebase-perf"\napply plugin: "io.fabric"\n\nimport com.android.build.OutputFile\n\nproject.ext.react = [\n    entryFile: "index.js"\n]\n\napply from: "../../node_modules/react-native/react.gradle"\n\ndef enableSeparateBuildPerCPUArchitecture = false\n\n/**\n * Run Proguard to shrink the Java bytecode in release builds.\n */\ndef enableProguardInReleaseBuilds = false\n\nandroid {\n    compileSdkVersion rootProject.ext.compileSdkVersion\n\n    defaultConfig {\n        applicationId "com.projectname"\n        minSdkVersion rootProject.ext.minSdkVersion\n        targetSdkVersion rootProject.ext.targetSdkVersion\n        versionCode 1\n        versionName "1.0"\n        ndk {\n            abiFilters "armeabi-v7a", "x86"\n        }\n    }\n    signingConfigs {\n        release {\n            if (project.hasProperty(\'MYAPP_RELEASE_STORE_FILE\')) {\n                storeFile file(MYAPP_RELEASE_STORE_FILE)\n                storePassword MYAPP_RELEASE_STORE_PASSWORD\n                keyAlias MYAPP_RELEASE_KEY_ALIAS\n                keyPassword MYAPP_RELEASE_KEY_PASSWORD\n            }\n        }\n    }\n    splits {\n        abi {\n            reset()\n            enable enableSeparateBuildPerCPUArchitecture\n            universalApk false  // If true, also generate a universal APK\n            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"\n        }\n    }\n    buildTypes {\n        release {\n            minifyEnabled enableProguardInReleaseBuilds\n            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"\n            signingConfig signingConfigs.release\n        }\n    }\n    // applicationVariants are e.g. debug, release\n    applicationVariants.all { variant ->\n        variant.outputs.each { output ->\n            // For each separate APK per architecture, set a unique version code as described here:\n            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits\n            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]\n            def abi = output.getFilter(OutputFile.ABI)\n            if (abi != null) {  // null for the universal-debug, universal-release variants\n                output.versionCodeOverride =\n                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode\n            }\n        }\n    }\n}\n\ndependencies {\n    implementation project(\':react-native-splash-screen\')\n    implementation project(\':@react-native-community_netinfo\')\n    implementation project(\':@react-native-community_async-storage\')\n    implementation project(\':react-native-linear-gradient\')\n    implementation project(\':react-native-svg\')\n    implementation project(\':bugsnag-react-native\')\n    implementation \'com.android.support:multidex:1.0.3\'\n    implementation project(\':react-native-firebase\')\n    implementation "com.google.android.gms:play-services-base:16.0.1"\n    implementation "com.google.firebase:firebase-core:16.0.6"\n    implementation "com.google.firebase:firebase-messaging:17.3.4"\n    implementation "com.google.firebase:firebase-perf:16.2.3"\n    implementation(\'com.crashlytics.sdk.android:crashlytics:2.9.5@aar\') {\n        transitive = true\n    }\n    implementation project(\':react-native-config\')\n    implementation project(\':react-native-device-info\')\n    implementation project(\':react-native-i18n\')\n    implementation project(\':react-native-vector-icons\')\n    implementation project(\':react-native-gesture-handler\')\n    implementation fileTree(dir: "libs", include: ["*.jar"])\n    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"\n    implementation "com.facebook.react:react-native:+"  // From node_modules\n}\n\n// Run this once to be able to run the application with BUCK\n// puts all compile dependencies into folder libs for BUCK to use\ntask copyDownloadableDepsToLibs(type: Copy) {\n    from configurations.compile\n    into \'libs\'\n}\n\napply plugin: \'com.google.gms.google-services\'\ncom.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true\n\nconfigurations.all {\n    resolutionStrategy.eachDependency { DependencyResolveDetails details ->\n        if (details.requested.group == \'com.google.android.gms\'\n            && ( (details.requested.name == \'play-services-base\') || (details.requested.name == \'play-services-maps\') ) ) {\n            details.useVersion \'16.0.1\'\n        }\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

此错误发生在我的 Metro-bundler 加载 100% 后(并且捆绑器控制台屏幕上没有发生错误)。

\n

感谢所有提供帮助的人!

\n

Sof*_*ixt 1

该错误是因为您忘记在 android 检查 MainApplication.java 中安装某些模块,检查是否导入所有包以及是否添加到 ReactPackage list 。