Repository navigation
Description
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'
}
}
Activity
h-amg commentedon Jul 1, 2019
I have narrowed down cause of the duplication to firestore dependency (com.google.firebase:firebase-firestore:20.1.0) and dialogflow dependency (implementation 'com.google.cloud:google-cloud-dialogflow:0.98.0-alpha)
h-amg commentedon Jul 3, 2019
Hi @sduskis, I till haven't figured out a way to sort this issue, do you have any tip on anything i should try?
h-amg commentedon Jul 6, 2019
Hi @android10, I'd really appreciate your input on this. any thoughts on how to solve this problem?
DavidBuzatu-Marian commentedon Jul 7, 2019
@h-amg I have the exact same problem as you and I tried all the steps you said. Still, it doesn't work. Did you find a workaround?
h-amg commentedon Jul 7, 2019
@DavidBuzatu-Marian Nope, not yet. I'll post an update if i figured it out
DavidBuzatu-Marian commentedon Jul 7, 2019
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
h-amg commentedon Jul 7, 2019
@DavidBuzatu-Marian The snippet lance provided is unnecessary since android studio lists all the duplicate classes and jars where they are located in the build window (part of which is included in my post above under "stacktrace"), in other words there is a similar script built into android studio that does this. The challenge is how to exclude the duplicate classes?
DavidBuzatu-Marian commentedon Jul 8, 2019
@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'
}
h-amg commentedon Jul 9, 2019
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)
Let me know if this works for you.
20 remaining items
shiran82 commentedon Aug 7, 2019
I have the same issue, @h-amg I added what you suggested and there are no duplicates, however i still get: Verifier rejected class com.google.firestore.v1.WriteResponse
I tried adding protobuf 'com.google.protobuf:protobuf-java:3.6.1' and it works but then when i try to build in release mode it doesn't compile
Any suggestions?
h-amg commentedon Aug 8, 2019
@shiran82 yeah thats what i got too, unfortunate i could't figure out how to get it to work. The fact is dialogflow is not supported for android so you are pretty much on your own. i ended switching to mongodb stitch.
carlosrsabreu commentedon Dec 27, 2019
@h-amg did you tried to use the Realtime Database instead of the Cloud Firestore? It's working fine on my project and doesn't give the errors that you have: duplicate classes.
kaniundungu commentedon Feb 15, 2020
Here's a great workaround for those who can't wait for an official fix:
protocolbuffers/protobuf#7094 (comment)
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.
99ansh commentedon Apr 12, 2020
@Laguses I followed the steps you have mentioned but because I have copied the com folder from protolite-well-known-types, and not excluded it, I still get Duplicate class error between new protolite. jar and protolite-well-known-types.jar Can you please help me out? I am stuck on this for more than a week now.
@athakor I have added the exclusion but still, gives me duplicate class error
lordciriuz commentedon May 10, 2020
The workarround just work if you are using protobuf-javalite. The title is confusing, be careful.
I am trying to use protobuf-java 3.11.4 (full version, no lite) with Firestore 21.4.3 and it seems to be impossible, due to internal incompatibilities with different protobuf versions.
I have to use protobuf-java because my app needs Any type message.
I would like to know if there is a way to accomplish that. If it is not, I will move away from Firestore.
rakeshprojects commentedon Jul 31, 2020
Thank you man!!!!! its working............i got stuck for last few days and you really help me. Thank you again
giovappp commentedon Dec 24, 2020
I have the same problem, I followed some solutions proposed here, only I could not solve the problem of duplicate classes. Anyone have a solution?
Yoginee47 commentedon Feb 2, 2021
@h-amg I have followed some of the solutions given here.. I dont have any compile issues like duplicate classes but app crashes when performing any firestore operation..Is there a way to use both firestore and dialogflow at the same time or i have to change my db? If anyone could help really appreciate it..
h-amg commentedon Feb 2, 2021
@Yoginee47 I had to change my db to mongodb at the end to resolve this issue. I hope this helps
Yoginee47 commentedon Mar 2, 2021
@h-amg Firestore provides the REST API to access the database... Should we consider using that in place of firestore sdk?
Would appreciate your views on this..
h-amg commentedon Mar 3, 2021
@Yoginee47 hi, I think that will help. Since you no longer use the FIRE STORE SDK and therefore avoid the dependencies conflict.
guneet-appinventiv commentedon Dec 1, 2021
This worked for me:
Ref:
https://github.com/GoogleCloudPlatform/android-docs-samples/blob/master/speech/SpeechRecognitionClient/app/build.gradle
https://stackoverflow.com/a/64226363/8459761
PriyavratTalyan commentedon Feb 16, 2022
Working solution after updates in firebase and google libraries
https://stackoverflow.com/a/71136907/9162733