[英]Android Error: Firebase Database component is not present
I have integrated a firebase real-time database in my app and I am getting a我在我的应用程序中集成了一个 firebase 实时数据库,我得到了一个
java.lang.NullPointerException: Firebase Database component is not present
when I try to create an instance of a firebase database with the code below,当我尝试使用以下代码创建 firebase 数据库的实例时,
FirebaseApp firebaseApp = FirebaseApp.initializeApp(this);
mFirebaseInstance = FirebaseDatabase.getInstance(firebaseApp);
I also tried this,我也试过这个,
mFirebaseInstance = FirebaseDatabase.getInstance();
Every time getting error Firebase Database component is not present.
每次出现错误Firebase Database component is not present.
Below is project gradle file code:以下是项目gradle文件代码:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
//classpath 'com.google.gms:google-services:4.2.0'
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 {
mavenCentral()
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Below are dependency which I have added Dependencies :以下是我添加的依赖项 Dependencies :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
//implementation 'com.android.support:design:28.0.0'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// Firebase
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'android.arch.work:work-runtime:1.0.1'
// Firebase real time databse
implementation 'com.google.firebase:firebase-database:17.0.0'
// Glide
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
// Link preview
implementation 'io.github.ponnamkarthik:richlinkpreview:1.0.9'
implementation 'org.jsoup:jsoup:1.10.2'
// Piccaso
implementation 'com.squareup.picasso:picasso:2.71828'
//AdMob
implementation 'com.google.android.gms:play-services-ads:18.0.0'
// Needed to fix a dependency conflict with FirebaseUI'
implementation 'androidx.arch.core:core-runtime:2.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
}
apply plugin: 'com.google.gms.google-services'
I also tried to change the database dependency version, change class path and update google-services.json
file but I am still facing the same error.我还尝试更改数据库依赖项版本、更改类路径并更新google-services.json
文件,但我仍然面临同样的错误。
只需删除包的android和ios文件夹并键入
flutter create .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.