Internal error in Firestore (0.6.6-dev) because of GRPC and R8

Viewed 395

After I updated my Firebase dependencies, my app stopped working. The crash report shown this log:

java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
at com.google.firebase.firestore.g.b.a(com.google.firebase:firebase-firestore@@17.0.5:324)
at com.google.firebase.firestore.g.d.run(com.google.firebase:firebase-firestore@@17.0.5)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
 Caused by: java.lang.AbstractMethodError: abstract method "b.d.g.z$d b.d.g.z$d.a(int)"
at b.d.g.u.a(GeneratedMessageLite.java:1319)
at b.d.c.a.y.a(com.google.firebase:firebase-firestore@@17.0.5:8440)
at b.d.c.a.y$a.a(com.google.firebase:firebase-firestore@@17.0.5:6589)
at com.google.firebase.firestore.f.n.b(com.google.firebase:firebase-firestore@@17.0.5:689)
at com.google.firebase.firestore.c.N.a(com.google.firebase:firebase-firestore@@17.0.5:152)
at com.google.firebase.firestore.c.w.b(com.google.firebase:firebase-firestore@@17.0.5:82)
at com.google.firebase.firestore.c.O.a(com.google.firebase:firebase-firestore@@17.0.5:479)
at com.google.firebase.firestore.c.V.run(com.google.firebase:firebase-firestore@@17.0.5)
at com.google.firebase.firestore.c.u.a(com.google.firebase:firebase-firestore@@17.0.5:117)
at com.google.firebase.firestore.c.O.a(com.google.firebase:firebase-firestore@@17.0.5:474)
at com.google.firebase.firestore.b.f.a(com.google.firebase:firebase-firestore@@17.0.5:165)
at com.google.firebase.firestore.b.o.a(com.google.firebase:firebase-firestore@@17.0.5:79)
at com.google.firebase.firestore.b.r.c(com.google.firebase:firebase-firestore@@17.0.5:132)
at com.google.firebase.firestore.b.w.run(com.google.firebase:firebase-firestore@@17.0.5)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.firebase.firestore.g.b$a.run(com.google.firebase:firebase-firestore@@17.0.5:190)
at java.lang.Thread.run(Thread.java:761)

Since the log don't have any class reference to my source code, I tried to figure out the dependencies.

Finally understood that, the issue is because of R8 shrinker and GRPC.

Below are the solution to the above problem:

  1. android.enableR8=false
  2. -keep class io.grpc.** { *; }

Neither of both the above solutions really looked interesting to me.

I don't want to apply the 1st solution, as disabling R8 increases 200 KB in my APK size. Where as the 2nd solution looked a hack to me. I am not in favour of keeping the whole library when a single class cause some problem.

Now the question is how to make my app working with R8 enabled and not keeping the grpc library away from obfuscation?

1 Answers

I went through Firestore's quickstart example app using R8 and gRPC and did not have any issues, even with the com.google.firebase:firebase-firestore:17.0.5 release (which appears to be what you're using from the stack trace). I think you may have run into https://github.com/firebase/FirebaseUI-Android/issues/1175, which should be fixed in recent firestore releases, e.g., 17.1.2. (According to their release notes, 17.0.5 contained a bug and should not be used). If upgrading is not an option, you should be able to just manually add the following to your proguard rules, as was done in the Firestore quickstart example:

-dontwarn okio.**

(I can't reproduce the error you describe, but that seems to be the only proguard rule in the quickstart example that would apply to the gRPC dependency)

Related