Elihu Del Valle
Elihu Del Valle

Reputation: 406

Problem using firestore and firebase auth/core all together

I have a problem with my app, whenever I try to add Firestore into it building the gradle works but after I try to run the program it crashes and gives this message:

Error: Program type already present: com.google.common.base.AbstractIterator$State

or

Error: Program type already present: com.google.common.base.Absent

And some other errors of the same type "Error: type already present"

This is my gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myApp.name"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.api-client:google-api-client:1.23.0'
    implementation 'com.google.http-client:google-http-client-gson:1.23.0'
    implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-firestore:17.0.1'
    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'

}

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


configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '28.0.0'
            }
        }

    }
}

I have tried putting all 3 firebase implementations to version 16.0.0 but gives me the same error

The project gradle is the following:

buildscript {

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

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

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

Upvotes: 2

Views: 254

Answers (1)

Elihu Del Valle
Elihu Del Valle

Reputation: 406

If anyone has the same problem as me, this was the solution I found

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '28.0.0'
            }
        }
        if (requested.group == 'com.google.android.gms') {
            details.useVersion '12.0.1'
        }
        if (requested.group == 'com.google.firebase') {
            details.useVersion '12.0.1'
        }
    }
}

Upvotes: 1

Related Questions