使用Dialogflow和Firebase Firestore导致protobuf冲突(protobuf-lite与protobuf-java)

时间:2019-01-13 13:17:50

标签: android firebase google-cloud-firestore protocol-buffers dialogflow

当尝试在我的Android应用中实现Firebase Firestore(com.google.firebase:firebase-firestore)时,我收到与Google Dialogflow(com.google.cloud:google-cloud-dialogflow:0.77.0- α)。在排除任何依赖项之前,我得到的第一个错误是:

Error: Program type already present: com.google.api.AuthProviderOrBuilder

由于Firestore使用以下依赖项,因此我将这种情况的范围缩小了:

com.google.protobuf:protobuf-lite:3.0.1
io.grpc:grpc-protobuf-lite:1.16.1

而Dialogflow使用:

com.google.protobuf:protobuf-java-util:3.6.1
com.google.protobuf:protobuf-java:3.6.1
io.grpc:grpc-protobuf:1.16.1

排除这两个版本会导致protobuf-java的编译器错误(缺少相关性而缺少类),或者在以下功能处导致应用崩溃,并显示以下错误:

db.collection("users")
    .get()
    .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                // For every document within the specified collection
                for (QueryDocumentSnapshot document : task.getResult()) {
                    Log.d(TAG, document.getId() + " => " + document.getData());
                }
            } else {
                Log.w(TAG, "Error getting documents.", task.getException());
            }
        }
   });

错误:

java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
    at com.google.firebase.firestore.util.AsyncQueue.lambda$panic$5(com.google.firebase:firebase-firestore@@17.1.5:377)
    at com.google.firebase.firestore.util.AsyncQueue$$Lambda$5.run(Unknown Source:2)
    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:6680)
    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.VerifyError: Verifier rejected class com.google.firestore.v1beta1.WriteResponse: void com.google.firestore.v1beta1.WriteResponse.mergeCommitTime(com.google.protobuf.Timestamp) failed to verify: void com.google.firestore.v1beta1.WriteResponse.mergeCommitTime(com.google.protobuf.Timestamp): [0x12] register v3 has type Precise Reference: com.google.protobuf.Timestamp but expected Reference: com.google.protobuf.GeneratedMessageLiteVerifier rejected class com.google.firestore.v1beta1.WriteResponse: java.lang.Object com.google.firestore.v1beta1.WriteResponse.dynamicMethod(com.google.protobuf.GeneratedMessageLite$MethodToInvoke, java.lang.Object, java.lang.Object) failed to verify: java.lang.Object com.google.firestore.v1beta1.WriteResponse.dynamicMethod(com.google.protobuf.GeneratedMessageLite$MethodToInvoke, java.lang.Object, java.lang.Object): [0x74] register v5 has type Precise Reference: com.google.protobuf.Timestamp but expected Reference: com.google.protobuf.GeneratedMessageLite (declaration of 'com.google.firestore.v1beta1.WriteResponse'
    at com.google.firestore.v1beta1.WriteResponse.getDefaultInstance(com.google.firebase:firebase-firestore@@17.1.5:1012)
    at com.google.firestore.v1beta1.FirestoreGrpc.getWriteMethod(com.google.firebase:firebase-firestore@@17.1.5:379)
    at com.google.firebase.firestore.remote.WriteStream.<init>(com.google.firebase:firebase-firestore@@17.1.5:75)
    at com.google.firebase.firestore.remote.Datastore.createWriteStream(com.google.firebase:firebase-firestore@@17.1.5:154)
    at com.google.firebase.firestore.remote.RemoteStore.<init>(com.google.firebase:firebase-firestore@@17.1.5:182)
    at com.google.firebase.firestore.core.FirestoreClient.initialize(com.google.firebase:firebase-firestore@@17.1.5:217)
    at com.google.firebase.firestore.core.FirestoreClient.lambda$new$2(com.google.firebase:firebase-firestore@@17.1.5:108)
    at com.google.firebase.firestore.core.FirestoreClient$$Lambda$2.run(Unknown Source:8)
    at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$4(com.google.firebase:firebase-firestore@@17.1.5:309)
    at com.google.firebase.firestore.util.AsyncQueue$$Lambda$4.call(Unknown Source:2)
    at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$3(com.google.firebase:firebase-firestore@@17.1.5:285)
    at com.google.firebase.firestore.util.AsyncQueue$$Lambda$3.run(Unknown Source:4)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at com.google.firebase.firestore.util.AsyncQueue$DelayedStartFactory.run(com.google.firebase:firebase-firestore@@17.1.5:203)
    at java.lang.Thread.run(Thread.java:764)

这是我的应用gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.placeholder.name"
        minSdkVersion 23
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/INDEX.LIST'
        exclude 'META-INF/proguard/androidx-annotations.pro'
    }
}


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
    implementation 'com.google.android.material:material:1.1.0-alpha02'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.google.android.gms:play-services-base:16.0.1'
    implementation 'com.google.android.gms:play-services-flags:16.0.1'
    implementation 'com.google.android.gms:play-services-stats:16.0.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'androidx.room:room-runtime:2.1.0-alpha03'
    annotationProcessor 'androidx.room:room-compiler:2.1.0-alpha03'

    implementation 'io.grpc:grpc-okhttp:1.16.1'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
    implementation 'com.google.firebase:firebase-firestore:17.1.5'
    implementation 'com.google.cloud:google-cloud-dialogflow:0.77.0-alpha'
    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
}

apply plugin: 'com.google.gms.google-services'

这是我的build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

最后,这是我依赖项的输出(由于长度原因,必须粘贴bin):https://pastebin.com/dSGm1wCV

0 个答案:

没有答案