Using grpc dependencies in plugin gives errors

Getting the following error

io.grpc.ManagedChannelProvider: Provider io.grpc.netty.NettyChannelProvider not a subtype

I have the following dependencies in the plugin.

'io.grpc:grpc-netty:1.4.0',
'io.grpc:grpc-protobuf:1.4.0',
'io.grpc:grpc-stub:1.4.0',

I see io.grpc.ManagedChannelProvider exists in studio-profiler-grpc-1.0-jarjar.jar(IC-172.3317.76) and grpc-netty which might be creating the above problem.

Any help will be appreciated.

4
5 comments

Does your plugin depend on 'android' plugin?

0

No, It doesn't depend on android plugin.

0

It's strange then. Classes of your plugins are loaded by a separate class loader, which shouldn't see classes from Android plugin. You can debug the code and look which classloader is used to load ManagedChannelProvider's services.

0
Avatar
Nicholas Bransby-Williams

Did you get a solution to this? I am having the same problem with studio-profiler-grpc-1.0-jarjar - it contains the class

io/grpc/okhttp/OkHttpChannelProvider which is loaded unintentionally by the grpc-java lib that is bundled with my plugin on this line: https://github.com/grpc/grpc-java/blob/master/core/src/main/java/io/grpc/ManagedChannelProvider.java#L107
 
That causes it to crash as it isn't the class it was expecting :
 
Caused by: java.lang.ClassCastException: class io.grpc.okhttp.OkHttpChannelProvider
    at java.lang.Class.asSubclass(Class.java:3404)
 
What I need to happen is for it not to find that class and so load the NettyChannelProvider:
 
Is there a way to achieve this? Obviously this is only an issue in Android Studio. 
0

I also encountered this problem after upgrading the AS to Bumblebee | 2021.1.1.

In Arctic Fox | 2020.3.1, the ClassLoader used to load ManagedChannelProvider is UrlClassLoader:

In Bumblebee | 2021.1.1, the ClassLoader is PluginClassLoader:

1

Please sign in to leave a comment.