我正在尝试实现gRPC,现在我遇到了各种各样的问题,但我只是不明白我做错了什么。我正在跟踪这个医生:https://github.com/grpc/grpc-java/blob/master/README.md
现在,当我试图构建我的项目时,我总是会遇到这样的错误
error: package com.google.protobuf.GeneratedMessageV3 does not exist
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements在我的Android外部库中,我有protobuf-java-3.12.1 jar。
在我的项目gradle文件中,我将其添加到依赖项中:
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.14'在我的应用程序gradle文件中:
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'在依赖项中,我添加了:
implementation 'io.grpc:grpc-okhttp:1.35.0'
implementation 'io.grpc:grpc-protobuf-lite:1.35.0'
implementation 'io.grpc:grpc-stub:1.35.0'
compileOnly 'org.apache.tomcat:annotations-api:6.0.53'
implementation 'com.google.protobuf:protobuf-javalite:3.12.1'在android标签之外:
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.12.1"
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.35.0'
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}最后,我的proto文件:
syntax = "proto3";
import "google/protobuf/timestamp.proto";
option java_package = "com.xxx.xxx.proto.log";
option java_outer_classname = "MyClass";
message MyObject {
string name = 1;
string unit = 2;
oneof value {
bool bool_value = 3;
sint32 int32_value = 4;
uint32 u_int32_value = 5;
google.protobuf.Timestamp timestamp_value = 6;
}
} 当我运行: protoc --终端版本时,这是输出:
libprotoc 3.12.1我是否必须添加其他内容,还是在我的Gradle设置中遗漏了什么?
发布于 2021-02-03 18:21:24
看起来,您希望使用protobuf (这是Android项目的正常情况):
implementation 'io.grpc:grpc-protobuf-lite:1.35.0'
...
implementation 'com.google.protobuf:protobuf-javalite:3.12.1'但是,目前您正在生成完整的protobuf代码。您需要告诉java和grpc代码生成器通过选项为lite生成。如java Android helloworld示例所示
protobuf {
...
generateProtoTasks {
all().each { task ->
task.builtins {
java { option 'lite' }
}
task.plugins {
grpc { option 'lite' }
}
}
}
}https://stackoverflow.com/questions/66028045
复制相似问题