Avalonia
Avalonia copied to clipboard
Android app in Release mode gets stuck in splash screen
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:
- Create a Cross Platform Avalonia Application from official template.
- Set configuration to Release
- Deploy to phone.
- 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
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
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 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).
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.
- I use Serilog for logging: https://serilog.net . I think they have a logger for Android as well, check out their docs.
- 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.
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?
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 what exactly did you change and does it run without these changes?
Maybe we can figure out the root case together 😃
@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.
@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)));
}
}
@lukaszossowski I tried to disable it, but I got the same issue.