HostObject::get 中的异常:<unknown>- React Native Build Android [英] Exception in HostObject::get: <unknown> - React Native Build Android

查看:49
本文介绍了HostObject::get 中的异常:<unknown>- React Native Build Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

After updating my React Native Application to React Native 0.59, i started to face an issue when trying to run my app in debug mode ( react-native run-android ) or after generating the package and installing into a device.

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

Here is the information about my issue:

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

React Native 错误屏幕中的错误:

Error in the React Native error screen:

Error · Module AppRegistry is not a registered callable module (calling runApplication)
http://localhost:8081/index.delta?platform=android&dev=true&minify=false:3954:26invariant   
http://localhost:8081/index.delta?platform=android&dev=true&minify=false:4674:18__callFunction  
http://localhost:8081/index.delta?platform=android&dev=true&minify=false:4433:31    
http://localhost:8081/index.delta?platform=android&dev=true&minify=false:4630:15__guard 
http://localhost:8081/index.delta?platform=android&dev=true&minify=false:4432:21callFunctionReturnFlushedQueue  
[native code]callFunctionReturnFlushedQueue

我的 build.gradle 文件

buildscript {
    ext {
         buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
        classpath 'io.fabric.tools:gradle:1.26.0'
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.10.2'
    distributionUrl = distributionUrl.replace("bin", "all")
}

我的 app/build.gradle 文件

apply plugin: "com.android.application"
apply plugin: "com.google.firebase.firebase-perf"
apply plugin: "io.fabric"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

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

def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    defaultConfig {
        applicationId "com.projectname"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        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", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            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, "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-splash-screen')
    implementation project(':@react-native-community_netinfo')
    implementation project(':@react-native-community_async-storage')
    implementation project(':react-native-linear-gradient')
    implementation project(':react-native-svg')
    implementation project(':bugsnag-react-native')
    implementation 'com.android.support:multidex:1.0.3'
    implementation project(':react-native-firebase')
    implementation "com.google.android.gms:play-services-base:16.0.1"
    implementation "com.google.firebase:firebase-core:16.0.6"
    implementation "com.google.firebase:firebase-messaging:17.3.4"
    implementation "com.google.firebase:firebase-perf:16.2.3"
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
        transitive = true
    }
    implementation project(':react-native-config')
    implementation project(':react-native-device-info')
    implementation project(':react-native-i18n')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-gesture-handler')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

// 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 plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == 'com.google.android.gms'
            && ( (details.requested.name == 'play-services-base') || (details.requested.name == 'play-services-maps') ) ) {
            details.useVersion '16.0.1'
        }
    }
}

这个错误发生在我的 Metro-bundler 加载 100% 之后(并且在 bundler 控制台屏幕上没有发生错误).

This error happens after my metro-bundler loads 100% ( and no error happens on the bundler console screen ).

感谢所有提供帮助的人!

Thanks for everyone who helps!

推荐答案

就我而言,问题在于 react-native-device-info.

In my case, the problem was with react-native-device-info.

在您的 app/build.gradle 依赖项中试试这个:

Try this in your app/build.gradle dependencies:

dependencies {
   ...
   implementation(project(':react-native-device-info')) {
      exclude group: 'com.google.android.gms'
   }
}

它对我有用.

这篇关于HostObject::get 中的异常:<unknown>- React Native Build Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