Search code examples
javaandroidfirebasegradlefirebaseui

Firebase Dependencies Causing Gradle Build Errors - Program Type Already Present


I have recently updated my Build.Gradle files, and my project is not building successfully. After researching several possible issues, I came across [this post][1] that indicates it may be a conflict with my Firebase dependencies. It could also have to do with multidex, but based on how vague the error is I do not even have a starting point:

Error:

Program type already present: android.arch.core.util.Function   

Build.Gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        vectorDrawables.useSupportLibrary = true
        applicationId "xxxxxxxx"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }

    dexOptions {
        javaMaxHeapSize "4g"

    }

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

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

    // Support library
    implementation "com.android.support:design:27.1.1"
    implementation "com.android.support:cardview-v7:27.1.1"
    implementation "com.android.support:support-v4:27.1.1"
    implementation "com.android.support:appcompat-v7:27.1.1"



            // Firebase
    implementation "com.google.firebase:firebase-storage:16.0.1"
    implementation "com.google.firebase:firebase-core:16.0.0"
    implementation "com.google.firebase:firebase-auth:16.0.1"
    implementation "com.google.android.gms:play-services-auth:15.0.1"
//    implementation "com.google.firebase:firebase-database:$playServicesVersion"
    implementation "com.google.firebase:firebase-appindexing:15.0.1"
    implementation "com.google.firebase:firebase-firestore:17.0.1"
    implementation 'com.firebaseui:firebase-ui-firestore:4.0.0'
    implementation 'com.firebaseui:firebase-ui-database:3.3.1'


    // Third party
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.facebook.android:facebook-android-sdk:4.+'
    implementation 'jp.wasabeef:recyclerview-animators:2.2.3'
    implementation 'com.github.clans:fab:1.6.2'
    implementation 'de.hdodenhof:circleimageview:2.0.0'
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.squareup.okhttp3:okhttp:3.1.2'
    implementation 'com.github.PhilJay:MPAndroidChart:v2.2.2'
    implementation 'com.google.code.gson:gson:2.6.2'
    implementation 'com.squareup.retrofit2:retrofit:2.1.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
    implementation 'com.android.support:multidex:1.0.3'
}

Build.Gradle

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        maven { url 'https://jitpack.io' }
        maven { url "https://maven.google.com" }

        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

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

ext {
    supportLibVersion = "27.1.1"
    playServicesVersion = "17.0.1"
}

Solution

  • Add these dependencies:

    implementation "android.arch.core:runtime:$version"
    implementation "android.arch.core:common:$version"
    

    You can find more info here: https://github.com/firebase/FirebaseUI-Android/issues/1357