My Xamarin.Android app sometimes crashes on launch

2019-07-19 05:43发布

问题:

Recently, my Xamarin.Android app has started to crash on launch, caused by:

Java.Lang.ClassNotFoundException: mono.android.app.Application

This exception is being thrown more often than not. Usually, a rebuild fixes the issue for a build or two. I tried to combat the issue by making my own application class:

[Application(AllowBackup = true, Debuggable = true, Label = "My Application",
 Theme = "@style/AppBaseTheme", Icon = "@drawable/icon", Logo = "@drawable/icon")]
[MetaData("com.google.android.gms.version", Value = "@integer/google_play_services_version"),
 MetaData("com.google.android.geo.API_KEY", Value = "[redacted]")]
public class MyApplication: Application {
    public MyApplication(IntPtr handle, JniHandleOwnership ownership) : base(handle, ownership) {
    }

    public override void OnCreate() {
        base.OnCreate();
    }
}

Unfortunately, the same exception occurs (except that it's upset about not finding my class, instead of Mono's). Various Google searches, Xamarin Forums threads, and StackOverflow questions haven't helped a whole lot (in fact, the ideas to rebuild and make a custom application class came from that). This issue is really annoying and it is making it hard for me to debug my app. Am I doing something wrong? How can I fix this?

回答1:

I did some messing around and I turned off the shared Mono runtime in my project's settings, and that seems to have solved the problem (for now at least). I'll update the question if it stops working again.