7

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 ?

  • It would be awesome if you could provide a [mcve]. – mjwills Apr 04 '18 at 11:22
  • You can turn on debugging in release mode – TheGeneral Apr 04 '18 at 11:34
  • Anyway https://stackoverflow.com/questions/4424544/where-are-android-logcat-files-stored what do the logcat files tell you – TheGeneral Apr 04 '18 at 11:36
  • 2
    Possible duplicate of [Xamarin app runs on emulator but crashes on real device](https://stackoverflow.com/questions/49645888/xamarin-app-runs-on-emulator-but-crashes-on-real-device) – Frauke Apr 04 '18 at 11:38
  • Asking the same question again just because you didn't get any answers the first time is frowned upon here. https://stackoverflow.com/questions/49645888/xamarin-app-runs-on-emulator-but-crashes-on-real-device#49645888 – Frauke Apr 04 '18 at 11:39
  • My issue was using a wrong static resource in one of my pages. – zmovahedi Jun 08 '21 at 05:44

6 Answers6

6

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.

chaosifier
  • 2,666
  • 25
  • 39
2

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

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
VenkyDhana
  • 905
  • 5
  • 16
  • I have found out that "Sdk and user assemblies" linking option just screws up the build. I ran into class "cannot be instantiated" and "not found" when using this option. Set it to "Sdk only" works fine. How funny it is when Xamarin gives you an option but it rarely works. Even that still happens in 2021. – Khoa Tran Sep 13 '21 at 06:30
1

Make sure that Shared Mono Runtime is not selected in the release config enter image description here

Mohamed Saleh
  • 2,881
  • 1
  • 23
  • 35
  • My issue was only with the iOS build in release mode on a physical device (not a simulator) and it turned out to be the linking settings on the project properties were different from debug to release mode. Same principle as above. – tkerwood Jun 24 '20 at 06:17
1

I switched off "optimize code" for "release" in project properties. Worked for me.

0

I had the same issue today. After making several trials on configurations and build settings, the only solution that worked for me was to update all Xamarin related packages via NuGet Package Manager. You can try this next time when you encounter this kind of a situation.

0

Actually, Clean the solution, uninstall the app and uninstall API working fine for me

Mohamad Mahmoud Darwish
  • 3,865
  • 9
  • 51
  • 76