1

So I've been beating my brain down for over 2 weeks trying to deal with this build error that's effecting my Android app.

Duplicate class com.google.protobuf.AbstractMessageLite found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)

I randomly got this error and have no idea what to do about it anymore. I've looked all around the internet and have tried just about everything that I can think of. I have narrowed it down to Firebase Firestore being the primary issue. My attempts at manually removing the class from the JAR file have failed. I'm kind of just throwing this out here to see if anyone else has experienced this.

Here is my build.gradle file:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.android.gms.oss-licenses-plugin'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
apply plugin: 'project-report'


android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.my.app"
        minSdkVersion 23
        targetSdkVersion 28
        multiDexEnabled true
        compileOptions {
            sourceCompatibility 1.8
            targetCompatibility 1.8
        }

        //Optionally configure your OneSignal IDs below
        manifestPlaceholders = [manifestApplicationId          : "${applicationId}",
                                onesignal_app_id               : "",
                                onesignal_google_project_number: ""]
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }

        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.txt'
        }
    }
    dexOptions {
        jumboMode true
        javaMaxHeapSize "4g"
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
    maven {
        url "https://jitpack.io"
    }
    jcenter()
}

configurations {
    //Exclusions that I've tried
    //implementation.exclude module:'protolite-well-known-types'
    //implementation.exclude module:'guava'
    //implementation.exclude module:'protobuf-javalite'
    //implementation.exclude module:'proto-google-common-protos'
}

dependencies {
    implementation 'com.devbrackets.android:exomedia:4.3.0' //TV
    implementation 'com.google.android.exoplayer:exoplayer:2.9.6' //TV & Radio
    implementation 'com.cleveroad:audiovisualization:1.0.1' //Radio
    implementation 'com.google.code.gson:gson:2.8.5' //WC
    implementation 'com.squareup.okhttp3:okhttp:3.12.1'
    implementation 'org.jsoup:jsoup:1.8.3'
    implementation 'com.onesignal:OneSignal:3.12.0'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.duolingo.open:rtl-viewpager:1.0.2'
    implementation 'com.github.chrisbanes:PhotoView:1.3.0'
    implementation 'androidx.multidex:multidex:2.0.1'

    implementation 'androidx.multidex:multidex-instrumentation:2.0.0'
    implementation 'androidx.exifinterface:exifinterface:1.2.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.google.android.material:material:1.2.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
    implementation 'androidx.media:media:1.1.0'

    implementation "com.google.android.gms:play-services-oss-licenses:17.0.0"
    implementation "com.google.android.gms:play-services-gcm:17.0.0"
    implementation "com.google.android.gms:play-services-ads:19.3.0"
    implementation "com.google.android.gms:play-services-maps:17.0.0"
    //noinspection GradleDynamicVersion
    implementation 'com.google.maps.android:android-maps-utils:0.5+'
    implementation 'com.google.android.gms:play-services-auth:18.1.0'

    implementation 'com.google.firebase:firebase-analytics:17.4.4'
    implementation 'com.google.firebase:firebase-auth:19.3.2'
    implementation ('com.google.firebase:firebase-firestore:21.5.0')
    implementation 'com.google.firebase:firebase-database:19.3.1'
    implementation 'com.google.firebase:firebase-storage:19.1.1'
    implementation 'com.google.firebase:firebase-functions:19.0.2'
    implementation 'com.google.firebase:firebase-messaging:20.2.4'

    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
    implementation 'com.android.billingclient:billing:2.0.3'


    implementation files('libs/YouTubeAndroidPlayerApi.jar')
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'de.hdodenhof:circleimageview:3.0.1'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    implementation 'ja.burhanrashid52:photoeditor:1.0.0'

}

The results from my dependency tree show that Protobuf is only present within the Firebase-Firestore library:

