Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on "Small Desktop" Android device when resizing window #16468

Closed
michael-taylor opened this issue Jul 25, 2024 · 2 comments
Closed

Crash on "Small Desktop" Android device when resizing window #16468

michael-taylor opened this issue Jul 25, 2024 · 2 comments

Comments

@michael-taylor
Copy link

Describe the bug

When running the Avalonia app (it can be the stock Avalonia template app) on a "Small Desktop" Android device, it crashes when clicking on the window resize/restore button (which isn't visible). This same crash also happens on my own app and was caught by Google Store's automated quality check.

Here are the exception details

Message
Unable to activate instance of type Avalonia.Android.Platform.SkiaPlatform.TopLevelImpl+ViewImpl from native handle 0x7fff7dace158 (key_handle 0x3812fd6).

Exception

System.NotSupportedException: Unable to activate instance of type Avalonia.Android.Platform.SkiaPlatform.TopLevelImpl+ViewImpl from native handle 0x7fff7dace158 (key_handle 0x3812fd6).
 ---> System.MissingMethodException: No constructor found for Avalonia.Android.Platform.SkiaPlatform.TopLevelImpl+ViewImpl::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
 ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.

  --- End of managed Java.Lang.Error stack trace ---
java.lang.Error: Java callstack:
	at crc64bd239b21961e24ab.TopLevelImpl_ViewImpl.n_surfaceDestroyed(Native Method)
	at crc64bd239b21961e24ab.TopLevelImpl_ViewImpl.surfaceDestroyed(TopLevelImpl_ViewImpl.java:130)
	at android.view.SurfaceView.notifySurfaceDestroyed(SurfaceView.java:1800)
	at android.view.SurfaceView.updateSurface(SurfaceView.java:993)
	at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:308)
	at android.view.View.dispatchDetachedFromWindow(View.java:21336)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5573)
	at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5544)
	at android.view.ViewGroup.removeView(ViewGroup.java:5475)
	at com.android.internal.widget.DecorCaptionView.removeContentView(DecorCaptionView.java:383)
	at com.android.internal.policy.DecorView.clearContentView(DecorView.java:2383)
	at com.android.internal.policy.PhoneWindow.clearContentView(PhoneWindow.java:530)
	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5459)
	at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5743)
	at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5658)
	at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:71)
	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7872)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

  --- End of managed Java.Lang.Error stack trace ---
java.lang.Error: Java callstack:
	at crc64bd239b21961e24ab.TopLevelImpl_ViewImpl.n_surfaceDestroyed(Native Method)
	at crc64bd239b21961e24ab.TopLevelImpl_ViewImpl.surfaceDestroyed(TopLevelImpl_ViewImpl.java:130)
	at android.view.SurfaceView.notifySurfaceDestroyed(SurfaceView.java:1800)
	at android.view.SurfaceView.updateSurface(SurfaceView.java:993)
	at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:308)
	at android.view.View.dispatchDetachedFromWindow(View.java:21336)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5573)
	at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5544)
	at android.view.ViewGroup.removeView(ViewGroup.java:5475)
	at com.android.internal.widget.DecorCaptionView.removeContentView(DecorCaptionView.java:383)
	at com.android.internal.policy.DecorView.clearContentView(DecorView.java:2383)
	at com.android.internal.policy.PhoneWindow.clearContentView(PhoneWindow.java:530)
	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5459)
	at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5743)
	at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5658)
	at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:71)
	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7872)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

   --- End of inner exception stack trace ---
   at Java.Interop.TypeManager.CreateProxy(Type type, IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 349
   at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 311
   --- End of inner exception stack trace ---
   at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 318
   at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 303
   at Java.Lang.Object._GetObject[ISurfaceHolderCallback](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 289
   at Java.Lang.Object.GetObject[ISurfaceHolderCallback](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 281
   at Java.Lang.Object.GetObject[ISurfaceHolderCallback](IntPtr jnienv, IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 275
   at Android.Views.ISurfaceHolderCallbackInvoker.n_SurfaceDestroyed_Landroid_view_SurfaceHolder_(IntPtr jnienv, IntPtr native__this, IntPtr native_holder) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.ISurfaceHolder.cs:line 220
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 121

Inner Exception

System.MissingMethodException: No constructor found for Avalonia.Android.Platform.SkiaPlatform.TopLevelImpl+ViewImpl::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
 ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.

  --- End of managed Java.Lang.Error stack trace ---
java.lang.Error: Java callstack:
	at crc64bd239b21961e24ab.TopLevelImpl_ViewImpl.n_surfaceDestroyed(Native Method)
	at crc64bd239b21961e24ab.TopLevelImpl_ViewImpl.surfaceDestroyed(TopLevelImpl_ViewImpl.java:130)
	at android.view.SurfaceView.notifySurfaceDestroyed(SurfaceView.java:1800)
	at android.view.SurfaceView.updateSurface(SurfaceView.java:993)
	at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:308)
	at android.view.View.dispatchDetachedFromWindow(View.java:21336)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5573)
	at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5544)
	at android.view.ViewGroup.removeView(ViewGroup.java:5475)
	at com.android.internal.widget.DecorCaptionView.removeContentView(DecorCaptionView.java:383)
	at com.android.internal.policy.DecorView.clearContentView(DecorView.java:2383)
	at com.android.internal.policy.PhoneWindow.clearContentView(PhoneWindow.java:530)
	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5459)
	at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5743)
	at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5658)
	at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:71)
	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7872)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

  --- End of managed Java.Lang.Error stack trace ---
