firebase-android-sdk
firebase-android-sdk copied to clipboard
RuntimeException due to org.json:json dependency
Environment
- Android Studio version: Android Studio Bumblebee | 2021.1.1 Patch 3
- Firebase Component: Database
- Component version: 20.0.4
Describe the problem
Steps to reproduce:
- What happened? Crash on the
getReferenceofFirebaseDatabase.getInstance().getReference("whatever"). - How can we make the problem occur? Add
implementation("org.json:json:20220320")+ minification - Reproduced 100% of the time on any Android device.
How to reproduce the issue?
- Sample project that reproduce the issue: firebase-android-sdk-database-issue-3643
- Line of code cause of the issue: dependency
org.json:json - Crash only when minification enabeled.
- Reproduced by @argzdev: on this issue comment
- This issue created because of: this comment
- Related investigation done on the issue: https://github.com/firebase/firebase-android-sdk/issues/3643#issuecomment-1106762584
Stacktrace
Note that the mapping is pointing b9.g to org.json.JSONStringer
2022-04-21 23:08:38.743 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mercandalli.android.apps.sampler, PID: 11865
java.lang.RuntimeException: Uncaught exception in Firebase Database runloop (20.0.4). If you are not already on the latest version of the Firebase SDKs, try updating your dependencies. Should this problem persist, please file a report at https://github.com/firebase/firebase-android-sdk
at j4.n$a$a.run(:96)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7870)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.NoSuchMethodError: No virtual method object()Lb9/g; in class Lb9/g; or its super classes (declaration of 'b9.g' appears in /data/app/~~MDSz81k4B6uCZgrZsQ9zyQ==/com.mercandalli.android.apps.sampler-66tdqwTq1qJ-KDvS2fRLdw==/base.apk)
Thank you for your amazing work on firebase, great tool for Android developpers =) Have a nice day ! @Mercandj
Hi, @Mercandj this is due to the fact that the call signature used by your version of org.json does not match the call signature expected by Realtime Database. This is due to the differing versions between the built-in version shipped with Android and the one included in your gradle file. If you remove the dependency, is your app still able to run?
Hi @maneesht,
My app is not directly depending on org.json but is depending on external non-android java libraries that are depending on the latest version of org.json (transitive dependency).
Indeed firebase is using the JSONStringer methods that are avaibable on the Android version directly on JSONStringer. But these methods have been moved to the supper class JSONWriter on "org.json:json:20220320"
To fix the issue and keep JSONWriter and JSONStringer with the same signatures, I added these proguard rules and it works 🎉, no more crash
# https://github.com/firebase/firebase-android-sdk/issues/3688
-keep class org.json.** { *; }
-keepclassmembers class org.json.** { *; }
Thks for the help 🙏 .
Other possibilities for the fix, exclude transitive declaration from every libs using org.json via gradle "exclude" keyword. But did not work for me.
So, does not seems to be an issue related to firebase-android-sdk directly. Ok to close it if you want. I hope other dev facing this issue will know that even if the stacktrace is pointing to firebase, the error is caused by the org.json non-android dependency and firebase using org.json methods that have been moved to super class. And so the solution is to disable the minification for org.json. Hopefull google search indexed this issue to help futur devs =)
Hey @Mercandj, sorry for the delayed response here. I'm glad you were able to resolve your issue. That said, I'll close this issue as resolved now. Thank you for providing this solution!