How can i fix This error in background notification handler? - firebase

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

Related

App crashes on launch after adding Firebase Authentication dependency

I'm integrating firebase authentication into my android project with firebase assistant. After integrating firebase auth, it adds a dependency implementation 'com.google.firebase:firebase-auth:21.0.1' . when I use this dependency app crashes on launch.
and this is the log cat error
2021-07-13 14:03:04.319 20371-20371/? E/.store.admi: Unknown bits set in runtime_flags: 0x8000
2021-07-13 14:03:04.719 20371-20371/app.store.admin W/.ugpapers.admi: Accessing hidden method Ljava/lang/invoke/LambdaMetafactory;->metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; (blacklist, linking, denied)
2021-07-13 14:03:04.719 20371-20371/app.store.admin D/AndroidRuntime: Shutting down VM
2021-07-13 14:03:04.720 20371-20371/app.store.admin E/AndroidRuntime: FATAL EXCEPTION: main
Process: app.ugpapers.admin, PID: 20371
java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar)
at com.google.firebase.components.ComponentDiscovery.discoverLazy(ComponentDiscovery.java:112)
at com.google.firebase.FirebaseApp.<init>(FirebaseApp.java:418)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:299)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:267)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:252)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2102)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2076)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45)
at android.app.ActivityThread.installProvider(ActivityThread.java:7430)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6934)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6851)
at android.app.ActivityThread.access$1600(ActivityThread.java:242)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:227)
at android.app.ActivityThread.main(ActivityThread.java:7822)
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:1026)
2021-07-13 14:03:04.739 20371-20371/app.store.admin I/Process: Sending signal. PID: 20371 SIG: 9
after referring to my old projects I used the old dependency implementation 'com.google.firebase:firebase-auth:20.0.4' and now it's working fine.
Why is the latest dependency not working for me? I'm testing my app on android 10 device.
Also if I add the latest firestore dependency, the app crash on launch.
what's going wrong here?

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.

Multiple transactions to same document failure in flutter firestore

I am been trying to implement multiple transactions to the same document in flutter application which is using firestore as a its database, but it is crashing the application. The same thing when it was implemented in native apps of Xcode or android studio this issue didn't occur for even once.
Is there any guide how to make multiple transactions successful in flutter firestore.
For Instance, if more than 1 user from different devices is making the transaction to the same document at the same time, the transaction fails and the app crashes.
How could this be resolved?
Firestore.instance.runTransaction((Transaction tx) async {
DocumentSnapshot postSnapshot = await tx.get(docRef);
if (postSnapshot.exists) {
await tx.update(docRef, <String, dynamic>{'likes': postSnapshot.data['likes'] + 1});
// print("transaction completed");
}
})
ERROR LOGS
2020-05-27 18:43:14.529 1022-1344/dev.jideguru.social_app_ui
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4 Process:
dev.jideguru.social_app_ui, PID: 1022 java.lang.RuntimeException: An
error occurred while executing doInBackground() at
android.os.AsyncTask$3.done(AsyncTask.java:353) at
java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271) at
android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764) Caused by:
java.lang.AssertionError: INTERNAL ASSERTION FAILED: A transaction
object cannot be used after its update callback has been invoked. at
com.google.firebase.firestore.util.Assert.fail(com.google.firebase:firebase-firestore##21.3.0:46)
at
com.google.firebase.firestore.util.Assert.hardAssert(com.google.firebase:firebase-firestore##21.3.0:31)
at
com.google.firebase.firestore.core.Transaction.ensureCommitNotCalled(com.google.firebase:firebase-firestore##21.3.0:246)
at
com.google.firebase.firestore.core.Transaction.lookup(com.google.firebase:firebase-firestore##21.3.0:81)
at
com.google.firebase.firestore.Transaction.getAsync(com.google.firebase:firebase-firestore##21.3.0:191)
at
com.google.firebase.firestore.Transaction.get(com.google.firebase:firebase-firestore##21.3.0:228)
at
io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$5.doInBackground(CloudFirestorePlugin.java:613)
at
io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$5.doInBackground(CloudFirestorePlugin.java:608)
at android.os.AsyncTask$2.call(AsyncTask.java:333) at
java.util.concurrent.FutureTask.run(FutureTask.java:266) at
android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764) 2020-05-27 18:43:14.529
1022-1346/dev.jideguru.social_app_ui E/AndroidRuntime: FATAL
EXCEPTION: AsyncTask #6 Process: dev.jideguru.social_app_ui, PID: 1022
java.lang.RuntimeException: An error occurred while executing
doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:353) at
java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271) at
android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764) Caused by:
java.lang.AssertionError: INTERNAL ASSERTION FAILED: A transaction
object cannot be used after its update callback has been invoked. at
com.google.firebase.firestore.util.Assert.fail(com.google.firebase:firebase-firestore##21.3.0:46)
at
com.google.firebase.firestore.util.Assert.hardAssert(com.google.firebase:firebase-firestore##21.3.0:31)
at
com.google.firebase.firestore.core.Transaction.ensureCommitNotCalled(com.google.firebase:firebase-firestore##21.3.0:246)
at
com.google.firebase.firestore.core.Transaction.lookup(com.google.firebase:firebase-firestore##21.3.0:81)
at
com.google.firebase.firestore.Transaction.getAsync(com.google.firebase:firebase-firestore##21.3.0:191)
at
com.google.firebase.firestore.Transaction.get(com.google.firebase:firebase-firestore##21.3.0:228)
at
io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$5.doInBackground(CloudFirestorePlugin.java:613)
at
io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$5.doInBackground(CloudFirestorePlugin.java:608)
at android.os.AsyncTask$2.call(AsyncTask.java:333) at
java.util.concurrent.FutureTask.run(FutureTask.java:266) at
android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Link To the Issue
Caused by: java.lang.AssertionError: INTERNAL ASSERTION FAILED: A transaction object cannot be used after its update callback has been invoked.
It looks like the transaction is being used after it's been committed/canceled.
This is a known issue in the FlutterFire library, as recorded in this issue on the open-source repo.
There is a workaround mentioned in this comment. So you can either try to apply that to your case, propose a PR that fixes the bug, or wait until somebody else fixes it.

FirebaseRemoteConfig.getInstance crashes with NullPointerException

I'm seeing bunch of crashes inside Crashlitics which are coming from most recent Firebase 15.0.0 on attempt to get FirebaseRemoteConfig
Caused by java.lang.NullPointerException
Attempt to invoke virtual method 'void com.google.android.gms.internal.config.zzar.zzc(long)' on a null object reference
com.google.firebase.remoteconfig.FirebaseRemoteConfig. (Unknown Source)
com.google.firebase.remoteconfig.FirebaseRemoteConfig.getInstance (Unknown Source)
com.google.firebase.remoteconfig.FirebaseRemoteConfig.getInstance (Unknown Source)
FirebaseRemoteConfig.getInstance is called during Application.onCreate and it worked fine on all previous versions.
Build:
implementation "com.google.firebase:firebase-config:15.0.0"
classpath 'com.google.gms:google-services:3.2.1'
Does anyone see it? Any solutions or workarounds?
P.S. I've sent bug report to firebase team via https://firebase.google.com/support/contact/bugs-features/
https://github.com/firebase/quickstart-android/issues/474
According to https://github.com/firebase/quickstart-android/issues/474 is't fixed with 15.0.2 update to Firebase RemoteConfig

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