NoSuchMethodException due to OkHttpChannelProvider default constructor missing after R8 full mode optimization
- Dominant language
- Java
- Stars
- 12.1k
- Forks
- 4k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 37
Description
### What version of gRPC-Java are you using?
1.49.2
### What is your environment?
Android
### What did you see?
When run after R8 full mode optimization, grpc throws an exception during execution:
Failed to construct OkHttpChannelProvider
```
java.lang.NoSuchMethodException: io.grpc.okhttp.OkHttpChannelProvider. []
at java.lang.Class.getConstructor0(Class.java:2363)
at java.lang.Class.getConstructor(Class.java:1759)
at io.grpc.android.AndroidChannelBuilder.(SourceFile:14)
at com.example.GrpcServiceModule$channel$1.invokeSuspend(SourceFile:51)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(SourceFile:6)
at kotlinx.coroutines.DispatchedTask.run(SourceFile:108)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(SourceFile:77)
```
This is because R8 full mode does not implicitly keep default constructors:
https://r8.googlesource.com/r8/+/refs/heads/master/compatibility-faq.md#r8-full-mode
This Proguard/R8 configuration rule avoids the issue and should be added to https://github.com/grpc/grpc-java/blob/master/android/proguard-rules.txt:
```
-keepclassmembers, allowoptimization class io.grpc.okhttp.OkHttpChannelProvider {
();
}
```
There may be additional configuration rules needed to take care of further default constructors accessed via reflection.
Contributor guide
Assessment
This issue has not been assessed yet.