Duplicate Class Error When Using Firestore And Google Speech To Text
Solution 1:
I've figured it out. The Google Speech-to-Text Java library does not currently support Android, hence the error. From what I understand, protobuf-java (used by Google Speech-to-Text) is used for desktop solutions and protobuf-lite (used by Firestore) is used for mobile solutions. Excluding either module will break their respective dependents.
My workaround was to create my own .jar that included classes from both, including that .jar in my project, then excluding the modules from their dependents in my build.gradle. This will ensure that I have the right modules in my project, but also that I will only have one copy of the classes.
Steps I took:
- Copy each .jar with conflicts to a new folder (doesn't matter where)
- Change extension to .zip
- Extract the contents in each zip to a single folder. When asked to overwrite, do so.
- IMPORTANT: make sure the last zips you extract are protolite-well-known-types and protobuf-javalite, this will ensure that Firestore has the right libraries. Make sure they overwrite any existing files.
- Zip the contents of the folder.
- Change the file extension to .jar
- Add the new .jar to your /lib folder
- Exclude the modules from their dependents in your build.gradle
implementation('com.google.firebase:firebase-firestore:21.4.3') {
exclude module: 'protolite-well-known-types'
exclude module: 'protobuf-javalite'
exclude module: 'protobuf-java'
exclude module: 'protobuf-java-util'
}
implementation('com.google.cloud:google-cloud-speech:1.23.0') {
exclude module: 'protolite-well-known-types'
exclude module: 'protobuf-javalite'
exclude module: 'proto-google-common-protos'
exclude module: 'protobuf-java'
exclude module: 'protobuf-java-util'
}
EDIT:
This does not work fully. It allows the project to compile and calls to Firestore to run, but will produce a runtime error when attempting to make any method calls utilizing the Google Speech-to-Text library.
As of now, I do not think there is any way to use Firebase with the Google Speech-to-Text library, as Google Speech-to-Text is not yet supported by Android.
Solution 2:
In my case, I was using DialogFlow
with Firestore
.
Using below dependency was enough for me
implementation('com.google.firebase:firebase-firestore:21.4.3') {
exclude module: 'protolite-well-known-types'
exclude module: 'protobuf-javalite'
exclude module: 'protobuf-java'
exclude module: 'protobuf-java-util'
}
Post a Comment for "Duplicate Class Error When Using Firestore And Google Speech To Text"