dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 528 forks source link

Firestore "DEADLINE_EXCEEDED" error in Release, but not in Debug mode #8378

Closed CostasAthan closed 5 months ago

CostasAthan commented 1 year ago

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

VS 2022 17.7.4

Description

The Android app of a Xamarin.Android project I develop gives a "DEADLINE_EXCEEDED" error when run under "Release" configuration, but runs without any issues in "Debug" mode.

The error happens both on physical devices and when using the emulator. I also have tried different Android API levels (both on phones and on the emulator), but that makes no difference.

Steps to Reproduce

  1. Create an Android app that uses Firestore.
  2. Deploy the app under Release configuration.
  3. The "DEADLINE_EXCEEDED" error arises.

Did you find any workaround?

No response

Relevant log output

No response

grendello commented 1 year ago

This is unlikely to be a problem with Xamarin.Android, the error appears to be server side. Please check some solutions suggested elsewhere:

If you still think this is caused by some issue in Xamarin.Android, please provide logs gathered by issuing the following commands at the developer prompt:

> adb shell setprop debug.mono.level default,assembly,timing=bare,mono_log_level=debug,mono_log_mask=all
> adb logcat -G 16M
> adb logcat -c
rem Run the application here and wait for the error to occur, then wait a few seconds more followed by:
> adb logcat -d > logcat.txt

And attach the resulting logcat.txt file here.

CostasAthan commented 1 year ago

I'm afraid I didn't pay attention and I gave a wrong error. The right one is: _crc64[alphanumeric string].CrashlyticsException: Java.Lang.IncompatibleClassChnageError: no "Lcom/google/firebase/firestore/FirebaseFirestoreException$Code;" field "DEADLINEEXCEEDED" in class "Lcom/google/firebase/firestore/FirebaseFirestoreException$Code;" or its super classes

moljac commented 1 year ago

no field in class or its superclass

Checking generated code in:

./generated/com.google.firebase.firebase-firestore/obj/Release/monoandroid12.0/generated/src/Firebase.Firestore.FirebaseFirestoreException.cs

Found code:

            // Metadata.xml XPath field reference: path="/api/package[@name='com.google.firebase.firestore']/class[@name='FirebaseFirestoreException.Code']/field[@name='DEADLINE_EXCEEDED']"
            [Register ("DEADLINE_EXCEEDED")]
            public static global::Firebase.Firestore.FirebaseFirestoreException.Code DeadlineExceeded {
                get {
                    const string __id = "DEADLINE_EXCEEDED.Lcom/google/firebase/firestore/FirebaseFirestoreException$Code;";

                    var __v = _members.StaticFields.GetObjectValue (__id);
                    return global::Java.Lang.Object.GetObject<global::Firebase.Firestore.FirebaseFirestoreException.Code> (__v.Handle, JniHandleOwnership.TransferLocalRef);
                }
            }

gives a "DEADLINE_EXCEEDED" error when run under "Release" configuration, but runs without any issues in "Debug" mode.

This (Release crash, Debug OK) indicates that R8/proguard caused removal of that field (very high probability). Try adding proguard rules to the app.

CostasAthan commented 1 year ago

@moljac Added a .cfg file to the Android project (Build Action: ProguardConfiguration) with the following rule: -keep class com.google.firebase.** { *; } No luck! Same error...

moljac commented 1 year ago

-keep class com.google.firebase.** { *; }

OK. This would keep all Firebase stuff. Maybe too much.

Can you try -keepclassmembersand -keepclasseswithmembers

Something like:

# preserve private fields in all classes use
-keepclassmembers class * {
    private <fields>;    
}

Start with that and increase specificity until

-keepclassmembers class com.google.firebase.firestore.FirebaseFirestoreException.Code {
    private <fields>;    
}

maybe (note $):

-keepclassmembers class com.google.firebase.firestore.FirebaseFirestoreException$Code {
    public static <fields>;    
}

Some samples

https://gist.github.com/lingarajsankaravelu/db4dae89dcbc5b5346a0154791802af5

moljac commented 1 year ago

BTW which version of Firestore do yo use?

CostasAthan commented 1 year ago

@moljac

Actually after a couple of tries the error changed, so the rule worked. (Maybe a cached version of the app ran initially?)

Now the error is: crc64[alphanumeric string].CrashlyticsException: Plugin.CloudFirestore.CloudFirestoreException: Failed to get document because the client is offline

