本文介绍了HostObject :: get(propName:RNfirebase)中的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习如何使用react-native(Android)实现Firestore.然后,我找到了"react-native-firebase",并陷入了这种异常.
I am learning how to implement Firestore with react-native(Android). Then, I found 'react-native-firebase' and stuck in this exception.
Error:Exception in
HostObject::get(propName:RNFirebase):
java.lang.NoClassDefFoundError: Failed resolution
of: Lcom/google/firebase/FirebaseApp;
我已经在gradle中设置了Firebase(参考 https://firebase.google.com/docs/android/setup/?authuser = 0 )
Firebase数据库的规则
I already setup firebase in my gradle (ref.https://firebase.google.com/docs/android/setup/?authuser=0)
Firebase database's rule
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
这是我的学习代码(ref. https://www.youtube.com/观看?v = _GOI7h9ojr8 )
and this is my learning code (ref.https://www.youtube.com/watch?v=_GOI7h9ojr8)
import React,{ Component } from 'react';
import {
Flatlist,
Text,
TextInput,
TouchableHighlight,
Image,
View } from 'react-native';
import firebase from 'react-native-firebase';
export default class test extends Component {
constructor(props){
super(props);
this.state = ({
todoTask: [],
newTaskName: '',
loading: false
});
this.ref = firebase.firestore().collection('todo');
}
onPressAdd = () => {
this.ref.add({
taskName: this.state.newTaskName
}).then((data) => {
console.log('added data = ${data}');
this.setState({
newTaskName: '',
loading: true
});
}).catch((error) => {
console.log('error adding firestore document = ${error}');
this.setState({
newTaskName: '',
loading: true
});
});
}
render(){
return (
<View style={{flex: 1}}>
<Text>Hello</Text>
<TextInput style={{
height: 40,
width: 200,
margin: 10,
padding: 10,
borderColor: 'white',
borderWidth: 1,
color: 'white'
}}
keyboardType='default'
placeholderTextColor='white'
placeholder='Enter task name'
onChangeText={
(text) => {
this.setState({ newTaskName: text});
}
}
>
</TextInput>
<TouchableHighlight
style={{ marginRight: 10 }}
underlayColor='tomato'
onPress={this.onPressAdd}>
<Image
style={{ width: 35, height: 35 }}
source={require('./icon-add.png')}
>
</Image>
</TouchableHighlight>
<Flatlist
data={this.state.todoTask}
renderItem={({item, index}) => {
return(
<Text>{item.taskName}</Text>
);
}}
>
</Flatlist>
</View>
);
}
}
你能解释为什么会发生吗?非常感谢.
Can u explain why it happen? Thanks a lot.
推荐答案
You installed 'react-native-firebase' package so kindly note to remove(uninstall) it.
According to the docs:
First you need to install firebase package:
npm install --save firebase
Then import it using firebase/app:
// Firebase App (the core Firebase SDK) is always required and
// must be listed before other Firebase SDKs
import * as firebase from "firebase/app";
这篇关于HostObject :: get(propName:RNfirebase)中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!