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.
Related
After upgrading unity version from 2019 to 2020
Crash intermittently when switching scenes.
So I tried to view the backtrace through firebase crashlytics, but I can't see the backtrace with the error below.
2022-03-11 16:58:10.102 21274-21274/? E/AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: main
java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/com.myapp/lib/arm/libcrashlytics-handler.so" has unexpected e_machine: 40
at com.google.firebase.crashlytics.ndk.CrashpadMain.main(CrashpadMain.java:31)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:301)
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/com.myapp/lib/arm/libcrashlytics-handler.so" has unexpected e_machine: 40
at java.lang.Runtime.load0(Runtime.java:908)
at java.lang.System.load(System.java:1537)
at com.google.firebase.crashlytics.ndk.CrashpadMain.main(CrashpadMain.java:29)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:301)
2022-03-11 16:58:10.107 21274-21274/? E/AndroidRuntime: Error reporting crash
java.lang.RuntimeException: Bad file descriptor
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:615)
at android.os.ServiceManagerProxy.getService(ServiceManagerNative.java:123)
at android.os.ServiceManager.getService(ServiceManager.java:55)
at android.app.ActivityManagerNative$1.create(ActivityManagerNative.java:3049)
at android.app.ActivityManagerNative$1.create(ActivityManagerNative.java:3048)
at android.util.Singleton.get(Singleton.java:34)
at android.app.ActivityManagerNative.getDefault(ActivityManagerNative.java:86)
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:123)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
First of all, I checked that "libcrashlytics-handler.so" is in that location and it is there.
And I tried to upgrade the version of the sdk to the latest version of 8.8.0, but it was not resolved.
Does anyone know about this issue? I need your help.
unity version : 2020.3.29f
firebase sdk : 8.8.0
android : 7.1.2(Emulator)
Everything was working fine. I did not change any code. Today some of my users can not download files from firebase storage and others can download the files.
Non-fatal Exception: com.google.firebase.storage.StorageException: The operation retry limit has been exceeded.
at com.google.firebase.storage.network.NetworkRequest.completeTask(NetworkRequest.java:539)
at com.google.firebase.storage.GetDownloadUrlTask.run(GetDownloadUrlTask.java:85)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by java.io.IOException
at com.google.firebase.storage.network.NetworkRequest.parseResponse(NetworkRequest.java:445)
at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(NetworkRequest.java:462)
at com.google.firebase.storage.network.NetworkRequest.processResponseStream(NetworkRequest.java:453)
at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:272)
at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:289)
at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:113)
at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:68)
at com.google.firebase.storage.GetDownloadUrlTask.run(GetDownloadUrlTask.java:77)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
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?
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
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().