java.lang.Error: Java callstack:
	at crc64bd239b21961e24ab.TopLevelImpl_ViewImpl.n_surfaceDestroyed(Native Method)
	at crc64bd239b21961e24ab.TopLevelImpl_ViewImpl.surfaceDestroyed(TopLevelImpl_ViewImpl.java:130)
	at android.view.SurfaceView.notifySurfaceDestroyed(SurfaceView.java:1800)
	at android.view.SurfaceView.updateSurface(SurfaceView.java:993)
	at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:308)
	at android.view.View.dispatchDetachedFromWindow(View.java:21336)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3949)
	at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5573)
	at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5544)
	at android.view.ViewGroup.removeView(ViewGroup.java:5475)
	at com.android.internal.widget.DecorCaptionView.removeContentView(DecorCaptionView.java:383)
	at com.android.internal.policy.DecorView.clearContentView(DecorView.java:2383)
	at com.android.internal.policy.PhoneWindow.clearContentView(PhoneWindow.java:530)
	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5459)
	at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5743)
	at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5658)
	at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:71)
	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7872)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

   --- End of inner exception stack trace ---
   at Java.Interop.TypeManager.CreateProxy(Type type, IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 349
   at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 311

To Reproduce

  1. Create an Android emulator for "Small Desktop" 1366x768. I'm using Android 13.0
  2. Create a new Avalonia Cross Platform app
  3. Debug the app on the Android device
  4. Find where the resize/restore window decoration button would be (it's the second from the right). It won't be visible, but the mouse cursor will change
  5. Click that button and the app will crash
Screencast.from.2024-07-25.17-58-22.mp4

Expected behavior

The window should resize without crashing

Avalonia version

11.1

OS

Android

Additional context

No response

@workgroupengineering
Copy link
Contributor

This exception is trhowed when your Activity is not configured to handle the configuration change, in that case the android runtime recreates the activity. To avoid the issue it is sufficient to adjust ConfigurationChanges of the ActivityAttribute. In your case it should be similar to:

namespace ControlCatalog.Android
{
    [Activity(Label = "ControlCatalog.Android"
        , Theme = "@style/MyTheme.NoActionBar"
        , Icon = "@drawable/icon", MainLauncher = true
        , Exported = true
        , ConfigurationChanges = ConfigChanges.Orientation 
            | ConfigChanges.ScreenSize 
            | ConfigChanges.UiMode 
            | ConfigChanges.SmallestScreenSize 
            | ConfigChanges.ScreenLayout
            | ConfigChanges.Keyboard 
            | ConfigChanges.KeyboardHidden
            | ConfigChanges.Navigation
        )]
    // CategoryBrowsable and DataScheme are required for Protocol activation.
    // CategoryLeanbackLauncher is required for Android TV.
    [IntentFilter(new [] { ActionView }, Categories = new [] { CategoryDefault, CategoryBrowsable, CategoryLeanbackLauncher }, DataScheme = "avln" )]
    public class MainActivity : AvaloniaMainActivity<App>
    {
        protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
        {
            return base.CustomizeAppBuilder(builder)
                 .AfterSetup(_ =>
                 {
                     Pages.EmbedSample.Implementation = new EmbedSampleAndroid();
                 });
        }
    }
}

@michael-taylor
Copy link
Author

That fixed it! Thank you so much @workgroupengineering!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants