应用程序崩溃启动后在android

时间:2018-04-21 07:28:56

标签: android react-native react-native-firebase

将react-native firebase插件添加到我的本机应用程序后,我的应用程序在启动时崩溃。

我正在使用 RN 0.51, gradle 2.2.3& 2.14.1

dependencies {
compile project(':react-native-config')
compile project(':react-native-code-push')
compile (project(':react-native-camera')) {
    exclude group: "com.android.support"
}

编译“com.android.support:exifinterface:26.1.0”

compile project(':react-native-beacons-manager')
//compile project(':react-native-google-places')
compile project(':react-native-device-info')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+"  // From node_modules
 compile 'com.android.support:multidex:1.0.1'

compile project(':react-native-fcm')
compile 'com.google.firebase:firebase-core:10.0.1' //this decides your firebase SDK version
compile 'com.google.firebase:firebase-messaging:10.0.1'

      compile project(':react-native-bluetooth-status')

   compile project(':react-native-beacons-manager')
compile project(':react-native-vector-icons')

}

这些是我在项目中的插件。在新的gradle版本中,我的所有插件都已过时,所以我降级了gradle。我尝试了一切,但仍然我的应用程序崩溃,我得到相同的错误。请帮帮我..谢谢

这是我的错误日志

 FATAL EXCEPTION: main Process: com.spazebudenterprise, PID: 8089
                                              java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbp;
                                                     at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
                                                     at android.app.ActivityThread.installProvider(ActivityThread.java:6057)
                                                     at android.app.ActivityThread.installContentProviders(ActivityThread.java:5628)
                                                     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5567)
                                                     at android.app.ActivityThread.-wrap2(ActivityThread.java)
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1625)
                                                     at android.os.Handler.dispatchMessage(Handler.java:110)
                                                     at android.os.Looper.loop(Looper.java:203)
                                                     at android.app.ActivityThread.main(ActivityThread.java:6339)
                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
                                                  Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzbp" on path: DexPathList[[zip file "/data/app/com.spazebudenterprise-1/base.apk"],nativeLibraryDirectories=[/data/app/com.spazebudenterprise-1/lib/arm, /data/app/com.spazebudenterprise-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
                                                     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                     at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                     at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

2 个答案:

答案 0 :(得分:1)

确保您已将Google导入导入Gradle插件并且已更新,即版本15.0.0

https://rnfirebase.io/docs/v4.0.x/installation/android

项目build.gradle文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'
        classpath 'com.google.gms:google-services:3.2.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}



allprojects {
    repositories {


        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }

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

app build.gradle文件

dependencies {

    implementation(project(':react-native-firebase')) {
        transitive = false
    }

    implementation("com.google.android.gms:play-services-base:15.0.0") {
        force = true
    }

    implementation 'com.google.firebase:firebase-core:15.0.0'

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:27.1.1"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

/* add the following to the VERY BOTTOM of your app android/app/build.gradle file */
apply plugin: 'com.google.gms.google-services'
gradle-wrapper.properties

下找到

project_name\android\gradle\wrapper

#Fri Mar 02 12:52:38 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

在终端 cd android后跟gradlew clean.\gradlew clean(不确定斜线,它可能是/或是两者)然后cd ..react-native run-android

答案 1 :(得分:0)

最后我解决了这个问题。 问题是react-native-fcm,react-native-camera,react-native-device-info,react-native-google-places之间的谷歌服务版本冲突。

我取代了 react-native-camera to react-native-camera-kit,  react-native-device-info用于响应本机设备信息 我将google-places插件中的google play服务更改为

n! = n * (n - 1)!