I will address the issue of the generic rule I used after solving the new error. I will try to use the most specific one, but my priority is to fix the last error.

By the way, I use version 3.3.0.

CostasAthan commented 1 year ago

@moljac

-keepclassmembers class com.google.firebase.firestore.FirebaseFirestoreException$Code { <fields>; } works fine.

As for the new error, it is definitely an error that happens during linking. When I set the linking to "None" it vanishes. I'm not sure how to deal with it though.

moljac commented 1 year ago

As for the new error, it is definitely an error that happens during linking. When I set the linking to "None" it vanishes. I'm not sure how to deal with it though.

Can you provide more info please;

CostasAthan commented 1 year ago

Here you go:

Fatal Exception: crc64[alphanumeric_string].CrashlyticsException: Plugin.CloudFirestore.CloudFirestoreException: Failed to get document because the client is offline. at MyApp.MyPage (System.Object sender, System.EventArgs e)() at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b7_0 (System.Object state)() at Android.App.SyncContext+<>c__DisplayClass2_0.b0 ()() at Java.Lang.Thread+RunnableImplementor.Run ()() at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)() at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V (_JniMarshal_PP_V callback, System.IntPtr jnienv, System.IntPtr klazz)() at (Inner Exception) Firebase.Firestore.FirebaseFirestoreException: Failed to get document because the client is offline.()

ReferenceQueueDaemon: at java.lang.Object.wait(Object.java) at java.lang.Object.wait(Object.java:442) at java.lang.Object.wait(Object.java:568) at java.lang.Daemons$ReferenceQueueDaemon.runInternal(Daemons.java:217) at java.lang.Daemons$Daemon.run(Daemons.java:139) at java.lang.Thread.run(Thread.java:923)

ConnectivityThread: at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loop(Looper.java:183) at android.os.HandlerThread.run(HandlerThread.java:67)

grpc-default-executor-1: at sun.misc.Unsafe.park(Unsafe.java) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230) at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:461) at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362) at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:937) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1091) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)

pool-3-thread-1: at sun.misc.Unsafe.park(Unsafe.java) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2109) at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1091) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)

FirebaseInstanceId: at sun.misc.Unsafe.park(Unsafe.java) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:190) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2067) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1120) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:849) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1092) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at com.google.android.gms.common.util.concurrent.zza.run(SourceFile:7) at java.lang.Thread.run(Thread.java:923)

OkHttp ConnectionPool: at java.lang.Object.wait(Object.java) at com.android.okhttp.ConnectionPool$1.run(ConnectionPool.java:106) 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:923)

FinalizerWatchdogDaemon: at java.lang.Object.wait(Object.java) at java.lang.Object.wait(Object.java:442) at java.lang.Object.wait(Object.java:568) at java.lang.Daemons$FinalizerWatchdogDaemon.sleepUntilNeeded(Daemons.java:341) at java.lang.Daemons$FinalizerWatchdogDaemon.runInternal(Daemons.java:321) at java.lang.Daemons$Daemon.run(Daemons.java:139) at java.lang.Thread.run(Thread.java:923)

Measurement Worker: at java.lang.Object.wait(Object.java) at java.lang.Object.wait(Object.java:442) at com.google.android.gms.measurement.internal.zzfy.run(SourceFile:97)

GoogleApiHandler: at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loop(Looper.java:183) at android.os.HandlerThread.run(HandlerThread.java:67)

Okio Watchdog: at java.lang.Object.wait(Object.java) at java.lang.Object.wait(Object.java:442) at okio.AsyncTimeout.awaitTimeout(SourceFile:16) at okio.AsyncTimeout$Watchdog.run(SourceFile:4)

grpc-default-executor-0: at sun.misc.Unsafe.park(Unsafe.java) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230) at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:461) at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362) at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:937) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1091) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)

com.google.firebase.crashlytics.startup1: at sun.misc.Unsafe.park(Unsafe.java) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:190) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2067) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1092) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at com.google.firebase.crashlytics.internal.common.ExecutorUtils$1$1.onRun(:2) at com.google.firebase.crashlytics.internal.common.BackgroundPriorityRunnable.run(SourceFile:6) at java.lang.Thread.run(Thread.java:923)

FinalizerDaemon: at java.lang.Object.wait(Object.java) at java.lang.Object.wait(Object.java:442) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:190) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:211) at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:273) at java.lang.Daemons$Daemon.run(Daemons.java:139) at java.lang.Thread.run(Thread.java:923)

