问题
Firestore onSnapshot()和get()导致Android App崩溃.我确信我在编程和设置中没有做错任何事.有人可以告诉我哪里做错了吗?
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
}
的build.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'
的package.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)
Screen Shot Error Crash Analytics
环境
Android的
反应原生0.55.1
react-native-firebase 4.0.0
>应用目标平台:
macOS High Sierra 10.13.3
>开发操作系统:
intelliJ终极
Android(Pixel 2 API 25)
>构建工具:
> React Native版本:
0.55.1
> RNFirebase版本:
“react-native-firebase”:“^ 4.0.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'
For Android Emulator: Google Play Services (Auth) 12.0.1 – Requires
Android 8.1 (Oreo API 27)
如果您偶然感到困惑,请查看react-native-firebase-starter
app/build.gradle
希望这可以帮助.