繁体   English   中英

如何在android for Firedle for gradle中为数据库和auth一起添加依赖项?

[英]How to add dependencies in gradle file in android for Firebase for database and auth together?

我是非常新的android并尝试firebase我正在尝试firebase auth和firebase数据库。

我可以成功完成auth功能,下面是app模块的gradle文件内容。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    defaultConfig {
        applicationId "com.cirvi.laxmimobileshopee"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'


    compile "com.google.firebase:firebase-auth:9.0.2"

    testCompile 'junit:junit:4.12'
}

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

现在,对于下一步,我想在同一个项目中使用firebase数据库,并通过添加依赖项来更新gradle文件

compile 'com.google.firebase:firebase-database:9.6.1'

一旦我这样做并开始同步我得到以下错误

Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]
Error:Execution failed for task ':app:processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.6.1.
Information:BUILD FAILED
Information:Total time: 2.86 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

下面是我的项目gradle文件的代码。

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

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

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

allprojects {
    repositories {
        jcenter()
    }
}

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

我尝试更新项目gradle文件中的google服务版本,但后来遇到了其他问题。 由于我是Android的新手,并尝试了一些事情,我陷入困境,目前无法弄清楚如何解决这个问题。 任何人都可以指导我或帮助我吗?

项目结构

试试这个

转到项目级build.gradle并检查它是否完全如下所示:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

为两者设置相同的依赖

implementation "com.google.firebase:firebase-auth:9.6.1"
implementation 'com.google.firebase:firebase-database:9.6.1'

试试这个: Build> Edit Libraries and Dependencies ...

在此输入图像描述 在此输入图像描述


现在,搜索可用的模块:

在此输入图像描述

您必须使用相同版本的firebase。 您使用的是版本9.0.2的auth和9.6.1的数据库。

另外我建议使用最新版本的firebase SDK

com.google.firebase:firebase-auth:11.0.4
com.google.firebase:firebase-database:11.0.4
Add this dependency from your needs

implementation 'com.google.firebase:firebase-messaging:17.3.0'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-database:16.0.1'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM