我使用firestore,firebase-auth和fcm进行了一个Android项目。现在,当我将Google-cloud-textTospeech添加到我的项目中时,我会收到"重复类"错误
这是我的依赖项
//Firebase
implementation "com.google.firebase:firebase-core:17.0.0"
implementation "com.google.firebase:firebase-firestore:20.1.0"
/*implementation "com.crashlytics.sdk.android:crashlytics:$rootProject.crashlytics"*/
implementation "com.google.firebase:firebase-messaging:19.0.1"
implementation "com.google.firebase:firebase-auth:18.0.0"
// Ad-mob
implementation "com.google.android.gms:play-services-ads:18.0.0"
implementation ("com.google.cloud:google-cloud-texttospeech:0.97.0-beta")
这是我在构建项目时遇到的错误。
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)
Duplicate class com.google.api.AnnotationsProto 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.AuthProto 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.AuthProvider 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.AuthProvider$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.AuthProvider$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.AuthProviderOrBuilder 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.AuthRequirement 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.AuthRequirement$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.AuthRequirement$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.AuthRequirementOrBuilder 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.Authentication 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.Authentication$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.Authentication$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.AuthenticationOrBuilder 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.AuthenticationRule 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)
现在,我了解Firebase和Google-Cloud-TextTospeech正在使用依赖项内部使用相同的类。所以我试图将其排除在
上implementation ("com.google.cloud:google-cloud-texttospeech:0.97.0-beta"){
exclude group: 'com.google.api.grpc', module: 'proto-google-common-protos'
exclude group: 'com.google.protobuf', module: 'protobuf-lite'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
}
然后该应用程序正在构建,但在语音合成时崩溃
2019-07-03 20:04:15.861 24851-24851/package.dev E/AndroidRuntime: FATAL EXCEPTION: main
Process: package.dev, PID: 24851
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/protobuf/GeneratedMessageV3;
at com.google.cloud.texttospeech.v1.TextToSpeechClient.create(TextToSpeechClient.java:101)
at package_name.tts.TextSpeachAPI.<init>(TextSpeachAPI.kt:8)
at package_name.ui.home.sofar.WordDetailsVM.speak(WordDetailsVM.kt:318)
at package_name.ui.home.sofar.WordDetailsFragment$listeners$11.onClick(WordDetailsFragment.kt:264)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.protobuf.GeneratedMessageV3" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/package_name.dev-apgPZPeLvH3LUXKWw2gBbg==/base.apk"],nativeLibraryDirectories=[/data/app/package_name.dev-apgPZPeLvH3LUXKWw2gBbg==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.cloud.texttospeech.v1.TextToSpeechClient.create(TextToSpeechClient.java:101)
at package_name.tts.TextSpeachAPI.<init>(TextSpeachAPI.kt:8)
at package_name.ui.home.sofar.WordDetailsVM.speak(WordDetailsVM.kt:318)
at package_name.ui.home.sofar.WordDetailsFragment$listeners$11.onClick(WordDetailsFragment.kt:264)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
我在使用" Google Cloud Speech"时遇到了这样的问题。在使用" Firestore"one_answers" Google Cloud语音"时,我在" Protobuf-Java"," Protobuf-lite"," Proto-Google-Common-Protos"one_answers" Protolite-Well-Well-Well-newand-types"中展示了重复的类别。我通过解压缩JAR文件并创建一个没有重复类的新JAR文件来解决问题。请参阅我在下面发布的GitHub项目。
https://github.com/ivso0001/googlecloodspeechandfirebaseIntegration
这对我有用:
android{
...
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/INDEX.LIST'
}
}
dependencies{
...
implementation ('com.google.cloud:google-cloud-speech:0.41.0-alpha'){
exclude module: 'protobuf-javalite'
exclude module: 'protobuf-java'
exclude module: 'proto-google-common-protos'
}
}
参考:
https://github.com/googlecloodplatform/android-docs-samples/blob/master/speech/speechrecognitionclient/app/app/build/build.gradle
https://stackoverflow.com/a/64226363/8459761