Build fails with 'Program type already present: android.arch.core.util.Function'

I found the solution which some great guy posted on GitHub. Instead of downgrading your firebaseUI database, you can add arch common and runtime dependencies which are these:

//Arch
    implementation "android.arch.core:runtime:1.1.1"
    implementation "android.arch.core:common:1.1.1"

Just add these in your app: module dependencies section and you know build it.


My project works with the latest version of firebase core, database, messaging and auth dependencies and latest classpath 'com.google.gms:google-services:4.0.1'

App/build.gradle

dependencies {

    // Tab Layout and ViewPager
    implementation 'com.android.support:design:27.1.1'

    // firebase dependencies
    // implementation 'com.firebaseui:firebase-ui-database:4.0.0' Source of error
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
}

build.gradle

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

The problem evolves when adding implementation 'com.firebaseui:firebase-ui-database:4.0.0'

It shows this error:

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

Message{kind=ERROR, text=Program type already present: android.arch.core.util.Function, sources=[Unknown source file], tool name=Optional.of(D8)}

The solution was to downgrade implementation 'com.firebaseui:firebase-ui-database:4.0.0' to implementation 'com.firebaseui:firebase-ui-database:3.3.1' as follows:

App/build.gradle

dependencies {

    // Tab Layout and ViewPager
    implementation 'com.android.support:design:27.1.1'

    // firebase dependencies
    implementation 'com.firebaseui:firebase-ui-database:3.1.1' // No trouble in compiling
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
}

I hope Google will solve this issue in future updates.

Hope that helped!