grpc / grpc/grpc-java

NoSuchMethodException due to OkHttpChannelProvider default constructor missing after R8 full mode optimization

Offen
#9,611 24 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @temawi Auf GitHub ansehen
android enhancement
Vorherrschende Sprache
Java
Sterne
12.1k
Forks
4k
Ø Merge
2 T. 17 Std.
Gemergte PRs (30 T.)
37

Beschreibung

### 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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.