0
votes

I added firebase to android. It used to work fine but after pulling from github it shows the errors below:

Duplicate class com.google.android.gms.measurement.AppMeasurement found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.2.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1) Duplicate class com.google.firebase.analytics.FirebaseAnalytics found in modules classes.jar (com.google.android.gms:play-services-measurement-api:17.2.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1) Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Event found in modules classes.jar (com.google.android.gms:play-services-measurement-api:17.2.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1) Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Param found in modules classes.jar (com.google.android.gms:play-services-measurement-api:17.2.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1) Duplicate class com.google.firebase.analytics.FirebaseAnalytics$UserProperty found in modules classes.jar (com.google.android.gms:play-services-measurement-api:17.2.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)

I tried deleting a few lines in gradle file but it doesn't seem to work.

My gradle file is:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.example.agrismart"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.firebaseui:firebase-ui-database:6.0.2'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation'com.google.firebase:firebase-auth:18.1.0'

    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation 'com.google.firebase:firebase-database:19.1.0'
    implementation 'com.google.firebase:firebase-core:15.0.0'

    implementation 'com.firebase:firebase-client-android:2.4.0'
    implementation 'com.google.android.gms:play-services:10.0.1'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

How can I resolve these problems?

1
this build.gradle is a mess and also uses age-old versions mixed with new versions. - Martin Zeitler
Try using the latest versions and remove implementation 'com.firebase:firebase-client-android:2.4.0'. - Alex Mamo
@AlexMamo I was merely referring to play-services:10.0.1 and apply plugin: 'com.android.application' probably should be on top... also the conflict hints for duplicate play-services pulled in due to version mismatch. - Martin Zeitler
@MartinZeitler Totally agree ;) - Alex Mamo

1 Answers

1
votes

Update the following:

    implementation 'com.google.firebase:firebase-core:15.0.0'

into this:

    implementation 'com.google.firebase:firebase-core:17.2.0'

Remove the following dependency:

    implementation 'com.firebase:firebase-client-android:2.4.0'

Since this is used in the old firebase version.

According to the docs:

Note: Don't use the combined play-services target. It brings in dozens of libraries, bloating your application. Instead, specify only the specific Google Play services APIs your app uses.

Therefore remove:

    implementation 'com.google.android.gms:play-services:10.0.1'

And use the specific service that you need in the app (Also use the versions found in the following page):

https://developers.google.com/android/guides/setup