Flutter firebase integration getting error: Failed to turn object into JSON - firebase

All of the sudden I am getting the following error when doing any firebase interaction (auth or firestore) in my flutter Android app.
E/StorageHelpers(15925): Failed to turn object into JSON
E/StorageHelpers(15925): java.lang.NullPointerException: Attempt to invoke virtual method 'org.json.JSONObject com.google.firebase.auth.internal.zzm.zzbf()' on a null object reference
E/StorageHelpers(15925): at com.google.firebase.auth.internal.zzz.zzi(Unknown Source:126)
E/StorageHelpers(15925): at com.google.firebase.auth.internal.zzz.zzg(Unknown Source:3)
E/StorageHelpers(15925): at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source:28)
E/StorageHelpers(15925): at com.google.firebase.auth.zzm.zza(Unknown Source:3)
E/StorageHelpers(15925): at com.google.firebase.auth.api.internal.zzaw.zzaa(Unknown Source:27)
E/StorageHelpers(15925): at com.google.firebase.auth.api.internal.zzcy.zzal(Unknown Source:0)
E/StorageHelpers(15925): at com.google.firebase.auth.api.internal.zzcy.zza(Unknown Source:0)
E/StorageHelpers(15925): at com.google.firebase.auth.api.internal.zzdb.zzb(Unknown Source:42)
E/StorageHelpers(15925): at com.google.firebase.auth.api.internal.zzci.dispatchTransaction(Unknown Source:13)
E/StorageHelpers(15925): at com.google.android.gms.internal.firebase_auth.zzb.onTransact(Unknown Source:22)
E/StorageHelpers(15925): at android.os.Binder.execTransact(Binder.java:697
)
Here are my firebase dependencies:
firebase_auth: "^0.5.3"
cloud_firestore: "^0.7.0+2"
Similar unresolved questions:
https://github.com/invertase/react-native-firebase/issues/1068
Failed to turn object into JSON

I just faced the same problem as yours, I think that's the latest update of Firebase cause this.
In the beginning, I tried to do [Build] > [Clean Project], and [File] > [Invalidate caches/Restart] in Android Studio, but still not working, and this error still occurred.
Finally I fixed this, when I removed the app on my device, and re-install, now everything works fine.
Here's the version I use in my gradle file:
com.google.firebase:firebase-auth:15.1.0
com.google.firebase:firebase-firestore:16.0.0
Hope this can help.

Related

