Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Android app in Release mode gets stuck in splash screen

Open lukaszossowski opened this issue 1 year ago • 11 comments

Describe the bug Changing android app from Debug to Release mode and debugging it with VS causes it to get stuck in the splash screen.

To Reproduce Steps to reproduce the behavior:

  1. Create a Cross Platform Avalonia Application from official template.
  2. Set configuration to Release
  3. Deploy to phone.
  4. App does not go pas splash screen.

Expected behavior It should close splash screen and open main window.

Desktop (please complete the following information):

  • OS: Android

lukaszossowski avatar Sep 15 '22 21:09 lukaszossowski

Maybe something goes wrong on start up. Try to do some logging to find the root cause: https://docs.avaloniaui.net/docs/getting-started/logging-errors-and-warnings

timunie avatar Sep 16 '22 07:09 timunie

Maybe something goes wrong on start up. Try to do some logging to find the root cause: https://docs.avaloniaui.net/docs/getting-started/logging-errors-and-warnings

I am not sure how to do that in Android unfortunately, and where would the trace be.

However, after doing some dumb debugging by using Vibrations as "breakpoint" it seems that the OnResume() override in SplashActivity never gets called. I tried overriding OnStart() as wel, but it also never gets called. The I tried overdiding OnCreate:

 protected override void OnCreate(Bundle? savedInstanceState)
        {
            Vibration.Vibrate();
            base.OnCreate(savedInstanceState);
        }

But the vibration doesn't happen in Release configuration, though it does in Debug.

How should I proceed?

lukaszossowski avatar Sep 16 '22 08:09 lukaszossowski

@lukaszossowski please try to get logs with AndroidEnvironment.UnhandledExceptionRaiser event. You can save an exception to the log file (note, that it might be saved to the virtual/internal memory with android sandbox restrictions).

maxkatz6 avatar Oct 03 '22 19:10 maxkatz6

please try to get logs with AndroidEnvironment.UnhandledExceptionRaiser event. You can save an exception to the log file (note, that it might be saved to the virtual/internal memory with android sandbox restrictions).

Could you please explain how to do that or point me in the right direction? Unfortunately I have basically zero experience in this kind of stuff.

lukaszossowski avatar Oct 05 '22 21:10 lukaszossowski

  1. I use Serilog for logging: https://serilog.net . I think they have a logger for Android as well, check out their docs.
  2. See https://stackoverflow.com/questions/48499328/how-to-catch-all-exceptions-in-try-catch-block-in-xamarin-android for an example how to log an error in Xamarin. Avalonia should work similar.

timunie avatar Oct 06 '22 07:10 timunie

Is this and #9230 the same? I'm seeing this gray screen with the debug configuration. I can see the data binding for the MainViewModel being executed so it may have more to do with rendering. AndroidEnvironment.UnhandledExceptionRaiser is not raised and I'm not seeing anything suspicious with Information-level logs enabled. I can even see that a layout pass runs successfully. Any other ideas?

tristanlabelle avatar Oct 31 '22 21:10 tristanlabelle

I also has this problem. in debug mode, it's always good, but in release, it will get stuck. I also tried this project AvaloniaUI/Wordle-onia and do some changes (change to .net 6) and test, and it also stopped in splash screen.

CYLMos avatar Nov 02 '22 04:11 CYLMos

@CYLMos what exactly did you change and does it run without these changes?

Maybe we can figure out the root case together 😃

timunie avatar Nov 02 '22 05:11 timunie

@CYLMos what exactly did you change and does it run without these changes?

For me it turns out that Startup Tracing enabled was causing the issues. After disabling that the app works in release mode as well.

lukaszossowski avatar Nov 02 '22 07:11 lukaszossowski

@timunie

All of the TargetFramework are changed to net6. And in global.json, the value of version are changed to one of the net 6 version (Sorry I can't check now). I also modify MainActivity and SplashActivity because of 11.0 version of Avalonia.

MainActivity:

[Activity(Label = "Wordle.Android", Theme = "@style/MyTheme.NoActionBar", Icon = "@drawable/icon", LaunchMode = LaunchMode.SingleInstance, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
    public class MainActivity : AvaloniaMainActivity
    {
    }

SplashActivity

[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
    public class SplashActivity : AvaloniaSplashActivity<App>
    {
        protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
        {
            return base.CustomizeAppBuilder(builder);
        }

        protected override void OnResume()
        {
            base.OnResume();

            StartActivity(new Intent(Application.Context, typeof(MainActivity)));
        }
    }

CYLMos avatar Nov 02 '22 11:11 CYLMos

@lukaszossowski I tried to disable it, but I got the same issue.

CYLMos avatar Nov 02 '22 11:11 CYLMos