无法在我的 android 应用程序上实现 firebase 依赖项

时间:2021-05-31 13:14:25

标签: java android database firebase dependencies

我正在开发一个 Android Studio 应用程序并尝试创建一个用户注册活动。我已经将 firebase 添加到项目中,但是当我尝试添加 firebase 数据库依赖项时,应用程序立即崩溃并且没有报告任何错误。但是,当我从构建 gradle 中删除 3 个工具时,它运行正常。在这里,我留下了两个构建 gradle 代码。谢谢。

构建 gradle 项目:

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

buildscript {
    
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.4'
        classpath 'com.google.gms:google-services:4.3.8'

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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

构建 gradle 应用程序(这可以正常工作):

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

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.jota02"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    //new implements
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'com.google.android.material:material:1.4.0-beta01'
    implementation platform('com.google.firebase:firebase-bom:28.0.1')
}

构建 gradle 应用程序(此崩溃):

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

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.jota02"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    //new implements
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'com.google.android.material:material:1.4.0-beta01'
    implementation platform('com.google.firebase:firebase-bom:28.0.1')
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.firebase:firebase-core:19.0.0'
    implementation 'com.google.firebase:firebase-database:20.0.0'
}

已解决

问题只是我运行的是旧的 Android Studio 版本。我更新了 Android Studio 并检查了 gradle 版本,现在一切正常,谢谢。

1 个答案:

答案 0 :(得分:1)

当您使用 firebase-bom 依赖项时,您无需提及 firebase-database 和其他 Firebase 库的版本。

firebase-bom 会为你选择合适的版本,或者如果你想要特定版本的 firebase 删除 firebase-bom.so 添加如下依赖

 // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:28.0.1')

   
    // When using the BoM, you don't specify versions in Firebase library dependencies
     implementation 'com.google.firebase:firebase-auth'
     implementation 'com.google.firebase:firebase-core'
     implementation 'com.google.firebase:firebase-database'
相关问题