MissingPluginException(No implementation found for method Messaging#requestPermission on channel firebase_messaging

final NotificationSettings settings = await messaging.requestPermission();
I am getting this error when calling requestPermission() method of firebase messaging.
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method Messaging#requestPermission on channel plugins.flutter.io/firebase_messaging)
E/flutter ( 7180): #0 convertPlatformException (package:firebase_messaging_platform_interface/src/method_channel/utils/exception.dart:13:5)
E/flutter ( 7180): #1 MethodChannelFirebaseMessaging.requestPermission (package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:286:13)
E/flutter ( 7180):
In build.gradle i implemented
'com.google.firebase:firebase-messaging'
implementation platform('com.google.firebase:firebase-bom:28.3.0')
I had the same issue. Fixed it updating to the last version:
firebase_core: ^1.10.0
firebase_messaging: ^11.1.0
Use the latest versions of below packages
firebase_core
https://pub.dev/packages/firebase_core/versions
firebase_messaging
https://pub.dev/packages/firebase_messaging/versions
Terminate the current running session.
Do flutter pub get in your terminal
Then run again.
remove onBackgroundmessage from the firebase configure, it's a temporary solution but it works for older firebase packages

How can i fix This error in background notification handler?

I have a problem with app flutter when I integrate firebase_messaging to receive notification in the background
when I debug I get this error :
I/FLTFireBGExecutor(29060): Creating background FlutterEngine instance, with args: [--start-paused, --enable-dart-profiling] W/FlutterEngineCxnRegstry(29060): Attempted to register plugin (io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry$ShimRegistrarAggregate#2549a44) but it was already registered with this FlutterEngine (io.flutter.embedding.engine.FlutterEngine#99e972d). E/MethodChannel#(29060): Parameter messenger must not be null. I/BlockMonitor(29060): dispatchingThrewException In MainThread D/AndroidRuntime(29060): Shutting down VM I/QarthLog(29060): [PatchStore] createDisableExceptionQarthFile I/QarthLog(29060): [PatchStore] create disable file for com.dgmsolutions.foolivery uid is 10523 E/AndroidRuntime(29060): FATAL EXCEPTION: main E/AndroidRuntime(29060): java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.BinaryMessenger.setMessageHandler(java.lang.String, io.flutter.plugin.common.BinaryMessenger$BinaryMessageHandler)' on a null object reference E/AndroidRuntime(29060): at io.flutter.plugin.common.MethodChannel.setMethodCallHandler(MethodChannel.java:119) E/AndroidRuntime(29060): at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin.initInstance(FlutterFirebaseMessagingPlugin.java:64) E/AndroidRuntime(29060): at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin.registerWith(FlutterFirebaseMessagingPlugin.java:58) E/AndroidRuntime(29060): at com.dgmsolutions.foolivery.Application.registerWith(Application.kt:16) E/AndroidRuntime(29060): at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundExecutor.lambda$null$0$FlutterFirebaseMessagingBackgroundExecutor(FlutterFirebaseMessagingBackgroundExecutor.java:206) E/AndroidRuntime(29060): at io.flutter.plugins.firebase.messaging.-$$Lambda$FlutterFirebaseMessagingBackgroundExecutor$e4cdQ2b1x-adsVcO-hA2dn2VM8E.run(Unknown Source:6) E/AndroidRuntime(29060): at android.os.Handler.handleCallback(Handler.java:888) E/AndroidRuntime(29060): at android.os.Handler.dispatchMessage(Handler.java:100) E/AndroidRuntime(29060): at android.os.Looper.loop(Looper.java:213) E/AndroidRuntime(29060): at android.app.ActivityThread.main(ActivityThread.java:8178) E/AndroidRuntime(29060): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(29060): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) E/AndroidRuntime(29060): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) I/Process (29060): Sending signal. PID: 29060 SIG: 9 Lost connection to device.
my code (in the picture)
main class
application.kt
manifest.xml
notification class
Since you're running Flutter 2.0.1, you only need to configure the Flutter part of the firebase messaging plugin, and add your google-services.json files.
Read carefully the official documentation and you'll fix your problem :)
If you need a sample project showcasing how to implement the Firebase Notifications, you can take a look at this one

Exception in thread "Build Event Notification" java.lang.NoClassDefFoundError: Could not initialize class sun.security.ssl.SSLContextImpl$TLSContext

I want to build an app with Ionic V3 for Android but I have an issue when I build it on release.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:mergeDebugResources'.
java.lang.NoClassDefFoundError: Could not initialize class sun.security.ssl.SSLContextImpl$TLSContext
Exception in thread "Build Event Notification" java.lang.NoClassDefFoundError: Could not initialize class sun.security.ssl.SSLContextImpl$TLSContext
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.security.Provider$Service.getImplClass(Provider.java:1728)
at java.security.Provider$Service.newInstance(Provider.java:1686)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at javax.net.ssl.SSLContext.getInstance(SSLContext.java:156)
at com.crashlytics.reloc.org.apache.http.ssl.SSLContexts.createDefault(SSLContexts.java:51)
at com.crashlytics.reloc.org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:966)
at com.crashlytics.reloc.org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:56)
at com.crashlytics.api.net.proxy.ProxySettings.getClientFor(ProxySettings.java:56)
at com.crashlytics.api.RestfulWebApi.notifyBuildEvent(RestfulWebApi.java:1438)
at com.crashlytics.api.RestfulWebApi.access$100(RestfulWebApi.java:74)
at com.crashlytics.api.RestfulWebApi$10.run(RestfulWebApi.java:1371)
at java.lang.Thread.run(Thread.java:748)
It seems to be caused by Crashlytics (which I don't even use) which is integrated within this package https://github.com/dpa99c/cordova-plugin-firebasex.
When I build the app in debug mode, I still have the exception but the build proceed until the end and I still can run it on my phone.
How can I prevent this issue ? Is there anyway to disable entirely Crashlytics so I don't have this exception anymore ?
Thanks
Ok, so it was all because of the JDK version. I ended up updating the JDK and everything worked perfectly.

FlutterFirebaseAppRegistrar not found in release build of Flutter app

I have Firebase integrated into my Flutter project, for Storage. This works fine on my debug builds, but not in my release build.
The relevant lines from my pubspec.yaml:
# Firebase core
firebase_core: ^0.4.0+9
# Firebase cloud storage
firebase_storage: ^3.0.8
# Google analytics
firebase_analytics: ^5.0.2
The error I see on startup of the release app is:
2020-04-16 13:19:38.765 25613-25613/? W/ComponentDiscovery: Class io.flutter.plugins.firebase.storage.FlutterFirebaseAppRegistrar is not an found.
java.lang.ClassNotFoundException: io.flutter.plugins.firebase.storage.FlutterFirebaseAppRegistrar
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at java.lang.Class.forName(Class.java:379)
at com.google.firebase.components.h.a(:78)
at com.google.firebase.components.h.a(:71)
at c.a.b.c.<init>(:468)
at c.a.b.c.a(:354)
at c.a.b.c.a(:321)
at c.a.b.c.b(:305)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(:53)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2092)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2066)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(:47)
at android.app.ActivityThread.installProvider(ActivityThread.java:6983)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445)
at android.app.ActivityThread.access$1300(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.ClassNotFoundException: io.flutter.plugins.firebase.storage.FlutterFirebaseAppRegistrar
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:454) 
at java.lang.Class.forName(Class.java:379) 
at com.google.firebase.components.h.a(:78) 
at com.google.firebase.components.h.a(:71) 
at c.a.b.c.<init>(:468) 
at c.a.b.c.a(:354) 
at c.a.b.c.a(:321) 
at c.a.b.c.b(:305) 
at com.google.firebase.provider.FirebaseInitProvider.onCreate(:53) 
at android.content.ContentProvider.attachInfo(ContentProvider.java:2092) 
at android.content.ContentProvider.attachInfo(ContentProvider.java:2066) 
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(:47) 
at android.app.ActivityThread.installProvider(ActivityThread.java:6983) 
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445) 
at android.app.ActivityThread.access$1300(ActivityThread.java:219) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7356) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
Any idea what I'm doing wrong?

