程序类型已存在:com.google.logging.type.HttpRequestProto [Android]

时间:2019-03-03 04:58:42

标签: android firebase google-cloud-platform

在构建应用程序时,我想使用Firebase和Google Cloud Platform API,并且会发生错误。
最初,我认为这是由于组'gRPC'的过度使用引起的,因此我在Firestore的实现中将其排除在外,但它不起作用。
似乎已经通过Firestore或Storage或Auth呈现了proto / google目录中的一些类/变量(用于创建protobuf),但是我在Firestore / Storage / Auth的实现中找不到它们(尽管我可以找到它们在proto / google目录中,我不想在那里更改它们,因为在调用``语音到文本''API时需要使用它们。

那么您能告诉我如何解决这个问题吗?

build / gradle(app)如下:

apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'

ext {
    supportLibraryVersion = '26.0.1'
    grpcVersion = '1.4.0'
    googleApiClientVersion =    '1.23.0'
}

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "{myAppId}"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
        resolutionStrategy.force "com.android.support:support-annotations:$supportLibraryVersion"
    }
}

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.3.0'
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.plugins {
                javalite {}
                grpc {
                    // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
}

dependencies {
    implementation 'com.google.firebase:firebase-core:16.0.7'
    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'

    //add
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    implementation 'com.google.firebase:firebase-storage:16.1.0'
    implementation ('com.google.firebase:firebase-firestore:18.1.0') {
        exclude group: 'io.grpc'
    }

    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
//    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
    implementation 'com.android.support:customtabs:28.0.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation('com.android.support.test:runner:1.0.2') {
        exclude module: 'support-annotations'
    }
    androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2') {
        exclude module: 'support-annotations'
    }
    implementation 'com.android.support:support-annotations:28.0.0'

    // Support libraries
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'

    // gRPC
    implementation 'io.grpc:grpc-okhttp:1.16.1'
    implementation 'io.grpc:grpc-protobuf-lite:1.16.1'
    implementation 'io.grpc:grpc-stub:1.16.1'
    implementation 'javax.annotation:javax.annotation-api:1.2'
    protobuf 'com.google.protobuf:protobuf-java:3.4.0'

    // OAuth2 for Google API
    implementation('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
        exclude module: 'httpclient'
    }

    // Dependencies for Google API Client Libraries
    implementation("com.google.http-client:google-http-client:$googleApiClientVersion") {
        exclude module: 'httpclient'
        exclude module: 'jsr305'
        exclude module: "guava-jdk5"
    }
    implementation("com.google.api-client:google-api-client-android:$googleApiClientVersion") {
        exclude module: 'httpclient'
        exclude module: 'jsr305'
        exclude module: "guava-jdk5"
    }
    implementation("com.google.apis:google-api-services-language:v1-rev386-1.22.0") {
        exclude module: 'httpclient'
        exclude module: 'jsr305'
        exclude module: "guava-jdk5"
    }

    implementation 'com.android.support:multidex:1.0.3'
}
apply plugin: 'com.google.gms.google-services'

task copySecretKey(type: Copy) {
    def File secretKey = file "$System.env.GOOGLE_APPLICATION_CREDENTIALS"
    from secretKey.getParent()
    include secretKey.getName()
    into 'src/main/res/raw'
    rename secretKey.getName(), "credential.json"
}
preBuild.dependsOn(copySecretKey)

构建/渐变:

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

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.google.gms:google-services:4.2.0'
        //change1
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.8'

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

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

    }
}

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

可以在以下位置找到proto / google目录: https://github.com/GoogleCloudPlatform/android-docs-samples/tree/master/speech/Speech/app/src/main/proto/google

1 个答案:

答案 0 :(得分:0)

不包括其他protobuf lite依赖项:

    implementation("com.google.firebase:firebase-firestore:$firebaseFirestoreVersion") {
    exclude group: 'com.google.firebase', module: 'protolite-well-known-types'
    }

来自Sz-Nika Janos
显示原始答案:https://stackoverflow.com/a/51209959/10513888