It took me some time to figure out that below error is caused only when I try to use gRPC client from SyncAdapter:
No functional channel service provider found. Try adding a dependency on the grpc-okhttp or grpc-netty artifact
The setup is exactly like in official tutorial Transferring Data Using Sync Adapters.
I've generated gRPC code using same setup as an example from grpc-java. The compile 'com.squareup.okhttp:okhttp:2.2.0'
dependency in example is not necessary as compile 'io.grpc:grpc-okhttp:0.9.0'
was modified to be self contained.
When the gRPC service method is called from the main activity it works fine.
I suspect that the grpc-okhttp
must be initialized in some way but have no clue how.
I've decided to read the code of gRPC. The code I've used to create channel was:
mChannel = ManagedChannelBuilder.forAddress(mHost, mPort)
.usePlaintext(true).build();
The way the generic ManagedChannelBuilder class works is to dynamically load all classes extending ManageChannelBoulder
and choose the one with highest priority. Then the chosen class is remembered in static variable.
It seems that during a call in SyncAdapter
the appropriate builder for okhttp was not available. I've fixed it by hardcoding the choosen builder:
mChannel = OkHttpChannelBuilder.forAddress(mHost, mPort)
.usePlaintext(true).build();
I hope to save someone's evening.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With