Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin App runs on debug but crashes on release

My Xamarin application works perfectly on debug mode but crashes on release mod. I get this error: "Unfortunately App has stopped". I connected my phone through USB and when I run the app in release mode I get this error.

Unfortunately I can't debug the app in release mod because I get this message in the Output window: "Android application is running (debug is disabled in android project properties)", although the "Enable developer instrumentation" box is checked. I tried all linking alternative None/SDK/SDK and User but still doesn't work.

Is there a way to see what causes the crash, in a log file or something else ?

like image 381
Ionuț Gabriel Pițigoi Avatar asked Apr 04 '18 11:04

Ionuț Gabriel Pițigoi


2 Answers

After struggling for hours, in my case it was because I was using a static resource from within App.xaml file while defining another resource above the declaration. The weird thing is that it worked perfectly in debug mode but for some reason, kept crashing in release mode. After pinpointing the issue, I reordered the declarations and the issue was resolved.

Regardless, what you can do is wrap the entire onCreate block in your MainActivity inside a try catch block and log the exception somewhere, e.g. a public http request logger or write it to a file. At the time of this writing, RequestBin had such free service. After creating an endpoint, just make a post request to the url with exception message as data. Here's an example :

protected override void OnCreate(Bundle bundle)
{
    try
    {
        // oncreate logic
    }
    catch(Exception ex)
    {
        var client = new HttpClient();
        client.PostAsync("your logger api url", new StringContent(ex.ToString())).Wait();
    }
}

Hope this helps someone.

like image 108
chaosifier Avatar answered Oct 04 '22 00:10

chaosifier


Can you try the following

  1. Uninstall your local app that was deployed under Debug mode manually. Deploy Release app.

  2. Update your version of Xamarin

  3. Project setting → Android Options → Linker → Configuration = Release; Linking = Sdk Assemblies Only

like image 25
VenkyDhana Avatar answered Oct 03 '22 22:10

VenkyDhana