Chetan
Chetan

Reputation: 5095

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

I am extremely new to android and trying the firebase where i am trying out firebase auth and firebase database.

I could successfully complete the auth functionality and below is the gradle file contents for app module just after it.

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'

Now for the next step i want to use firebase database in the same project and i update the gradle file by adding the dependency

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

As soon as i do it and start the sync i get the following error

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

Below is the code for my project gradle file.

// 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
}

I tried to update the google service version in the project gradle file but then ran into other issues. As i am new to android and trying things out i am stuck and not able to figure out currently how to resolve this. Can anyone guide me or help me?

project Structure

Upvotes: 6

Views: 34712

Answers (4)

Ninja
Ninja

Reputation: 698

Try this

Go to project level build.gradle & check if it looks exactly like this:

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

set same dependency for both

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

Upvotes: 5

Makvin
Makvin

Reputation: 3629

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'

Upvotes: 1

ILYAS_Kerbal
ILYAS_Kerbal

Reputation: 1445

Try this: Build > Edit Libraries and Dependencies...

enter image description here enter image description here


Now, search for available modules:

enter image description here

Upvotes: 3

Alex
Alex

Reputation: 3382

You have to use the same versions of firebase. You used version 9.0.2 of auth and 9.6.1 of database.

Also I suggest to use the latest version of the firebase SDK

Add

com.google.firebase:firebase-auth:11.0.4
com.google.firebase:firebase-database:11.0.4

Upvotes: 0

Related Questions