1

我正在尝试测试我的 Android 应用程序(在设备上),但在 gradle 构建过程中我收到“错误:程序类型已经存在:com.google.protobuf.AnyProto”(或其他类)。

我正在使用 Google Firebase-Firestore DB,它实现了 grpc 并使用嵌套依赖项:com.google.protobuf:protobuf-lite:3.0.1。

此外,google/Capillary 库使用嵌套依赖项:com.google.protobuf:protobuf-java:3.4.0。

如果我仅从 Capillary lib 依赖项中排除 com.google.protobuf,则应用程序将运行,然后在实例化所需的 Capillary 类时崩溃,并出现错误:“java.lang.NoClassDefFoundError:解析失败:Lcom/google/protobuf/生成的消息V3;"

这是我的应用程序依赖项,没有排除:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-media-compat:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'

    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-auth:16.2.0'
    implementation 'com.google.firebase:firebase-messaging:17.5.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'


    //HERE ARE THE PROBLEM DEPENDENCIES:
    implementation('com.google.firebase:firebase-firestore:18.2.0', {})
    implementation('com.google.capillary:lib-android:1.0.0', { })
    //

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

这是 gradlew app:dependencies 的(树)读数:

...{CONTENT ABOVE OMITTED}...
+--- com.google.firebase:firebase-firestore:18.2.0
|    +--- com.google.android.gms:play-services-base:16.0.1 (*)
|    +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    +--- com.google.firebase:firebase-auth-interop:16.0.1 (*)
|    +--- com.google.firebase:firebase-common:16.1.0 (*)
|    +--- com.google.firebase:firebase-database-collection:16.0.1
|    +--- com.google.firebase:protolite-well-known-types:16.0.1
|    |    \--- com.google.protobuf:protobuf-lite:3.0.1
|    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|    +--- com.squareup.okhttp:okhttp:2.7.5
|    |    \--- com.squareup.okio:okio:1.6.0 -> 1.13.0
|    +--- io.grpc:grpc-android:1.16.1
|    |    \--- io.grpc:grpc-core:[1.16.1] -> 1.16.1
|    |         +--- io.grpc:grpc-context:1.16.1
|    |         +--- com.google.code.gson:gson:2.7
|    |         +--- com.google.errorprone:error_prone_annotations:2.2.0
|    |         +--- com.google.code.findbugs:jsr305:3.0.2
|    |         +--- org.codehaus.mojo:animal-sniffer-annotations:1.17
|    |         +--- com.google.guava:guava:26.0-android
|    |         |    +--- org.checkerframework:checker-compat-qual:2.5.2
|    |         |    \--- com.google.j2objc:j2objc-annotations:1.1
|    |         +--- io.opencensus:opencensus-api:0.12.3
|    |         |    \--- com.google.errorprone:error_prone_annotations:2.2.0
|    |         \--- io.opencensus:opencensus-contrib-grpc-metrics:0.12.3
|    |              +--- com.google.errorprone:error_prone_annotations:2.2.0
|    |              \--- io.opencensus:opencensus-api:0.12.3 (*)
|    +--- io.grpc:grpc-okhttp:1.16.1
|    |    +--- io.grpc:grpc-core:[1.16.1] -> 1.16.1 (*)
|    |    +--- com.squareup.okhttp:okhttp:2.5.0 -> 2.7.5 (*)
|    |    \--- com.squareup.okio:okio:1.13.0
|    +--- io.grpc:grpc-protobuf-lite:1.16.1  
|    |    +--- io.grpc:grpc-core:1.16.1 (*)
|    |    +--- com.google.protobuf:protobuf-lite:3.0.1
|    |    \--- com.google.guava:guava:26.0-android (*)
|    \--- io.grpc:grpc-stub:1.16.1
|         \--- io.grpc:grpc-core:1.16.1 (*)
\--- com.google.capillary:lib-android:1.0.0
     +--- com.google.capillary:lib:1.0.0
     |    \--- com.google.protobuf:protobuf-java:3.4.0
     +--- com.google.crypto.tink:tink-android:1.1.0
     +--- com.google.crypto.tink:apps-webpush:1.1.0
     +--- com.google.protobuf:protobuf-java:3.4.0
     +--- joda-time:joda-time:2.9.9
     \--- com.android.support:support-annotations:27.1.1 -> 28.0.0

我尝试使用几种包排除组合,包括从 Firestore 和 Capillary 中完全排除 com.google.protobuf 并分别实施:


    implementation('com.google.protobuf:protobuf-java:3.4.0')
    //{OR}
    //implementation('com.google.protobuf:protobuf-lite:3.0.1')

    implementation('com.google.firebase:firebase-firestore:18.2.0', {
        exclude group: 'com.google.protobuf'//, module: 'protobuf-lite'
    })


    implementation('com.google.capillary:lib-android:1.0.0', {
        exclude group: 'com.google.protobuf'//, module: 'protobuf-java'
    })

^我已经尝试了几种组合,但没有成功。

当我仅从 Capillary lib 依赖项中排除“com.google.protobuf”时(我没有使用此库的 grpc 功能),我可以让应用程序运行,但是,当来自毛细管库被实例化,出现错误:“java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/protobuf/GeneratedMessageV3;”

有没有人能帮我解决这个问题,这样就没有多余的依赖项或缺少类定义,而不会破坏 Capillary 依赖项的功能?

4

0 回答 0