如何解决Android Studio上的“Type com.google.protobuf.Any$1 is defined multiple times”问题

rdrgkggo  于 2023-06-20  发布在  Android
关注(0)|答案(1)|浏览(379)

我正在升级我的Android应用程序以支持API 33。为此,我还升级了protobuf和grpc库。一切都升级和应用程序的工作,如果我建立和运行它直接从Android Studio到我的手机。但是,如果我尝试构建用于发布应用程序的捆绑包,则会出现以下错误。

  1. Type com.google.protobuf.Any$1 is defined multiple times: C:\Users\ilker\.gradle\caches\transforms-3\156cd40978d20d5791c06b9e4b80c4fc\transformed\jetified-protobuf-javalite-3.21.7.jar:com/google/protobuf/Any$1.class, C:\Development\workspace\android_studio\VectorCTRLPRO\app\build\intermediates\javac\release\classes\com\google\protobuf\Any$1.class

我的build.gradle(应用程序级别)是这样的:

  1. apply plugin: 'com.android.application'
  2. apply plugin: 'com.google.protobuf'
  3. apply plugin: 'com.google.gms.google-services'
  4. apply plugin: 'com.google.firebase.crashlytics'
  5. android {
  6. compileSdkVersion 33
  7. defaultConfig {
  8. applicationId "com.test.app"
  9. minSdkVersion 21
  10. targetSdkVersion 33
  11. versionCode 125
  12. versionName "12.5"
  13. multiDexEnabled true
  14. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  15. }
  16. buildTypes {
  17. release {
  18. minifyEnabled true
  19. shrinkResources true
  20. proguardFiles getDefaultProguardFile(
  21. 'proguard-android-optimize.txt'),
  22. 'proguard-rules.pro'
  23. firebaseCrashlytics {
  24. mappingFileUploadEnabled true
  25. }
  26. }
  27. }
  28. lintOptions {
  29. disable 'GoogleAppIndexingWarning', 'HardcodedText', 'InvalidPackage'
  30. textReport true
  31. textOutput "stdout"
  32. }
  33. compileOptions {
  34. sourceCompatibility JavaVersion.VERSION_1_8
  35. targetCompatibility JavaVersion.VERSION_1_8
  36. }
  37. packagingOptions {
  38. exclude 'META-INF/DEPENDENCIES'
  39. exclude 'META-INF/LICENSE'
  40. exclude 'META-INF/LICENSE.txt'
  41. exclude 'META-INF/license.txt'
  42. exclude 'META-INF/NOTICE'
  43. exclude 'META-INF/NOTICE.txt'
  44. exclude 'META-INF/notice.txt'
  45. exclude 'META-INF/ASL2.0'
  46. exclude 'META-INF/INDEX.LIST'
  47. exclude 'META-INF/io.netty.versions.properties'
  48. }
  49. }
  50. dependencies {
  51. implementation 'androidx.appcompat:appcompat:1.7.0-alpha02'
  52. implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
  53. implementation 'com.google.android.material:material:1.8.0'
  54. implementation 'io.grpc:grpc-okhttp:1.52.1'
  55. implementation 'io.grpc:grpc-protobuf-lite:1.52.1'
  56. implementation 'io.grpc:grpc-stub:1.52.1'
  57. implementation 'javax.annotation:javax.annotation-api:1.2'
  58. protobuf 'com.google.protobuf:protobuf-java:3.23.2'
  59. protobuf 'com.google.api.grpc:googleapis-common-protos:0.0.3'
  60. implementation 'com.google.android.gms:play-services-ads:22.1.0'
  61. implementation 'com.google.firebase:firebase-analytics:21.3.0'
  62. implementation 'com.google.firebase:firebase-crashlytics:18.3.7'
  63. implementation 'com.google.firebase:firebase-messaging:23.1.2'
  64. implementation ('com.google.firebase:firebase-inappmessaging-display:20.3.2') {
  65. exclude group: 'com.google.firebase', module: 'protolite-well-known-types'
  66. }
  67. implementation 'org.jcodec:jcodec:0.2.5'
  68. implementation 'org.jcodec:jcodec-android:0.2.5'
  69. implementation 'org.jcodec:jcodec-javase:0.2.5'
  70. implementation 'com.google.android.gms:play-services-vision:20.1.3'
  71. implementation 'com.google.android.ads.consent:consent-library:1.0.8'
  72. implementation 'com.google.android.play:core:1.10.3'
  73. implementation 'com.google.guava:guava:28.2-android'
  74. implementation project(path: ':nativetemplates')
  75. constraints {
  76. implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
  77. because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
  78. }
  79. implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
  80. because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
  81. }
  82. }
  83. }
  84. configurations.implementation {
  85. exclude group: 'com.google.guava', module: 'listenablefuture'
  86. }
  87. protobuf {
  88. protoc { artifact = 'com.google.protobuf:protoc:3.23.2' }
  89. plugins {
  90. grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.52.1' }
  91. }
  92. generateProtoTasks {
  93. all().each { task ->
  94. task.builtins{
  95. java { option 'lite' }
  96. }
  97. task.plugins {
  98. grpc { option 'lite' }
  99. }
  100. }
  101. }
  102. }

尝试删除以下行,但得到了相同的错误:

  1. protobuf 'com.google.protobuf:protobuf-java:3.23.2'
  2. protobuf 'com.google.api.grpc:googleapis-common-protos:0.0.3'

gradle创建的依赖列表如下:
https://pastebin.com/raw/PdYSg8bm

ltskdhd1

ltskdhd11#

看起来您通过io.grpc:grpc-protobuf-lite依赖于com.google.protobuf:protobuf-javacom.google.protobuf:protobuf-javalite
提示在错误消息中,相关类为:jetified-protobuf-javalite-3.21.7.jar:com/google/protobuf/Any$1.classapp\build\intermediates\javac\release\classes\com\google\protobuf\Any$1.class
请参阅https://developer.android.com/build/dependencies#view-dependency-tree以获取有关如何处理此问题的更多信息。您需要调查是什么在拉多个不同的protobuf副本,然后找出如何解决依赖图。

相关问题