简体   繁体   English

安装Firebase和地图后,应对本机致命错误和应用程序崩溃

[英]React native fatal error and app crashing after installing firebase and maps

I'm creating a simple app that will use react-native-firebase and react-native-maps. 我正在创建一个简单的应用程序,它将使用react-native-firebase和react-native-maps。 I had the maps up and running with no issues following the documentation for installation. 按照安装文档的说明,我已经启动并运行了地图,没有任何问题。 Following I have installed Firebase and have also followed the tutorial. 接下来,我已经安装了Firebase,并且还遵循了该教程。 I ran into several errors on the way, but cleaning up gradle build etc eventually got me the "build successful" message. 我在途中遇到了一些错误,但是清理gradle build等最终使我得到了“ build success”的信息。 However the app keeps on crashing on start. 但是,该应用在启动时始终崩溃。 The logcat from Android Studio points out this error: Android Studio的logcat指出了此错误:

 FATAL EXCEPTION: create_react_context
Process: com.demoapp, PID: 13267
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzbfm;
    at com.airbnb.android.react.maps.MapsPackage.createViewManagers(MapsPackage.java:39)
    at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:770)
    at com.facebook.react.CoreModulesPackage.createUIManager(CoreModulesPackage.java:170)
    at com.facebook.react.CoreModulesPackage.access$200(CoreModulesPackage.java:53)
    at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:128)
    at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:125)
    at com.facebook.react.LazyReactPackage$2$1.next(LazyReactPackage.java:102)
    at com.facebook.react.LazyReactPackage$2$1.next(LazyReactPackage.java:89)
    at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:44)
    at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1212)
    at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1182)
    at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1120)
    at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:123)
    at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:943)
    at java.lang.Thread.run(Thread.java:764)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.internal.zzbfm" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/base.apk"],nativeLibraryDirectories=[/data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/lib/x86, /data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/base.apk!/lib/x86, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)

And here is my build.gradle 这是我的build.gradle

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 27
        supportLibVersion = "28.0.0"
        googlePlayServicesVersion = "11.8.0"
        androidMapsUtilsVersion = "0.5+"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
         classpath 'com.google.gms:google-services:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}



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

 apply plugin: 'com.google.gms.google-services'

In case it's necessary here is also my package-json file with all the versions of libraries I am using: 如果有必要,这也是我的package-json文件,其中包含我正在使用的所有版本的库:

{
  "name": "DemoApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.6.3",
    "react-native": "0.58.4",
    "react-native-firebase": "^5.2.2",
    "react-native-gesture-handler": "^1.0.15",
    "react-native-maps": "^0.23.0",
    "react-navigation": "^3.2.1"
  },
  "devDependencies": {
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "24.1.0",
    "jest": "24.1.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
  },
  "jest": {
    "preset": "react-native"
  }
}

Any help would be appreciated! 任何帮助,将不胜感激! Is it a wrong google play services version? Google Play服务版本错误吗? What could be causing this issue? 是什么导致此问题?

Edit: Full error log of after adding multidex. 编辑:添加multidex后的完整错误日志。 The device is connected and you can see it after running adb devices from the cmd. 设备已连接,从cmd运行adb设备后即可看到它。

    Building and installing the app on the device (cd android && gradlew.bat installDebug)...

> Configure project :
Warning: Please apply google-services plugin at the bottom of the build file.

> Configure project :react-native-firebase
react-native-firebase: using React Native prebuilt binary from C:\workspace\copleybros\DemoApp\node_modules\react-native\android

> Task :app:compileDebugJavaWithJavac
C:\workspace\copleybros\DemoApp\android\app\src\main\java\com\demoapp\MainApplication.java:4: error: cannot find symbol
import android.app.MultiDexApplication;
                  ^
  symbol:   class MultiDexApplication
  location: package android.app
C:\workspace\copleybros\DemoApp\android\app\src\main\java\com\demoapp\MainApplication.java:17: error: cannot find symbo
public class MainApplication extends MultiDexApplication implements ReactApplication {
                                     ^
  symbol: class MultiDexApplication
C:\workspace\copleybros\DemoApp\android\app\src\main\java\com\demoapp\MainApplication.java:19: error: incompatible types: MainApplication cannot be converted to Application
  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
                                                                       ^
C:\workspace\copleybros\DemoApp\android\app\src\main\java\com\demoapp\MainApplication.java:19: error: cannot find symbol  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
                                                   ^
  symbol: constructor (MainApplication)
C:\workspace\copleybros\DemoApp\android\app\src\main\java\com\demoapp\MainApplication.java:46: error: method does not override or implement a method from a supertype
  @Override
  ^
C:\workspace\copleybros\DemoApp\android\app\src\main\java\com\demoapp\MainApplication.java:48: error: cannot find symbol    super.onCreate();
    ^
  symbol:   variable super
  location: class MainApplication
C:\workspace\copleybros\DemoApp\android\app\src\main\java\com\demoapp\MainApplication.java:49: error: no suitable method found for init(MainApplication,boolean)
    SoLoader.init(this, /* native exopackage */ false);
            ^
    method SoLoader.init(Context,int) is not applicable
      (argument mismatch; MainApplication cannot be converted to Context)
    method SoLoader.init(Context,boolean) is not applicable
      (argument mismatch; MainApplication cannot be converted to Context)
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
7 errors


