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

时间:2019-03-18 21:54:26

标签: android react-native

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

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

我的环境:

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 screen

我的bugsnag捕获了错误

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%之后发生(并且在Bundle Console屏幕上没有发生错误)。

感谢所有提供帮助的人!

3 个答案:

答案 0 :(得分:1)

该错误是因为您忘记在android中安装某些模块,所以请检查MainApplication.java并检查是否导入了所有软件包,以及是否将其添加到ReactPackage列表中。

答案 1 :(得分:1)

在我的情况下,问题出在react-native-device-info。

在您的app / build.gradle依赖项中尝试以下操作:

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

对我有用。

答案 2 :(得分:0)

这真是个笑话!!!实施此lib非常困难,但是4小时后...

build.gradle项目级别

 dependencies {
            classpath 'com.android.tools.build:gradle:3.3.1'
            classpath 'com.google.gms:google-services:3.2.1'
        }

build.gradle应用程序级别

  dependencies {
        // FIREBASE \\
        implementation 'com.google.firebase:firebase-database:11.4.2'
        implementation 'com.google.firebase:firebase-ads:11.4.2'
        implementation 'com.google.firebase:firebase-auth:11.4.2'
        implementation 'com.google.firebase:firebase-messaging:11.4.2'
        implementation  'com.google.firebase:firebase-core:11.4.2'
        // END \\
        implementation fileTree(dir: "libs", include: ["*.jar"])
        implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
        implementation "com.facebook.react:react-native:+"  // From node_modules
    }

然后最后将樱桃放到顶部:

**MainApplication.java**

     @Override
        protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
                new RNFirebasePackage(),
                  new RNFirebaseDatabasePackage(),
                  new RNFirebaseAnalyticsPackage(),
                  new RNFirebaseAdMobPackage(),
                  new RNFirebaseAuthPackage()
          );
        }

现在您可以使用 react-native-firebase 欢呼。...-.-

import firebase from 'react-native-firebase';
firebase.analytics().logEvent('i_should_just_give_up_in_life');

希望这可以节省您的时间