google-cloud-java: Duplicate classes error when adding dialogflow dependency 0.98.0-alpha along with firebase

i’m getting a duplicate classes error when building with android studio gradle after i added dialogflow to my android app which uses firebase.

DEPENDENCIES: these are my dependencies:

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.3'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
implementation 'com.github.VaibhavLakhera:Circular-Progress-View:0.1.2'
implementation 'com.github.CardinalNow:Android-CircleProgressIndicator:v0.2'
implementation 'ai.api:sdk:2.0.7@aar'
implementation 'ai.api:libai:1.6.12'
implementation 'com.google.cloud:google-cloud-dialogflow:0.98.0-alpha'
implementation 'io.grpc:grpc-okhttp:1.21.0'
implementation 'com.google.apis:google-api-services-oauth2:v2-rev99-1.21.0'
implementation 'com.google.apis:google-api-services-dialogflow:v2beta1-rev9-1.23.0'
implementation 'com.andkulikov:transitionseverywhere:2.0.0-beta01'
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.firebase:firebase-firestore:20.1.0'

STACKTRACE: This is part of the stacktrace as it continues to show duplicate classes arror (com.google.api.***) for another atleast 60 more classes:

Duplicate class com.google.api.Advice found in modules classes.jar (com.google.firebase:protolite-well-known-types:17.0.0) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0) Duplicate class com.google.api.Advice$1 found in modules classes.jar (com.google.firebase:protolite-well-known-types:17.0.0) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0) Duplicate class com.google.api.Advice$Builder found in modules classes.jar (com.google.firebase:protolite-well-known-types:17.0.0) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0) Duplicate class com.google.api.AdviceOrBuilder found in modules classes.jar (com.google.firebase:protolite-well-known-types:17.0.0) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)

UNSUCCESSFUL ATTEMPTS: I have tried exludsing the duplicated classes unsuccessdully using the below methods:

implementation('com.google.cloud:google-cloud-dialogflow:0.93.0-alpha'){ 
exclude group: 'com.google.api.grpc' 
exclude group: 'com.google.protobuf' 
}
implementation('com.google.cloud:google-cloud-dialogflow:0.99.0-alpha'){ 
exclude group: 'com.google.api.' 
}
implementation('com.google.cloud:google-cloud-dialogflow:0.99.0-alpha'){ 
exclude group: 'com.google' , module: 'api'
}
android {
	configurations {

	        all*.exclude group:'com.google.api.Advice', module: 'classes.jar'
	        all*.exclude group: 'com.google.api.Advice', module: 'proto-google-common-protos-1.16.0.jar'

    	}
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 39 (3 by maintainers)

Most upvoted comments

Hey @DavidBuzatu-Marian, thank you so much. This method worked though i had to modify it a little bit. (for those landing on this page in search for a solution to the same problem. post the below code into your build.gradle (module app) file)

android {
    ... 


   configurations {
             implementation.exclude module:'proto-google-common-protos'
             implementation.exclude module:'protolite-well-known-types'
             implementation.exclude module:'guava'
             implementation.exclude module:'protobuf-lite'
    }

}

Let me know if this works for you.

The core of the issue is that protobuf-java and protobuf-lite provide the same classes with different implementations, and that proto-google-common-protos do the same protolite-well-known-types. Firebase pulls in the lite flavor of protobuf whereas google-cloud-java provided libraries pull in the full protobuf-java versions.

Since it appears you are using android, you likely want to keep the protobuf-lite and protolite-well-known-types and excluding protobuf-java and proto-google-common-protos.

Also note that the google-cloud-X libraries are not guaranteed to fully support android at this time although they may in fact work.

@h-amg I managed to exclude the classes, but I have something new in my code, maybe you did it differently and won’t have it.

I added this to gradle (module) just above dependencies:

configurations { implementation.exclude module:‘proto-google-common-protos’ implementation.exclude module:‘protobuf-java’ }

Here’s a great workaround for those who can’t wait for an official fix:

https://github.com/protocolbuffers/protobuf/issues/7094#issuecomment-586532060

The idea behind it is to ‘fatjar’ the proto artifacts in a sequence that overwrites classes that do not work well with firesbase firestore or inappmessaging.

@DavidBuzatu-Marian Nope, not yet. I’ll post an update if i figured it out

I’ve made a stackoverflow post and got a response, but I have an error. Maybe you can figure it out:

https://stackoverflow.com/questions/56922949/resolve-duplicate-classes-with-firebase-and-dialog-flow

@DavidBuzatu-Marian Nope, not yet. I’ll post an update if i figured it out