awaitEvenIfOnMainThread task continuation executor1: at sun.misc.Unsafe.park(Unsafe.java) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:190) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2067) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1092) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at com.google.firebase.crashlytics.internal.common.ExecutorUtils$1$1.onRun(:2) at com.google.firebase.crashlytics.internal.common.BackgroundPriorityRunnable.run(SourceFile:6) at java.lang.Thread.run(Thread.java:923)

FirestoreWorker: at sun.misc.Unsafe.park(Unsafe.java) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2109) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1132) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:849) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1092) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(SourceFile:16) at java.lang.Thread.run(Thread.java:923)

OkHttp ConnectionPool: at java.lang.Object.wait(Object.java) at okhttp3.ConnectionPool$1.run(SourceFile:38) 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:923)

TokenRefresher: at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loop(Looper.java:183) at android.os.HandlerThread.run(HandlerThread.java:67)

MessengerIpcClient: at sun.misc.Unsafe.park(Unsafe.java) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:190) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2067) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1120) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:849) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1092) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at com.google.android.gms.common.util.concurrent.zza.run(SourceFile:7) at java.lang.Thread.run(Thread.java:923)

grpc-timer-0: at sun.misc.Unsafe.park(Unsafe.java) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2109) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1132) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:849) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1092) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)

Crashlytics Exception Handler1: at dalvik.system.VMStack.getThreadStackTrace(VMStack.java) at java.lang.Thread.getStackTrace(Thread.java:1736) at java.lang.Thread.getAllStackTraces(Thread.java:1812) at com.google.firebase.crashlytics.internal.common.CrashlyticsReportDataCapture.captureEventData(SourceFile:123) at com.google.firebase.crashlytics.internal.common.SessionReportingCoordinator.persistEvent(SourceFile:31) at com.google.firebase.crashlytics.internal.common.SessionReportingCoordinator.persistFatalEvent(:7) at com.google.firebase.crashlytics.internal.common.CrashlyticsController$6.call(SourceFile:29) at com.google.firebase.crashlytics.internal.common.CrashlyticsController$21.then(SourceFile:1) at com.google.android.gms.tasks.zzc.run(SourceFile:247) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at com.google.firebase.crashlytics.internal.common.ExecutorUtils$1$1.onRun(:2) at com.google.firebase.crashlytics.internal.common.BackgroundPriorityRunnable.run(SourceFile:6) at java.lang.Thread.run(Thread.java:923)

InsetsAnimations: at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loop(Looper.java:183) at android.os.HandlerThread.run(HandlerThread.java:67)

queued-work-looper: at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loop(Looper.java:183) at android.os.HandlerThread.run(HandlerThread.java:67)

Okio Watchdog: at java.lang.Object.wait(Object.java) at java.lang.Object.wait(Object.java:442) at java.lang.Object.wait(Object.java:568) at com.android.okhttp.okio.AsyncTimeout.awaitTimeout(AsyncTimeout.java:313) at com.android.okhttp.okio.AsyncTimeout.access$000(AsyncTimeout.java:42) at com.android.okhttp.okio.AsyncTimeout$Watchdog.run(AsyncTimeout.java:288)

AsyncTask #1: at sun.misc.Unsafe.park(Unsafe.java) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:190) at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:459) at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362) at java.util.concurrent.SynchronousQueue.take(SynchronousQueue.java:920) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1092) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)

pool-7-thread-1: at sun.misc.Unsafe.park(Unsafe.java) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:190) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2067) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1092) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)

moljac commented 1 year ago

Do you have logcat?

jonpryor commented 1 year ago

@CostasAthan: reiterating @moljac 's comment, do you have full(er) adb logcat output?

In particular, this part of your most recent comment leaves me wanting more:

Fatal Exception: crc64[alphanumeric_string].CrashlyticsException: Plugin.CloudFirestore.CloudFirestoreException: Failed to get document because the client is offline.
  at MyApp.MyPage (System.Object sender, System.EventArgs e)()
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state)()
  at Android.App.SyncContext+<>c__DisplayClass2_0.b__0 ()()
  at Java.Lang.Thread+RunnableImplementor.Run ()()
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)()
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V (_JniMarshal_PP_V callback, System.IntPtr jnienv, System.IntPtr klazz)()
  at (Inner Exception) Firebase.Firestore.FirebaseFirestoreException: Failed to get document because the client is offline.()

