简体   繁体   English

在 Android 上使用最新的 gRPC 插件时出现组装错误 -> Input 在 --proto_path (Gradle 7.0.1) 中有阴影

[英]Assemble error while using latest gRPC plugin on Android -> Input is shadowed in the --proto_path (Gradle 7.0.1)

I am trying to update an Android project to use the latest gradle plugin (7.0.1), from the current 3.6.4 that it is using.我正在尝试更新一个 Android 项目以使用它正在使用的当前 3.6.4 中的最新 gradle 插件 (7.0.1)。 In order to do this, considering the project is using protobuf, I need to update the protobuf and gRPC dependencies, as the current ones are not compatible with the latest plugin.为此,考虑到项目正在使用 protobuf,我需要更新 protobuf 和 gRPC 依赖项,因为当前的依赖项与最新的插件不兼容。

I have followed https://github.com/grpc/grpc-java in order to use the latest dependency versions.我已关注https://github.com/grpc/grpc-java以使用最新的依赖版本。 I updated the dependencies to the following versions:我将依赖项更新为以下版本:

implementation 'io.grpc:grpc-okhttp:1.40.1'
implementation 'io.grpc:grpc-protobuf-lite:1.40.1'
implementation 'io.grpc:grpc-stub:1.40.1'
compileOnly 'org.apache.tomcat:annotations-api:6.0.53'
protobuf "com.google.protobuf:protobuf-java:3.17.3"

I am using the latest protobuf plugin我正在使用最新的 protobuf 插件

plugins {
    id 'com.google.protobuf' version '0.8.17'
}

And use the following block for code-gen并使用以下块进行代码生成

protobuf {
  protoc {
    artifact = "com.google.protobuf:protoc:3.17.3"
  }
  plugins {
    grpc {
      artifact = "io.grpc:protoc-gen-grpc-java:1.40.1"
    }
  }
  generateProtoTasks {
    all().each { task ->
      task.builtins {
        java { option 'lite' }
      }
      task.plugins {
        grpc { option 'lite' }
      }
    }
  }
}

The gradle sync succeeds while using those, the problem is when I try to assemble the project, I get the following error:使用这些时 gradle 同步成功,问题是当我尝试组装项目时,出现以下错误:

Execution failed for task ':App:generateDebugProto'.任务 ':App:generateDebugProto' 执行失败。 protoc: stdout: .协议:标准输出:。 stderr: C:\\Users\\phantom\\AndroidStudioProjects\\Protobuf\\App\\build\\extracted-protos\\main\\google\\protobuf\\any.proto: Input is shadowed in the --proto_path by "C:/Users/phantom/AndroidStudioProjects/Protobuf/App/build/extracted-include-protos/debug/google/protobuf/any.proto".标准错误:C:\\Users\\phantom\\AndroidStudioProjects\\Protobuf\\App\\build\\extracted-protos\\main\\google\\protobuf\\any.proto:输入在 --proto_path 中被“C:/Users/phantom/AndroidStudioProjects/ Protobuf/App/build/extracted-include-protos/debug/google/protobuf/any.proto”。 Either use the latter file as your input or reorder the --proto_path so that the former file's location comes first.要么使用后一个文件作为输入,要么重新排序 --proto_path 以便前一个文件的位置在前。

From what I understand while reading the error, the problem is that the proto files are generated now in both extracted-protos and extracted-include-protos build files, and the latter shadows the first one.根据我在阅读错误时的理解,问题是现在在提取的原型提取的包含原型构建文件中都生成了 proto 文件,而后者掩盖了第一个。 I have checked, in the previous version, the files were generated solely in the extracted-protos build files.我已经检查过,在以前的版本中,这些文件仅在提取的 protos构建文件中生成。 Is there a way to skip generating the files in the extracted-include-protos ?有没有办法跳过在extract-include-protos 中生成文件? Or what would be the course of action to be able to assemble the project?或者能够组装该项目的行动过程是什么?

I ran into this same issue yesterday.我昨天遇到了同样的问题。 This is more of a workaround than a full answer.这更像是一种解决方法,而不是完整的答案。 It got me working with Google speech-to-text, but it doesn't work if you add in a non-beta version of text-to-speech, so if anybody has a better answer please post.它让我使用 Google 语音转文本,但如果您添加文本转语音的非测试版,它就不起作用,所以如果有人有更好的答案,请发布。

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.17.3'
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:1.40.1"
        }
    }
    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'
                }
            }
        }
    }
}

implementation 'io.grpc:grpc-okhttp:1.40.1'
implementation 'io.grpc:grpc-protobuf-lite:1.25.0'
implementation 'io.grpc:grpc-stub:1.40.1'
compileOnly 'org.apache.tomcat:annotations-api:6.0.53'
protobuf "com.google.protobuf:protobuf-java:3.17.3"

implementation("com.google.cloud:google-cloud-speech:1.22.1") {
    exclude group: 'com.google.protobuf', module: 'protobuf-java'
    exclude group: 'com.google.api.grpc'
}

Note the versions of grpc-protobuf-lite and google-cloud-speech.注意 grpc-protobuf-lite 和 google-cloud-speech 的版本。 I had to downgrade both of them from the latest.我不得不将它们都从最新版本降级。

Had the same issue, After trying every possible gradle configuration for 2 days.有同样的问题,在尝试了所有可能的 gradle 配置 2 天后。 I just manually deleted all the proto files under ../build/extracted-include-protos/debug/google/protobuf/ and the error is gone我只是手动删除了 ../build/extracted-include-protos/debug/google/protobuf/ 下的所有 proto 文件,错误消失了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM