Android错误:Firebase数据库组件不存在

时间:2019-06-27 11:27:24

标签: android firebase firebase-realtime-database

我已经在我的应用程序中集成了一个firebase实时数据库,并且我得到了

java.lang.NullPointerException: Firebase Database component is not present

当我尝试使用以下代码创建Firebase数据库的实例时,

FirebaseApp firebaseApp = FirebaseApp.initializeApp(this);
mFirebaseInstance = FirebaseDatabase.getInstance(firebaseApp);

我也尝试过这个

mFirebaseInstance = FirebaseDatabase.getInstance();

每次遇到错误Firebase Database component is not present.

下面是项目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
}

下面是我添加的依赖项 依赖项:

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'

我还尝试更改数据库依赖版本,更改类路径并更新google-services.json文件,但仍然遇到相同的错误。

1 个答案:

答案 0 :(得分:1)

只需删除该软件包的android和ios文件夹并输入

flutter create .