Firebase database getInstance crashes app

When running the sample after creating google-service.json, the app crashes when trying to get database reference in SignInActivity
mDatabase = FirebaseDatabase.getInstance().getReference();
Crash log
05-21 09:27:27.644 488-488/com.google.firebase.quickstart.database D/AndroidRuntime: Shutting down VM
05-21 09:27:27.644 488-488/com.google.firebase.quickstart.database E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.firebase.quickstart.database, PID: 488
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.firebase.quickstart.database/com.google.firebase.quickstart.database.SignInActivity}: com.google.firebase.database.DatabaseException: Failed to get
FirebaseDatabase instance: FirebaseApp object has no DatabaseURL in its FirebaseOptions object.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: com.google.firebase.database.DatabaseException: Failed to get FirebaseDatabase instance: FirebaseApp object has no DatabaseURL in its FirebaseOptions object.
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.google.firebase.quickstart.database.SignInActivity.onCreate(SignInActivity.java:39)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
How to fix this issue ?
Download google-services.json from Project Settings in the Firebase console. My mistake was downloading it from https://developers.google.com/mobile/add.
Changing google-services.json file didn't worked for me
later i found out
that i was using
implementation 'com.google.firebase:firebase-analytics:17.5.0'
implementation 'com.google.firebase:firebase-database:16.0.4'
instead of
implementation 'com.google.firebase:firebase-analytics-ktx:17.5.0'
implementation 'com.google.firebase:firebase-database-ktx:19.4.0'
mFirebaseDatabaseReference = database.getInstance().getReference("root-element in firebase");
When you call getReference you need to provide a URL. If your project is bound already in Firebase with the database you have created, use the root element of the data in Firebase as the parameter to getReference().

Resources