4

问题

FirestoreonSnapshot()get()导致 Android 应用程序崩溃。我确信我在编程和设置中没有做错任何事情。有人可以告诉我我在哪里做错了吗?

try {
    const ref = firebase.firestore().collection(`test/${someId}/child`)

    this.unsubscribe = ref.onSnapshot(querySnapshot => {
        let list = []
        querySnapshot.forEach(doc => {

        }, error => console.error('error') // Error is not being caught)
} catch (e) {
    console.error(e) // error is not being caught
}

构建.gradle

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

buildscript {
    repositories {
        jcenter()
        google()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        classpath 'com.google.gms:google-services:3.1.2'
        classpath 'io.fabric.tools:gradle:+'
        classpath 'com.google.firebase:firebase-plugins:1.1.1'

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

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

        maven {
            url 'https://maven.google.com'
        }

        maven {
            url 'https://maven.fabric.io/public'
        }
    }
}

应用程序/build.gradle

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

import com.android.build.OutputFile

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

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

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    signingConfigs {
        debug {
            keyAlias 'debug'
            keyPassword 'android'
            storeFile file('debug.keystore')
            storePassword 'android'
        }
    }
    compileSdkVersion 23
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "..."
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // 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]
            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-firebase')) {
        transitive = false
    }
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:23.0.1'
    implementation 'com.facebook.react:react-native:+'
    // From node_modules
    implementation(project(':react-native-google-signin')) {
        exclude group: "com.google.android.gms" // very important
    }
    implementation 'com.google.android.gms:play-services-base:11.8.0'
    implementation 'com.google.android.gms:play-services-auth:11.8.0'

    implementation 'com.google.firebase:firebase-core:11.8.0'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation "com.google.firebase:firebase-firestore:11.8.0"
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true
    }
    implementation 'com.google.firebase:firebase-crash:11.8.0'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    implementation 'com.google.firebase:firebase-invites:11.8.0'
    implementation 'com.google.firebase:firebase-perf:11.8.0'
}

task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

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

包.json

{
  "name": "TokoDemo",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "base-64": "^0.1.0",
    "native-base": "^2.4.1",
    "numeral": "^2.0.6",
    "prop-types": "^15.6.1",
    "react": "16.3.1",
    "react-native": "0.55.1",
    "react-native-easy-grid": "^0.1.17",
    "react-native-firebase": "^4.0.0",
    "react-native-google-signin": "^0.12.0",
    "react-redux": "^5.0.7",
    "react-router": "^4.2.0",
    "react-router-native": "^4.2.0",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0",
    "shortid": "^2.2.8"
  },
  "devDependencies": {
    "babel-jest": "22.4.3",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.4.3",
    "react-test-renderer": "16.3.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

崩溃分析错误

Fatal Exception: java.lang.NoSuchMethodError
No virtual method getDocument()Lcom/google/firebase/firestore/QueryDocumentSnapshot; in class Lcom/google/firebase/firestore/DocumentChange; or its super classes (declaration of 'com.google.firebase.firestore.DocumentChange' appears in /data/app/io.zeven.toko.demo-2/base.apk)

io.invertase.firebase.firestore.FirestoreSerialize.documentChangeToWritableMap (FirestoreSerialize.java:129)
io.invertase.firebase.firestore.FirestoreSerialize.documentChangesToWritableArray (FirestoreSerialize.java:103)
io.invertase.firebase.firestore.FirestoreSerialize.snapshotToWritableMap (FirestoreSerialize.java:73)
io.invertase.firebase.firestore.RNFirebaseFirestoreCollectionReference.handleQuerySnapshotEvent (RNFirebaseFirestoreCollectionReference.java:246)
io.invertase.firebase.firestore.RNFirebaseFirestoreCollectionReference.access$000 (RNFirebaseFirestoreCollectionReference.java:32)
io.invertase.firebase.firestore.RNFirebaseFirestoreCollectionReference$2.onEvent (RNFirebaseFirestoreCollectionReference.java:85)
io.invertase.firebase.firestore.RNFirebaseFirestoreCollectionReference$2.onEvent (RNFirebaseFirestoreCollectionReference.java:81)
com.google.firebase.firestore.zzi.onEvent (Unknown Source)
com.google.android.gms.internal.zzevc.zza (Unknown Source)
com.google.android.gms.internal.zzevd.run (Unknown Source)
android.os.Handler.handleCallback (Handler.java:751)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6119)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:886)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:776)

屏幕截图错误崩溃分析

环境

Android react-native 0.55.1 react-native-firebase 4.0.0

  1. 应用目标平台:macOS High Sierra 10.13.3

  2. 开发操作系统:intelliJ Ultimate Android (Pixel 2 API 25)

  3. 构建工具:

  4. 反应原生版本:0.55.1

  5. RNFirebase 版本:“react-native-firebase”:“^4.0.0”,

4

1 回答 1

0

我没有找到这个问题的答案。

但是我只是将它升级RNFirebase到 12.0.1,它在升级后就可以工作了

这是我的新app/build.gradle

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

import com.android.build.OutputFile

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

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

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    signingConfigs {
        debug {
            keyAlias 'debug'
            keyPassword 'android'
            storeFile file('debug.keystore')
            storePassword 'android'
        }
    }
    compileSdkVersion 27

    defaultConfig {
        applicationId "..."
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }

        // TODO because of firestore: recheck for the next update
        multiDexEnabled true
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // 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]
            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-firebase')) {
        transitive = false
    }
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.facebook.react:react-native:+'

    // From node_modules
    implementation(project(':react-native-google-signin')) {
        exclude group: "com.google.android.gms" // very important
    }

    // RNFirebase required dependencies
    implementation "com.google.firebase:firebase-core:12.0.1"
    implementation "com.google.android.gms:play-services-base:12.0.1"
    implementation "com.google.android.gms:play-services-auth:12.0.1"

    // RNFirebase optional dependencies
    implementation "com.google.firebase:firebase-ads:12.0.1"
    implementation "com.google.firebase:firebase-auth:12.0.1"
    implementation "com.google.firebase:firebase-config:12.0.1"
    implementation "com.google.firebase:firebase-database:12.0.1"
    implementation "com.google.firebase:firebase-invites:12.0.1"
    implementation "com.google.firebase:firebase-firestore:12.0.1"
    implementation "com.google.firebase:firebase-messaging:12.0.1"
    implementation "com.google.firebase:firebase-perf:12.0.1"
    implementation "com.google.firebase:firebase-storage:12.0.1"

    implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true
    }
}

// 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'

对于 Android 模拟器:Google Play 服务 (Auth) 12.0.1 - 需要 Android 8.1 (Oreo API 27)

如果您仍然感到困惑,请查看react-native-firebase-starter app/build.gradle

希望这可以帮助。

于 2018-04-10T05:28:53.160 回答