Приложение продолжает останавливаться (только на apk от Azure DevOps)? - PullRequest
1 голос
/ 27 июня 2019

Мы внедряем наше приложение для Android Xamarin с помощью Azure DevOps. Приложение собирается, разворачивается и работает с VS2019 без проблем. Мы также можем подписать наш apk с помощью опции подписи пакетов Android.

Сборка, подписание и размещение .apk из Azure DevOps работает нормально, но мы столкнулись с зависанием и сбоем (отдельно). Если мы исправим зависание, произойдет сбой.

Перед проверкой опции 'Zipalign' наше приложение будет зависать от SplashActivity. После проверки опции «Zipalign» наше приложение, похоже, переключается с SplashActivity на MainActivity, но затем вылетает и говорит «Приложение продолжает останавливаться». Что попробовать отсюда? Не знаю, как отладить проблему, так как это не происходит при развертывании отладки или выпуска из VS.

Edit1

Пытался реализовать обработку ошибок, чтобы перехватить ошибки, но, похоже, что они не попадают в цель.

protected override void OnCreate(Bundle bundle)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(bundle);

    AppDomain.CurrentDomain.UnhandledException 
        += CurrentDomainOnUnhandledException;
    System.Threading.Tasks.TaskScheduler.UnobservedTaskException 
        += TaskSchedulerOnUnobservedTaskException;
    Android.Runtime.AndroidEnvironment.UnhandledExceptionRaiser 
        += OnAndroidEnvironmentUnhandledExceptionRaiser;

    global::Xamarin.Forms.Forms.Init(this, bundle);
    DisplayCrashReport();

    LoadApplication(new App());
}

#region Error handling
public static void TaskSchedulerOnUnobservedTaskException(object sender,
    System.Threading.Tasks.UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs)
{
    var newExc = new Exception("TaskSchedulerOnUnobservedTaskException", unobservedTaskExceptionEventArgs.Exception);
    LogUnhandledException(newExc);
}

public static void CurrentDomainOnUnhandledException(object sender, 
    UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{
    var newExc = new Exception("CurrentDomainOnUnhandledException", unhandledExceptionEventArgs.ExceptionObject as Exception);
    LogUnhandledException(newExc);
}

private void OnAndroidEnvironmentUnhandledExceptionRaiser(object sender, 
    Android.Runtime.RaiseThrowableEventArgs unhandledExceptionEventArgs)
{
    var newExc = new Exception("OnAndroidEnvironmentUnhandledExceptionRaiser", unhandledExceptionEventArgs.Exception);
    LogUnhandledException(newExc);
}

internal static void LogUnhandledException(System.Exception exception)
{
    try
    {
        const string errorFileName = "Fatal.log";
        var libraryPath = System.Environment.GetFolderPath(
            System.Environment.SpecialFolder.Personal); // iOS: Environment.SpecialFolder.Resources
        var errorFilePath = System.IO.Path.Combine(libraryPath, errorFileName);
        var errorMessage = System.String.Format("Time: {0}\r\nError: Unhandled Exception\r\n{1}",
        System.DateTime.Now, exception.ToString());
        System.IO.File.WriteAllText(errorFilePath, errorMessage);

        // Log to Android Device Logging.
        Android.Util.Log.Error("Crash Report", errorMessage);
    }
    catch
    {
        // just suppress any error logging exceptions
    }
}

/// <summary>
// If there is an unhandled exception, the exception information is diplayed 
// on screen the next time the app is started
/// </summary>
[System.Diagnostics.Conditional("DEBUG")]
public void DisplayCrashReport()
{
    const string errorFilename = "Fatal.log";
    var libraryPath = System.Environment.GetFolderPath(
        System.Environment.SpecialFolder.Personal);
    var errorFilePath = System.IO.Path.Combine(libraryPath, errorFilename);

    if (!System.IO.File.Exists(errorFilePath))
    {
        return;
    }

    var errorText = System.IO.File.ReadAllText(errorFilePath);
    new Android.App.AlertDialog.Builder(this)
        .SetPositiveButton("Clear", (sender, args) =>
        {
            System.IO.File.Delete(errorFilePath);
        })
        .SetNegativeButton("Close", (sender, args) =>
        {
            // User pressed Close.
        })
        .SetMessage(errorText)
        .SetTitle("Crash Report! MainActivity")
        .Show();
}
#endregion
...