Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 通过gRPC/Protobuf进行通信_Android_Protocol Buffers_Protobuf Net_Grpc - Fatal编程技术网

Android 通过gRPC/Protobuf进行通信

Android 通过gRPC/Protobuf进行通信,android,protocol-buffers,protobuf-net,grpc,Android,Protocol Buffers,Protobuf Net,Grpc,我来是因为我无法让API和客户端Android之间的通信正常工作 我有这个protobuf文件: syntax = "proto3"; option java_package = "com.emixam23.rushpoc.protobuf"; option java_outer_classname = "HelloWorld"; package helloworld; // The greeting service definition. service Greeter { // S

我来是因为我无法让API和客户端Android之间的通信正常工作

我有这个protobuf文件:

syntax = "proto3";

option java_package = "com.emixam23.rushpoc.protobuf";
option java_outer_classname = "HelloWorld";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}
protobuf文件来自的示例,我只是没有实现SayHelloAgain。我试图实现的是,从我的android应用程序中,向我的Go API问好并得到回复

对于android,我遵循该教程,以便从protobuf文件与我的API通信。然而,有一个存根,来自我不知道哪里

所以我搜索了如何创建存根,什么都没有。。ManagedChannel Builder不存在,我找不到安装它的方法

PS:为了从protobuf文件生成Java类,我遵循了该教程:

我的方向是对的还是完全错了

我的项目结构:

应用程序build.gradle

顶级/根build.gradle

//顶级生成文件,您可以在其中添加所有子项目/模块通用的配置选项

buildscript {
    ext.protobufVersion = '0.8.6'

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath "com.google.protobuf:protobuf-gradle-plugin:$protobufVersion"


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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

我还没有检查整个gradle文件,但我在您的屏幕截图中看到.proto文件位于src/main/protobufs中,它没有遵循您提到的任何教程。protobuf gradle插件默认情况下不会检测到此目录。因此,我建议您将其更改为默认目录src/main/proto。如果您想坚持将.proto文件放在src/main/protobufs中,您可能需要通过添加

// see https://github.com/google/protobuf-gradle-plugin#customizing-source-directories    
sourceSets {
  main {
    proto {
      // In addition to the default 'src/main/proto'
      srcDir 'src/main/protobufs'
    }
  }
}

之后,如果没有其他错误,protobuf gradle插件将生成java代码。

是的,你是对的,这是错误之一,但我从未注意到它应该是'src/main/proto'
// see https://github.com/google/protobuf-gradle-plugin#customizing-source-directories    
sourceSets {
  main {
    proto {
      // In addition to the default 'src/main/proto'
      srcDir 'src/main/protobufs'
    }
  }
}