    > Task :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 9s
48 actionable tasks: 1 executed, 47 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

Command failed: gradlew.bat installDebug

Error: Command failed: gradlew.bat installDebug
    at checkExecSyncError (child_process.js:601:13)
    at Object.execFileSync (child_process.js:621:13)
    at runOnAllDevices (C:\workspace\copleybros\DemoApp\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
    at buildAndRun (C:\workspace\copleybros\DemoApp\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)    at isPackagerRunning.then.result (C:\workspace\copleybros\DemoApp\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.internal.zzbfm" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/base.apk"],nativeLibraryDirectories=[/data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/lib/x86, /data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/base.apk!/lib/x86, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)

This line suggests that it could be a Dex issue. 这行提示可能是Dex问题。 You should enable multidex support for your app. 您应该为您的应用启用multidex支持。

In your dependencies in your app/build.gradle you must add: app/build.gradle依赖项中,您必须添加:

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}

In your app/build.gradle you need to set the following in your defaultConfig 在您的app/build.gradle您需要在defaultConfig中设置以下内容

android {
    defaultConfig {
        ...
        multiDexEnabled true
    }
    ...
}

And finally you will need to extend MultiDexApplication in your MainApplication.java like this: 最后,你需要扩展MultiDexApplicationMainApplication.java这样的:

public class MainApplication extends MultiDexApplication implements ReactApplication {

To read more about multidex you can check the documentation here . 要阅读有关multidex的更多信息,可以在此处查看文档。

Update 更新资料

Looking at your updated error message it seems like you are importing MultiDexApplication wrongly in your MainApplication.java 查看更新的错误消息,似乎您在MultiDexApplication错误地导入了MainApplication.java

> Task :app:compileDebugJavaWithJavac
C:\workspace\copleybros\DemoApp\android\app\src\main\java\com\demoapp\MainApplication.java:4: error: cannot find symbol
import android.app.MultiDexApplication;
                  ^
  symbol:   class MultiDexApplication
  location: package android.app

Currently you have it as 目前你有

import android.app.MultiDexApplication;

But it should be 但这应该是

import android.support.multidex.MultiDexApplication;

Most of the developer in React Native and Flutter are facing issue due to Android X . 由于Android X,React Native和Flutter中的大多数开发人员都面临着问题。 You may go through this https://developer.android.com/jetpack/androidx/migrate 您可以通过以下https://developer.android.com/jetpack/androidx/migrate

or you may go with library and build tool version related to 27 not 28. 或者您可以使用库并构建与27而不是28相关的工具版本。

So in the end this is what solved the problem: downgrading those to 15.0.0 最终,这就是解决问题的方法:将其降级为15.0.0

  implementation "com.google.android.gms:play-services-base:15.0.0"
  implementation "com.google.firebase:firebase-core:15.0.0"

and using 和使用

 googlePlayServicesVersion = "15.0.1"

also, at the very bottom of build.gradle 同样,在build.gradle的最底部

 com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

Only all of this combined with Andrew's and Sanjeev's answers got me there. 只有所有这些结合安德鲁(Andrew)和桑耶夫(Sanjeev)的答案,我才能到达那里。 Thanks to both of you for your input! 感谢你们双方的投入!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 安装react-native-firebase后,React Native Android应用程序崩溃 - React Native Android app crashes after installing react-native-firebase 应用程序继续停止响应本机地图和响应本机Firebase - App keep stopping in react native maps and react native firebase React Native Android 应用程序因“E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules”而崩溃 - React Native Android App crashing with “E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules” React Native:应用程序未加载,但没有错误消息,安装后 react-navigation - React Native: app doesn't load, but no error messages, after installing react-navigation React Native App 打开后一直关闭而不会崩溃 - React Native App keeps closing after opening it without crashing 尝试共享 Android 后 react-native-share 应用程序崩溃 - react-native-share App crashing after trying to share Android 在React Native中安装Native Module后无法构建应用程序吗? - App not building after installing Native Module in React Native? react-native-camera:Android 应用程序崩溃而没有错误 - react-native-camera: Android app crashing without error 使用 Android 仿真器响应本机应用程序崩溃而没有错误 - React Native App Crashing With Android Emulator Without Error React-native 应用程序在 android 工作室中崩溃且没有错误 - React-native app is crashing without error in android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM