2

将 protobuf gradle 更新到此项目的 0.8.5 后 https://github.com/GoogleCloudPlatform/android-docs-samples/tree/master/speech/Speech,我收到此错误消息:

程序类型已存在:com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream 不确定要删除什么

4

1 回答 1

0

很可能还有一些额外的依赖关系。这只是为了让托管在 Github 上的谷歌云语音项目正常工作。

重要的是要记住在依赖项部分使用它。

protobuf 'com.google.protobuf:protobuf-java:3.5.1'

同时应用插件

apply plugin: 'com.google.protobuf'

为此,在项目的 build.gradle 中,我们必须有类路径

classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.5'

但是,我们必须激活存储库

classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.5'

这是我的应用程序 gradle 文件。

/*
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

ext {
    supportLibraryVersion = '27.1.1'
    grpcVersion = '1.12.0'
}

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    flavorDimensions 'version'
    defaultConfig {
        applicationId "com.google.cloud.android.speech"
        targetSdkVersion 27
        versionCode 1
        versionName '1.0'
    }

    signingConfigs {
    }

    sourceSets {
        main {
            proto {
                srcDir 'src/main/proto/google/api'
                srcDir 'src/main/proto/google/logging'
                srcDir 'src/main/proto/google/longrunning'
                srcDir 'src/main/proto/google/rpc'
                srcDir 'src/main/proto/google/speech/v1'
                srcDir 'src/main/proto/google/type'
            }

        }
    }
    productFlavors {
        dev {
            // Minimum version with platform multi-dex support
            minSdkVersion 21
        }
        prod {
            // Minimum version that can run gRPC (TLS extension)
            minSdkVersion 16
        }
    }

    buildTypes {
        debug {
            minifyEnabled false
            multiDexEnabled true
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//            signingConfig signingConfigs.release
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

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

}


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    // Support libraries
    implementation "com.android.support:support-v4:$supportLibraryVersion"
    implementation "com.android.support:design:$supportLibraryVersion"
    implementation "com.android.support:cardview-v7:$supportLibraryVersion"
    implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"
    // gRPC
    implementation "io.grpc:grpc-okhttp:$grpcVersion"
    implementation "io.grpc:grpc-protobuf-lite:$grpcVersion"
    implementation "io.grpc:grpc-stub:$grpcVersion"
    implementation 'javax.annotation:javax.annotation-api:1.2'

    protobuf 'com.google.protobuf:protobuf-java:3.5.1'
    // OAuth2 for Google API
    implementation('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
        exclude module: 'httpclient'
    }
    // Tests
    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'
}

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.0.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.builtins {
                // In most cases you don't need the full Java output
                // if you use the lite output.
                remove java
            }
            task.plugins {
                javalite {}
                grpc {
                    // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
}

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)

这个是项目的gradle文件

    /*
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
            }
        google()
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.5'
//        classpath "gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.5"

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

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

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

我正在使用 gradle 4 和 gradle-plugin 3

我希望我有所帮助

谷歌云语音

于 2018-05-16T14:24:09.567 回答