Gradle“排除”故障排除:对protobuf-java和protobuf-lite

时间:2019-04-04 17:54:29

标签: android-gradle dependencies noclassdeffounderror grpc-java protobuf-java

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

我正在使用Google Firebase-Firestore数据库,该数据库实现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 / GeneratedMessageV3;“

这是我的应用依赖项,没有排除的内容:

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应用程序的(树)读数:依赖项:

...{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:解析失败:Lcom / google / protobuf / GeneratedMessageV3;”

有人能帮我解决这个问题,以便在不破坏毛细管依赖性功能的情况下,没有多余的依赖性也没有类定义吗?

0 个答案:

没有答案