grpc-java
grpc-java copied to clipboard
The methods `newBlockingStub` and `newStub` cannot take a channel object of class `ManagedChannel`.
- I'm trying to use grpc in my android project.
- I have generated my java class by protoc (version: libprotoc 3.21.7).
- Here is my proto file:
syntax = "proto3";
option java_package = 'com.example.davdmnn.protos';
option java_multiple_files = false;
option java_generic_services = true;
package fscomm;
service FsComm{
rpc sendMessage (MessageRequest) returns (MessageResponse) {};
}
message MessageRequest{
map<string, MsgValue> msg = 1;
}
message MsgValue{
oneof type {
mSingle single_msg = 1;
mList list_msg = 2;
mDict_keyIsString dict_msg_stringkey = 3;
mDict_keyIsInt dict_msg_intkey = 4;
}
}
message mSingle{
oneof type {
float float_value = 1;
int32 int_value = 2;
string str_value = 3;
}
}
message mList{
repeated MsgValue list_value = 1;
}
message mDict_keyIsString{
map<string, MsgValue> dict_value = 1;
}
message mDict_keyIsInt{
map<int32, MsgValue> dict_value = 1;
}
message MessageResponse{
string msg = 1;
}
-
When I want to create a new stub as follows, the parameter of methods
newStubandnewBlockingStubcannot beManagedChannelas follows
-
Here is my dependencies in
app.build.gradle
dependencies {
// grpc
implementation 'io.grpc:grpc-android:1.49.2'
implementation 'io.grpc:grpc-okhttp:1.49.2'
implementation 'io.grpc:grpc-protobuf-lite:1.49.2'
implementation 'io.grpc:grpc-stub:1.49.2'
compileOnly 'org.apache.tomcat:annotations-api:6.0.53'
// protobuf
implementation "com.google.protobuf:protobuf-java:3.21.7"
implementation "com.google.protobuf:protobuf-java-util:3.21.7"
implementation fileTree(includes: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}