+--- com.google.firebase:firebase-firestore:21.5.0 -> 17.1.5
|    +--- com.google.android.gms:play-services-base:16.0.1 -> 16.1.0 (*)
|    +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    +--- com.google.firebase:firebase-auth-interop:16.0.1 -> 17.0.0 (*)
|    +--- com.google.firebase:firebase-common:16.0.4 -> 17.1.0 (*)
|    +--- com.google.firebase:firebase-database-collection:16.0.1 -> 17.0.1
|    |    \--- com.google.android.gms:play-services-base:17.0.0 -> 16.1.0 (*)
|    +--- com.google.firebase:protolite-well-known-types:16.0.1 -> 17.1.0
|    |    \--- com.google.protobuf:protobuf-javalite:3.11.0
|    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|    +--- com.squareup.okhttp:okhttp:2.7.5
|    |    \--- com.squareup.okio:okio:1.6.0 -> 1.15.0
|    +--- io.grpc:grpc-android:1.16.1
|    |    \--- io.grpc:grpc-core:[1.16.1] -> 1.16.1
|    |         +--- io.grpc:grpc-context:1.16.1
|    |         +--- com.google.code.gson:gson:2.7 -> 2.8.0
|    |         +--- com.google.errorprone:error_prone_annotations:2.2.0
|    |         +--- com.google.code.findbugs:jsr305:3.0.2
|    |         +--- org.codehaus.mojo:animal-sniffer-annotations:1.17
|    |         +--- com.google.guava:guava:26.0-android
|    |         |    +--- org.checkerframework:checker-compat-qual:2.5.2
|    |         |    \--- com.google.j2objc:j2objc-annotations:1.1
|    |         +--- io.opencensus:opencensus-api:0.12.3
|    |         |    \--- com.google.errorprone:error_prone_annotations:2.2.0
|    |         \--- io.opencensus:opencensus-contrib-grpc-metrics:0.12.3
|    |              +--- com.google.errorprone:error_prone_annotations:2.2.0
|    |              \--- io.opencensus:opencensus-api:0.12.3 (*)
|    +--- io.grpc:grpc-okhttp:1.16.1
|    |    +--- io.grpc:grpc-core:[1.16.1] -> 1.16.1 (*)
|    |    +--- com.squareup.okhttp:okhttp:2.5.0 -> 2.7.5 (*)
|    |    \--- com.squareup.okio:okio:1.13.0 -> 1.15.0
|    +--- io.grpc:grpc-protobuf-lite:1.16.1
|    |    +--- io.grpc:grpc-core:1.16.1 (*)
|    |    +--- com.google.protobuf:protobuf-lite:3.0.1
|    |    \--- com.google.guava:guava:26.0-android (*)
|    \--- io.grpc:grpc-stub:1.16.1
|         \--- io.grpc:grpc-core:1.16.1 (*)

But the problem is that I can not exclude it at all. If I do, my app WILL compile but will crash as soon as Firestore needs to be called. Which is as soon as my app starts up.

I just don't get it.

2 Answers2

0

To find out who is using "jetified-protobuf-lite-3.0.1.jar" use this

gradle app:dependencies

Some dependency is still using the old version of protobuf

You can find out here what to do when dependencies are using different version of the same library.

Viatcheslav Ehrmann
  • 716
  • 2
  • 5
  • 11
  • Thank you for your input Viatcheslav. I still haven't solved the issue yet, please see my edit. I pasted the result from dependency tree that contains where the protobuf is being used. – Brandon LaBraun Curry Aug 21 '20 at 20:48
  • @BrandonLaBraunCurry If two different dependencies used protobuf it woul be easy to fix. Just upgrade them both to the newest version or remove one. At this point just try and upgrade all dependencies to the newest version. Sometimes Android Studio doesn't show that there is a new version available. Manually go over every dependency and see if there is a newer version available. Maybe try implementation "com.google.guava:guava:29.0-android" for grpc. – Viatcheslav Ehrmann Aug 22 '20 at 10:16
0
I had the same issue and i zeroed in on the following Cloud Firestore dependency i.e.

implementation 'com.google.firebase:firebase-firestore:22.0.0'

A combination of the above dependency and the below dependencies will cause the error message "**Duplicate Protobuf classes found in modules**"

implementation('com.google.cloud:google-cloud-translate:1.12.0') {
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'org.json', module: 'json'
        exclude group: 'com.google.auto.value', module: 'auto-value'
        exclude group: 'com.google.guava', module: 'listenablefuture'
    }
    annotationProcessor 'com.google.cloud:google-cloud-translate:1.12.0'

By commenting out the above unneeded google-cloud-translate dependency, i was able to successfully have an error FREE build. 
nocholla
  • 122
  • 5