CSharpShellApp icon indicating copy to clipboard operation
CSharpShellApp copied to clipboard

Installed APK crash after start

Open Alisis33 opened this issue 2 years ago • 5 comments

2 APKs I made work well on some devices. But on one they crash emediatly afte start without any hint why. Is there a way to report/log the cause of a crash, for example to compile a debug version? A try-catch in the main() did not work.

Alisis33 avatar Jun 05 '22 15:06 Alisis33

Yes, it is relatively easy to setup. For Xamarin.Forms do it in the App.cs file, before InitializeComponent. Try just a popup dialog for the 'Log' method.

        AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
        TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
        AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironmentOnUnhandledException;
		
		
	private void AndroidEnvironmentOnUnhandledException(object sender, RaiseThrowableEventArgs e)
        {
            e.Handled = true;
            Log(e.Exception);
        }
		
	private void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
        {
            e.SetObserved();
            Log(e.Exception);
        }
		
	private void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
	     Log(e.ExceptionObject as Exception);
        }
		
		

Or use an app called Logcat Reader and filter by package name. But this app requires granting a permission via ADB from a PC.

radimitrov avatar Jun 05 '22 17:06 radimitrov

Tanks muck, I will try it out.

(No PC and electricity, I work on a solar pannel and a phone only :-)

Alisis33 avatar Jun 05 '22 22:06 Alisis33

Tanks much! I needed a day to find the bug, it was RunOnUiThread related

Alisis33 avatar Jun 07 '22 20:06 Alisis33

I get it don do shoot down a code with a stack overflow with a infnite recursion. This was not catched with any of the exeption handlers. (because I worked on differend code parts, it taken a while before I found he error) Is thete a way to catch a stack overflow, at least in the IDE to write a log before its hart crash? I ask too because of curiosity, there are exceptions which can not be handeled? Not even from the IDE?

https://learn.microsoft.com/en-us/dotnet/api/system.stackoverflowexception?redirectedfrom=MSDN&view=net-6.0

Alisis33 avatar Nov 03 '22 13:11 Alisis33

No, StackOverflow is the one exception that silently crashes the entire shared runtime since there is no way to internally catch it. I've implemented a very, very basic "stack overflow" analyzer/catcher in the IDE's debug mode, so that might work for some cases.

radimitrov avatar Nov 03 '22 14:11 radimitrov