In particular, I want the full exception output for the nested FirebaseFirestoreException. This should be printed as part of the UNHANDLED EXCEPTION message which is printed as part of the .NET Android crash logging, but will not be part of the builtin Android crash logging. I suspect that your log information is from the Android crash logging output, not "full" adb logcat output.

CostasAthan commented 1 year ago

@jonpryor

How can I get the data you suggest? In Release mode I don't see any errors through the IDE and the error happens only in Release configuration.

CostasAthan commented 1 year ago

Running the app on Debug mode with linking enabled I get the following 2 unhandled exceptions:

System.ArgumentException: 'Type 'MyApp.DatabaseFields+TableFields' does not have a default constructor Parameter name: type'

Here is the line that causes the 1st one:

if (myDocument.ToObject<DatabaseFields>().myString1 == "string1")

That's the file that models the database's fields. Here is my code:

internal class DatabaseFields
{
    public class TableFields
    {
        public string myString1 { get; set; }

        public string myString2 { get; set; }
    }
}

When I hit the "Continue" button I get the following error:

System.TypeInitializationException: 'The type initializer for 'CreatorCache`1' threw an exception.'

All these happen when linking is enabled. Disabling the linking makes the errors to vanish.

CostasAthan commented 1 year ago

A few things to add...

The error in Release mode happens also with linking set to "Sdk Assemblies Only", so I guess it does not come from nugget packages, right?

Furthermore, even though I have enabled debugging in the Release configuration ("Enable developer instrumentation (debugging and profiling)"), trying to follow @jonpryor suggestion, I get this message in Visual Studio:

Android application is running (debug is disabled in android project properties).

Anyway, I have enabled linking in Debug mode. I hope the results are equivalent. In this message I have listed the errors I get with Debug configuration when linking is enabled: https://github.com/xamarin/xamarin-android/issues/8378#issuecomment-1745398610

edit: The errors in Debug mode happen only when the linking is set to "Sdk and User Assemblies", in contrast with Release mode in which the error arises regardless if linking is set to "Sdk Assemblies Only" or "Sdk and User Assemblies".

jonpryor commented 1 year ago

@CostasAthan asked:

How can I get the data you suggest?

By using the adb command. Within Visual Studio, click Tools > Android > Android Adb Command Prompt…. This will open a new cmd.exe window which has adb in %PATH%.

Then, before launching your app, run:

adb logcat > log.txt

then run your app. Once your app has crashed, return to the cmd.exe window, and type Ctrl+C to exit adb logcat. You can then read or upload log.txt.

jonpryor commented 1 year ago

@CostasAthan wrote:

I get the following 2 unhandled exceptions:

System.ArgumentException: 'Type 'MyApp.DatabaseFields+TableFields' does not have a default constructor Parameter name: type'

The linker and reflection don't always mix well. My assumption is that this expression:

myDocument.ToObject<DatabaseFields>()

involves Reflection, and tries to use the DatabaseFields+TableFields constructor. The linker doesn't know about this, and thus the linker has removed the constructor.

The fix for this is one of:

  1. Don't link that assembly, or
  2. "Somewhere" in code that is not linked away, use the DatabaseFields+TableFields constructor, a'la new TableFields(), or
  3. Tell the linker to preserve the constructor.

(3) can be done via custom attributes such as DynamicallyAccessedMembersAttribute or XML descriptors

System.TypeInitializationException: 'The type initializer for 'CreatorCache`1' threw an exception.

Similar to my other question regarding exceptions, the nested exception is hugely important, and is missing here. What exception did CreatorCache`1 throw? What's the message + callstack? Presumably this is another circumstance where Reflection is being used, and the linker has removed whatever CreatorCache`1 requires.

CostasAthan commented 1 year ago

I think here is the relevant part of the log file.

10-06 22:03:51.792 16798 16798 I MonoDroid: UNHANDLED EXCEPTION: 10-06 22:03:51.794 16798 16798 I MonoDroid: Plugin.FirebaseCrashlytics.CrashlyticsException: Exception of type 'Plugin.FirebaseCrashlytics.CrashlyticsException' was thrown. 10-06 22:03:51.794 16798 16798 I MonoDroid: --- End of managed Plugin.FirebaseCrashlytics.CrashlyticsException stack trace --- 10-06 22:03:51.794 16798 16798 I MonoDroid: crc[alphanumeric_string].CrashlyticsException: Plugin.CloudFirestore.CloudFirestoreException: Failed to get document because the client is offline. 10-06 22:03:51.794 16798 16798 I MonoDroid: at MyApp.App.Loader ()(:0) 10-06 22:03:51.794 16798 16798 I MonoDroid: at MyApp.App.<.ctor>b0_0 ()(:0) 10-06 22:03:51.794 16798 16798 I MonoDroid: at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state)(:0) 10-06 22:03:51.794 16798 16798 I MonoDroid: at Android.App.SyncContext+<>cDisplayClass2_0.b__0 ()(:0) 10-06 22:03:51.794 16798 16798 I MonoDroid: at Java.Lang.Thread+RunnableImplementor.Run ()(:0) 10-06 22:03:51.794 16798 16798 I MonoDroid: at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)(:0) 10-06 22:03:51.794 16798 16798 I MonoDroid: at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V (_JniMarshal_PP_V callback, System.IntPtr jnienv, System.IntPtr klazz)(:0) 10-06 22:03:51.794 16798 16798 I MonoDroid: at (Inner Exception) Firebase.Firestore.FirebaseFirestoreException: Failed to get document because the client is offline.(:0) 10-06 22:03:51.794 16798 16798 I MonoDroid: 10-06 22:03:51.798 1727 8043 W ActivityTaskManager: Force finishing activity com.my.app/crc[alphanumeric_string].MainActivity 10-06 22:03:51.798 1727 16869 I DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2 10-06 22:03:51.799 2481 24431 D LauncherFsGestureCompat: componentName is com.my.app/crc[alphanumeric_string].MainActivity 10-06 22:03:51.801 1727 8043 D ActivityTrigger: ActivityTrigger activityPauseTrigger 10-06 22:03:51.804 24428 16474 W NetworkScheduler: Error inserting flex_time=0 job_id=-1 period=2000 source=16 requires_charging=0 preferred_network_type=1 target_class=com.google.android.gms.measurement.PackageMeasurementTaskService user_id=0 target_package=com.google.android.gms tag=Measurement.PackageMeasurementTaskService.UPLOAD_TASK_TAG task_type=0 required_idleness_state=0 service_kind=0 source_version=233717000 persistence_level=1 preferred_charging_state=1 required_network_type=0 runtime=1696619031801 retry_strategy={"maximum_backoff_seconds":{"3600":0},"initial_backoff_seconds":{"30":0},"retry_policy":{"0":0}} last_runtime=0 [CONTEXT service_id=218 ] 10-06 22:03:51.804 24428 16474 W NetworkScheduler: android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: pending_ops.tag, pending_ops.target_class, pending_ops.target_package, pending_ops.user_id (code 2067 SQLITE_CONSTRAINT_UNIQUE) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:879) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:790) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:88) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1599) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at android.database.sqlite.SQLiteDatabase.insertOrThrow(SQLiteDatabase.java:1494) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at byou.f(:com.google.android.gms@233717028@23.37.17 (100400-570218080):721) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at byno.n(:com.google.android.gms@233717028@23.37.17 (100400-570218080):29) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at byno.u(:com.google.android.gms@233717028@23.37.17 (100400-570218080):225) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at byno.h(:com.google.android.gms@233717028@23.37.17 (100400-570218080):54) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at byjh.run(:com.google.android.gms@233717028@23.37.17 (100400-570218080):72) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at ajds.c(:com.google.android.gms@233717028@23.37.17 (100400-570218080):50) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at ajds.run(:com.google.android.gms@233717028@23.37.17 (100400-570218080):76) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at ajiy.run(:com.google.android.gms@233717028@23.37.17 (100400-570218080):8) 10-06 22:03:51.804 24428 16474 W NetworkScheduler: at java.lang.Thread.run(Thread.java:919) 10-06 22:03:51.808 1727 1862 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver 10-06 22:03:51.808 1727 1862 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver 10-06 22:03:51.814 16798 16798 I Process : Sending signal. PID: 16798 SIG: 9 10-06 22:03:51.819 1727 2227 I MiuiNetworkPolicy: updateUidState uid = 10013, uidState = 2 10-06 22:03:51.819 1727 2227 I MiuiNetworkPolicy: updateWmmForUidState uid: 10013 state: 2 wmm: 1 10-06 22:03:51.819 673 21660 D OemNetd : updateWmm: uid=10013, wmm=1 10-06 22:03:51.824 1727 2227 I MiuiNetworkPolicy: updateMLUid uid:10013,old:6,new:2 10-06 22:03:51.824 1727 2227 I MiuiNetworkPolicy: isMLEnabled state:6,uid:10013,connect:DISCONNECTED 10-06 22:03:51.824 1727 2227 I MiuiNetworkPolicy: isMLEnabled state:2,uid:10013,connect:DISCONNECTED 10-06 22:03:51.831 1727 3093 D CompatibilityInfo: mCompatibilityFlags - 0 10-06 22:03:51.831 1727 3093 D CompatibilityInfo: applicationDensity - 440 10-06 22:03:51.831 1727 3093 D CompatibilityInfo: applicationScale - 1.0 10-06 22:03:51.831 568 568 E SELinux : avc: denied { find } for interface=vendor.qti.hardware.servicetracker::IServicetracker sid=u:r:system_server:s0 pid=1727 scontext=u:r:system_server:s0 tcontext=u:object_r:default_android_hwservice:s0 tclass=hwservice_manager permissive=0 10-06 22:03:51.859 568 568 E SELinux : avc: denied { find } for interface=vendor.qti.hardware.servicetracker::IServicetracker sid=u:r:system_server:s0 pid=1727 scontext=u:r:system_server:s0 tcontext=u:object_r:default_android_hwservice:s0 tclass=hwservice_manager permissive=0 10-06 22:03:51.864 24428 16549 W NetworkScheduler: Error inserting flex_time=9000 job_id=-1 period=20000 source=16 requires_charging=0 preferred_network_type=1 target_class=com.google.android.gms.measurement.PackageMeasurementTaskService user_id=0 target_package=com.google.android.gms tag=Measurement.PackageMeasurementTaskService.UPLOAD_TASK_TAG task_type=0 required_idleness_state=0 service_kind=0 source_version=233717000 persistence_level=1 preferred_charging_state=1 required_network_type=0 runtime=1696619031853 retry_strategy={"maximum_backoff_seconds":{"3600":0},"initial_backoff_seconds":{"30":0},"retry_policy":{"0":0}} last_runtime=0 [CONTEXT service_id=218 ] 10-06 22:03:51.864 24428 16549 W NetworkScheduler: android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: pending_ops.tag, pending_ops.target_class, pending_ops.target_package, pending_ops.user_id (code 2067 SQLITE_CONSTRAINT_UNIQUE) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:879) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:790) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:88) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1599) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at android.database.sqlite.SQLiteDatabase.insertOrThrow(SQLiteDatabase.java:1494) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at byou.f(:com.google.android.gms@233717028@23.37.17 (100400-570218080):721) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at byno.n(:com.google.android.gms@233717028@23.37.17 (100400-570218080):29) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at byno.u(:com.google.android.gms@233717028@23.37.17 (100400-570218080):225) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at byno.h(:com.google.android.gms@233717028@23.37.17 (100400-570218080):54) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at byjh.run(:com.google.android.gms@233717028@23.37.17 (100400-570218080):72) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at ajds.c(:com.google.android.gms@233717028@23.37.17 (100400-570218080):50) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at ajds.run(:com.google.android.gms@233717028@23.37.17 (100400-570218080):76) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at ajiy.run(:com.google.android.gms@233717028@23.37.17 (100400-570218080):8) 10-06 22:03:51.864 24428 16549 W NetworkScheduler: at java.lang.Thread.run(Thread.java:919) 10-06 22:03:51.881 1727 2212 W InputDispatcher: channel '75927c4 com.my.app/crc[alphanumeric_string].MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 10-06 22:03:51.881 1727 2212 E InputDispatcher: channel '75927c4 com.my.app/crc[alphanumeric_string].MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 10-06 22:03:51.883 1727 3931 I WindowManager: WIN DEATH: Window{75927c4 u0 com.my.app/crc[alphanumeric_string].MainActivity} 10-06 22:03:51.883 1727 2189 I ActivityManager: Process com.my.app (pid 16798) has died: fore TOP 10-06 22:03:51.883 1727 3931 W InputDispatcher: Attempted to unregister already unregistered input channel '75927c4 com.my.app/crc[alphanumeric_string].MainActivity (server)' 10-06 22:03:51.886 674 674 I Zygote : Process 16798 exited due to signal 9 (Killed)

jpobst commented 5 months ago

With support for Classic Xamarin.Android ended May 1st, 2024, this issue is likely no longer relevant.

If this still persists in .NET 8+, please open a new issue with updated information based on net8.0-android or greater. Please include a link to this issue for context.