Skip to content

Uno 7: Crash on Android with Vulkan #23923

Closed

Description

@jonpryor

Current behavior 🐛

May be a heisenbug; recording here for posterity/investigation.

I am observing a crash from ANativeWindow_fromSurface() when running SamplesApp on an Android emulator.

Expected behavior 🎯

No crash.

How to reproduce it (as minimally and precisely as possible) 🔬

SamplesApp is in the unoplatform/uno repo. The commit I'm observing the crash on is on the feature/breakingchanges branch, which requires .NET 11 Preview 5. First, build SamplesApp.Skia.netcoremobile.csproj:

git clone https://github.com/unoplatform/uno.git
cd uno
# note: commit 0ebec is on the feature/breakingchanges branch
git checkout 0ebec1e321fc5ff5c21ed166130f69241ddcfbb8
export PATH=path/to/dotnet-sdk-11.0.100-preview.5.26302.115:$PATH
\cp build/ci/net11/_global.json global.json
dotnet publish src/SamplesApp/SamplesApp.Skia.netcoremobile/SamplesApp.Skia.netcoremobile.csproj -r android-arm64 -f net11.0-android -p:UnoTargetFrameworkOverride=net11.0-android

Next, launch an Android emulator. I use the emulator-uno script (expand the details block, below).

Note: I'm running this emulator on an arm64 macOS device, using the emulator Android SDK package, version 36.6.11, with an API-28 system image.

Once the emulator is running, capture adb logical output:

adb logcat > log.txt

Install and run the app:

adb install src/SamplesApp/SamplesApp.Skia.netcoremobile/bin/Release/net11.0-android/android-arm64/publish/uno.platform.samplesapp.skia-Signed.apk                                
adb shell am start uno.platform.samplesapp.skia/crc6448f3b0362cbf4bc9.MainActivity

The app launches, then crashes.

adb logcat contains:

ActivityManager: Displayed uno.platform.samplesapp.skia/crc6448f3b0362cbf4bc9.MainActivity: +1s380ms
samplesapp.ski: indirect_reference_table.cc:59] JNI ERROR (app bug): attempt to use stale Global 0x3916 (should be 0x391a)
samplesapp.ski: runtime.cc:558] Runtime aborting...
samplesapp.ski: runtime.cc:558] Dumping all threads without appropriate locks held: thread list lock
samplesapp.ski: runtime.cc:558] All threads:
samplesapp.ski: runtime.cc:558] DALVIK THREADS (20):
samplesapp.ski: runtime.cc:558] "Thread-8" prio=10 tid=19 Runnable
samplesapp.ski: runtime.cc:558]   | group="" sCount=0 dsCount=0 flags=0 obj=0x12d01368 self=0x6f186fa800
samplesapp.ski: runtime.cc:558]   | sysTid=7366 nice=-10 cgrp=default sched=0/0 handle=0x6f1993f4f0
samplesapp.ski: runtime.cc:558]   | state=R schedstat=( 3289249 4228251 22 ) utm=0 stm=0 core=2 HZ=100
samplesapp.ski: runtime.cc:558]   | stack=0x6f19844000-0x6f19846000 stackSize=1009KB
samplesapp.ski: runtime.cc:558]   | held mutexes= "abort lock" "mutator lock"(shared held)
samplesapp.ski: runtime.cc:558]   native: #00 pc 00000000003b49a0  /system/lib64/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, int, BacktraceMap*, char const*, art::ArtMethod*, void*, bool)+216)
samplesapp.ski: runtime.cc:558]   native: #01 pc 0000000000480e20  /system/lib64/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool, BacktraceMap*, bool) const+348)
samplesapp.ski: runtime.cc:558]   native: #02 pc 000000000049a598  /system/lib64/libart.so (art::DumpCheckpoint::Run(art::Thread*)+812)
samplesapp.ski: runtime.cc:558]   native: #03 pc 000000000049350c  /system/lib64/libart.so (art::ThreadList::RunCheckpoint(art::Closure*, art::Closure*)+464)
samplesapp.ski: runtime.cc:558]   native: #04 pc 00000000004927d4  /system/lib64/libart.so (art::ThreadList::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool)+504)
samplesapp.ski: runtime.cc:558]   native: #05 pc 00000000004564dc  /system/lib64/libart.so (art::Runtime::Abort(char const*)+380)
samplesapp.ski: runtime.cc:558]   native: #06 pc 0000000000008cb0  /system/lib64/libbase.so (android::base::LogMessage::~LogMessage()+724)
samplesapp.ski: runtime.cc:558]   native: #07 pc 00000000002356e0  /system/lib64/libart.so (art::IndirectReferenceTable::AbortIfNoCheckJNI(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)+236)
samplesapp.ski: runtime.cc:558]   native: #08 pc 00000000002e2790  /system/lib64/libart.so (art::IndirectReferenceTable::GetChecked(void*) const+436)
samplesapp.ski: runtime.cc:558]   native: #09 pc 00000000002ddabc  /system/lib64/libart.so (art::JavaVMExt::DecodeGlobal(void*)+24)
samplesapp.ski: runtime.cc:558]   native: #10 pc 0000000000486734  /system/lib64/libart.so (art::Thread::DecodeJObject(_jobject*) const+152)
samplesapp.ski: runtime.cc:558]   native: #11 pc 00000000003439c4  /system/lib64/libart.so (art::JNI::GetObjectField(_JNIEnv*, _jobject*, _jfieldID*)+596)
samplesapp.ski: runtime.cc:558]   native: #12 pc 00000000000ff6bc  /system/lib64/libandroid_runtime.so (android::android_view_Surface_getSurface(_JNIEnv*, _jobject*)+52)
samplesapp.ski: runtime.cc:558]   native: #13 pc 00000000000ff64c  /system/lib64/libandroid_runtime.so (android::android_view_Surface_getNativeWindow(_JNIEnv*, _jobject*)+36)
samplesapp.ski: runtime.cc:558]   native: #14 pc 0000000000012394  /system/lib64/libandroid.so (ANativeWindow_fromSurface+32)
samplesapp.ski: runtime.cc:558]   native: #15 pc 00000000064927d0  <anonymous:6fd9e70000> (???)
samplesapp.ski: runtime.cc:558]   (no managed stack frames)

Note frame 14: ANativeWindow_fromSurface() is

_nativeWindow = ANativeWindow_fromSurface(
JNIEnv.Handle,
surface.Handle);

emulator-uno
#!/bin/sh

DEFAULT_API_LEVEL=28
DEFAULT_EMU_GPU_MODE=swiftshader_indirect

for arg in "$@" ; do
  case "$arg" in
    --help)
      echo "Usage: [API_LEVEL=$DEFAULT_API_LEVEL] [EMU_GPU_MODE=$DEFAULT_EMU_GPU_MODE] $0"
      echo "Launches Android emulator for API-\$API_LEVEL using \`-gpu\` mode \$EMU_GPU_MODE".
      exit 0
  esac
done

set -ex

TMP="$HOME/Developer/tmp"
export ANDROID_HOME="$HOME/android-toolchain/sdk"
export ANDROID_PREFS_ROOT="${ANDROID_PREFS_ROOT:=$HOME}"
CMDLINE_TOOLS="$ANDROID_HOME/cmdline-tools/19.0/bin"

EMU_GPU_MODE="${EMU_GPU_MODE:-$DEFAULT_EMU_GPU_MODE}"

API_LEVEL=${API_LEVEL:-$DEFAULT_API_LEVEL} # Skia may crash with https://github.com/unoplatform/uno/pull/22571
# API_LEVEL=${API_LEVEL:-34}

arch=`arch`
name=`uname`

if [ "$name" = Darwin -a "$arch" = 'i386' ]; then
	AVD_ABI=x86_64
elif [ "$name" = Darwin -a "$arch" = "arm64" ]; then
	AVD_ABI=arm64-v8a
fi

if [ "${AVD_ABI:-}" = "" ]; then
	>&21 echo $0: could not determine emulator ABI.
	exit 1
fi

AVD_NAME="xamarin_android_emulator"
IMAGE_NAME="system-images;android-$API_LEVEL;google_apis_playstore;$AVD_ABI"
AVD_CONFIG_FILE="$HOME/.android/avd/$AVD_NAME.avd/config.ini"

AVDMANAGER="$CMDLINE_TOOLS/avdmanager"
SDKMANAGER="$CMDLINE_TOOLS/sdkmanager"

if "$AVDMANAGER" list avd | grep "Name: $AVD_NAME" >/dev/null 2>&1; then
  "$AVDMANAGER" delete avd -n "$AVD_NAME"
fi

"$SDKMANAGER" "$IMAGE_NAME"

echo "no" | "$AVDMANAGER" create avd \
  -n "$AVD_NAME" --abi "$AVD_ABI" \
  -k "$IMAGE_NAME" \
  --sdcard 128M

# As seen in `android-uitest-run.sh` in Uno.Gallery!
echo "hw.cpu.ncore=3" >> "$AVD_CONFIG_FILE"
echo "vm.heapSize=256M" >> "$AVD_CONFIG_FILE"

exec "$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME" \
  -skin 1280x800 -gpu "$EMU_GPU_MODE" -no-snapshot \
  -no-boot-anim -noaudio -prop ro.debuggable=1 \
  > "$TMP/loge.txt" 2>&1 

Workaround 🛠️

No response

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

No response

Uno.Sdk version (and other relevant versions) 📦

No response

IDE version 🧑‍💻

No response

Anything else we need to know? 💬

No response

Activity

  1. added theissue type on Jul 30, 2026
  2. added
    triage/untriaged
    on Jul 30, 2026
  3. jonpryor commented on Jul 30, 2026

    @jonpryor
    ContributorAuthor

    As with all great heisenbugs, logging to know the state of things may changes things enough that it no longer crashes, if it works at all. Consider:

    diff --git a/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs b/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs
    index 2a9d0f5246..8a873319e1 100644
    --- a/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs
    +++ b/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs
    @@ -168,9 +168,10 @@ internal sealed partial class UnoSKVulkanView : SurfaceView, ISurfaceHolderCallb
                    // We must keep this alive for the lifetime of the Vulkan context because
                    // the VkSurfaceKHR created from it internally references the ANativeWindow.
                    // Releasing it while Vulkan surfaces are active causes a destroyed-mutex crash.
    +               global::Android.Util.Log.Error("*jonp*", $"# jonp: InitializeVulkan: surface.Handle={Convert.ToString((long) surface.Handle, 2)}");
                    _nativeWindow = ANativeWindow_fromSurface(
                            JNIEnv.Handle,
                            surface.Handle);

    This message does not show for me at all. The app still crashes. If I add more logging or change the structure of the method, then I instead see the app launch, the screen "flash", and then the screen is blank/black. adb logcat contains:

    I DOTNET  :       Uno.UI.Runtime.Skia.Vulkan.VulkanException: vkCreateInstance returned VK_ERROR_INCOMPATIBLE_DRIVER
    I DOTNET  :          at Uno.UI.Runtime.Skia.Vulkan.Interop.VulkanInstance.Create(VkGetInstanceProcAddressDelegate getProcAddress, IReadOnlyList`1 requiredExtensions, Boolean enableDebug)
    I DOTNET  :          at Uno.UI.Runtime.Skia.Vulkan.VulkanContext.Initialize(IVulkanPlatformSurfaceFactory factory, IntPtr nativeWindowHandle, Int32 width, Int32 height)
    I DOTNET  :          at Uno.UI.Runtime.Skia.Android.UnoSKVulkanView.InitializeVulkan(ISurfaceHolder holder)
    I DOTNET  :          at Uno.UI.Runtime.Skia.Android.UnoSKVulkanView.RenderLoop(Object state)
    

    But focusing on the crash side of things, I can force the crash by replacing surface.Handle with IntPtr.Zero:

    diff --git a/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs b/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs
    index 2a9d0f5246..3b76192e2a 100644
    --- a/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs
    +++ b/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs
    @@ -170,7 +170,7 @@ internal sealed partial class UnoSKVulkanView : SurfaceView, ISurfaceHolderCallb
     		// Releasing it while Vulkan surfaces are active causes a destroyed-mutex crash.
     		_nativeWindow = ANativeWindow_fromSurface(
     			JNIEnv.Handle,
    -			surface.Handle);
    +			IntPtr.Zero);
     
     		if (_nativeWindow == IntPtr.Zero)
     			throw new InvalidOperationException("Failed to get ANativeWindow from Surface");

    The crash is otherwise "the same" as originally observed, with ANativeWindow.fromSurface() in the native call stack.

    This allows us to create a working hypothesis. Consider UnoSKVulkanView.InitializeVulkan():

    private void InitializeVulkan(ISurfaceHolder holder)
    {
    var surface = holder.Surface;
    if (surface == null || !surface.IsValid)
    throw new InvalidOperationException("Android Surface is not valid");
    // Get the ANativeWindow pointer from the Surface.
    // We must keep this alive for the lifetime of the Vulkan context because
    // the VkSurfaceKHR created from it internally references the ANativeWindow.
    // Releasing it while Vulkan surfaces are active causes a destroyed-mutex crash.
    _nativeWindow = ANativeWindow_fromSurface(
    JNIEnv.Handle,
    surface.Handle);
    if (_nativeWindow == IntPtr.Zero)
    throw new InvalidOperationException("Failed to get ANativeWindow from Surface");
    var rect = holder.SurfaceFrame;
    var factory = new AndroidVulkanSurfaceFactory();
    _vulkanContext.Initialize(factory, _nativeWindow, rect!.Width(), rect.Height());
    var (deviceName, driverVersion) = _vulkanContext.GetDeviceInfo();
    if (this.Log().IsEnabled(LogLevel.Information))
    {
    this.Log().Info($"Vulkan rendering initialized: {deviceName}, {driverVersion}");
    }
    }

    The hypothesis as follows:

    1. var surface = holder.Surface (line 163) causes a SurfaceInvoker instance to be created.

    2. surface.Handle (line 173) is the last use of surface, and "IL-wise in C#" what we'll have is:

      IntPtr __env = JNIEnv.Handle;
      IntPtr __h = surface.Handle;
      _nativeWindow = ANativeWindow_fromSurface(__env, __h);
    3. As line 173 is the last use of surface, nothing prevents the GC from collecting the surface instance between the surface.Handle invocation and the ANativeWindow_fromSurface() invocation. Meaning __h could be invalid.

    A way to confirm this would be (lots of) luck and the enabling of GREF logging:

    adb shell setprop debug.mono.log gref

    (Lots of luck would be necessary because the GREF logging may itself change program behavior enough that we don't see the crash anymore.)

    However, enabling GREF logging fails differently:

    I samplesapp.ski: Rejecting re-init on previously-failed class java.lang.Class<androidx.window.layout.adapter.sidecar.DistinctElementSidecarCallback>: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/window/sidecar/SidecarInterface$SidecarCallback;
    I samplesapp.ski:   at androidx.window.layout.adapter.sidecar.ExtensionInterfaceCompat androidx.window.layout.adapter.sidecar.SidecarWindowBackend$Companion.initAndVerifyExtension(android.content.Context) (SidecarWindowBackend.kt:209)
    I samplesapp.ski:   at androidx.window.layout.adapter.sidecar.SidecarWindowBackend androidx.window.layout.adapter.sidecar.SidecarWindowBackend$Companion.getInstance(android.content.Context) (SidecarWindowBackend.kt:193)
    I samplesapp.ski:   at androidx.window.layout.WindowInfoTracker androidx.window.layout.WindowInfoTracker$Companion.getOrCreate(android.content.Context) (WindowInfoTracker.kt:178)
    I samplesapp.ski:   at void crc6448f3b0362cbf4bc9.MainActivity.n_onCreate(android.os.Bundle) (MainActivity.java:-2)
    I samplesapp.ski:   at void crc6448f3b0362cbf4bc9.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:37)
    I samplesapp.ski:   at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7136)
    I samplesapp.ski:   at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7127)
    I samplesapp.ski:   at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1271)
    I samplesapp.ski:   at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2893)
    I samplesapp.ski:   at android.app.Activity android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.app.servertransaction.PendingTransactionActions, android.content.Intent) (ActivityThread.java:3048)
    I samplesapp.ski:   at void android.app.servertransaction.LaunchActivityItem.execute(android.app.ClientTransactionHandler, android.os.IBinder, android.app.servertransaction.PendingTransactionActions) (LaunchActivityItem.java:78)
    I samplesapp.ski:   at void android.app.servertransaction.TransactionExecutor.executeCallbacks(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:108)
    I samplesapp.ski:   at void android.app.servertransaction.TransactionExecutor.execute(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:68)
    I samplesapp.ski:   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1808)
    I samplesapp.ski:   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
    I samplesapp.ski:   at void android.os.Looper.loop() (Looper.java:193)
    I samplesapp.ski:   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6669)
    I samplesapp.ski:   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
    I samplesapp.ski:   at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:493)
    I samplesapp.ski:   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:858)
    I samplesapp.ski: Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.window.sidecar.SidecarInterface$SidecarCallback" on path: DexPathList[[zip file "/data/app/uno.platform.samplesapp.skia-gN811XNAjuIqiUO8SV-mNA==/base.apk"],nativeLibraryDirectories=[/data/app/uno.platform.samplesapp.skia-gN811XNAjuIqiUO8SV-mNA==/lib/arm64, /data/app/uno.platform.samplesapp.skia-gN811XNAjuIqiUO8SV-mNA==/base.apk!/lib/arm64-v8a, /system/lib64]]
    …
    I MonoDroid: UNHANDLED EXCEPTION:
    I MonoDroid: Java.Lang.LinkageError: Exception of type 'Java.Lang.LinkageError' was thrown.
    I MonoDroid:  ---> Java.Lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'
    I MonoDroid: 
    I MonoDroid:   --- End of managed Java.Lang.IllegalStateException stack trace ---
    I MonoDroid: java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'
    I MonoDroid:     at kotlinx.coroutines.internal.MainDispatchersKt.throwMissingMainDispatcherException(MainDispatchers.kt:77)
    I MonoDroid:     at kotlinx.coroutines.internal.MainDispatchersKt.createMissingDispatcher(MainDispatchers.kt:74)
    I MonoDroid:     at kotlinx.coroutines.internal.MainDispatchersKt.createMissingDispatcher$default(MainDispatchers.kt:68)
    I MonoDroid:     at kotlinx.coroutines.internal.MainDispatcherLoader.loadMainDispatcher(MainDispatchers.kt:35)
    I MonoDroid:     at kotlinx.coroutines.internal.MainDispatcherLoader.<clinit>(MainDispatchers.kt:18)
    I MonoDroid:     at kotlinx.coroutines.Dispatchers.getMain(Dispatchers.kt:19)
    I MonoDroid:     at androidx.window.layout.WindowInfoTrackerImpl.windowLayoutInfo(WindowInfoTrackerImpl.kt:64)
    I MonoDroid:     at androidx.window.java.layout.WindowInfoTrackerCallbackAdapter.addWindowLayoutInfoListener(WindowInfoTrackerCallbackAdapter.kt:55)
    I MonoDroid:     at crc64d0916be76e7aa092.ApplicationActivity.n_onStart(Native Method)
    I MonoDroid:     at crc64d0916be76e7aa092.ApplicationActivity.onStart(ApplicationActivity.java:84)
    I MonoDroid:     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
    I MonoDroid:     at android.app.Activity.performStart(Activity.java:7157)
    I MonoDroid:     at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2937)
    I MonoDroid:     at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
    I MonoDroid:     at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
    I MonoDroid:     at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
    I MonoDroid:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
    I MonoDroid:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
    I MonoDroid:     at android.os.Handler.dispatchMessage(Handler.java:106)
    I MonoDroid:     at android.os.Looper.loop(Looper.java:193)
    I MonoDroid:     at android.app.ActivityThread.main(ActivityThread.java:6669)
    I MonoDroid:     at java.lang.reflect.Method.invoke(Native Method)
    I MonoDroid:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    I MonoDroid:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
    I MonoDroid: 
    I MonoDroid:    --- End of inner exception stack trace ---
    I MonoDroid:    at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference, JniObjectReference, JniMethodInfo , JniArgumentValue*)
    I MonoDroid:    at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod(String, IJavaPeerable, JniArgumentValue* )
    I MonoDroid:    at AndroidX.Window.Java.Layout.WindowInfoTrackerCallbackAdapter.AddWindowLayoutInfoListener(Activity, IExecutor, IConsumer)
    I MonoDroid:    at Uno.UI.Foldable.FoldableApplicationViewSpanningRects.OnStartEvent(Object sender, EventArgs args)
    I MonoDroid:    at Uno.UI.BaseActivity.OnStart()
    I MonoDroid:    at Microsoft.UI.Xaml.ApplicationActivity.OnStart()
    I MonoDroid:    at Android.App.Activity.n_OnStart(IntPtr jnienv, IntPtr native__this)
    I MonoDroid:   --- End of managed Java.Lang.LinkageError stack trace ---
    I MonoDroid: java.lang.ExceptionInInitializerError
    I MonoDroid:     at kotlinx.coroutines.Dispatchers.getMain(Dispatchers.kt:19)
    I MonoDroid:     at androidx.window.layout.WindowInfoTrackerImpl.windowLayoutInfo(WindowInfoTrackerImpl.kt:64)
    I MonoDroid:     at androidx.window.java.layout.WindowInfoTrackerCallbackAdapter.addWindowLayoutInfoListener(WindowInfoTrackerCallbackAdapter.kt:55)
    I MonoDroid:     at crc64d0916be76e7aa092.ApplicationActivity.n_onStart(Native Method)
    I MonoDroid:     at crc64d0916be76e7aa092.ApplicationActivity.onStart(ApplicationActivity.java:84)
    I MonoDroid:     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
    I MonoDroid:     at android.app.Activity.performStart(Activity.java:7157)
    I MonoDroid:     at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2937)
    I MonoDroid:     at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
    I MonoDroid:     at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
    I MonoDroid:     at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
    I MonoDroid:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
    I MonoDroid:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
    I MonoDroid:     at android.os.Handler.dispatchMessage(Handler.java:106)
    I MonoDroid:     at android.os.Looper.loop(Looper.java:193)
    I MonoDroid:     at android.app.ActivityThread.main(ActivityThread.java:6669)
    I MonoDroid:     at java.lang.reflect.Method.invoke(Native Method)
    I MonoDroid:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    I MonoDroid:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
    I MonoDroid: Caused by: java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'
    I MonoDroid:     at kotlinx.coroutines.internal.MainDispatchersKt.throwMissingMainDispatcherException(MainDispatchers.kt:77)
    I MonoDroid:     at kotlinx.coroutines.internal.MainDispatchersKt.createMissingDispatcher(MainDispatchers.kt:74)
    I MonoDroid:     at kotlinx.coroutines.internal.MainDispatchersKt.createMissingDispatcher$default(MainDispatchers.kt:68)
    I MonoDroid:     at kotlinx.coroutines.internal.MainDispatcherLoader.loadMainDispatcher(MainDispatchers.kt:35)
    I MonoDroid:     at kotlinx.coroutines.internal.MainDispatcherLoader.<clinit>(MainDispatchers.kt:18)
    I MonoDroid:     ... 19 more
    

    Worse, trying to clear the debug.mono.log system property doesn't fix things. A reboot of the emulator is required. (?!)

    Additionally, this weird behavior isn't easily reproducible: adb shell setprop debug.mono.log gref in the new emulator doesn't trigger the same crashes. I guess the emulator was FUBAR.

  4. jonpryor commented on Jul 30, 2026

    @jonpryor
    ContributorAuthor

    Returning to the above hypothesis, if the problem is in fact that the GC is collecting the surface instance between accessing the surface.Handle property and invoking ANativeWindow_fromSurface(), then the fix is to tell the GC not to do that:

    diff --git a/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs b/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs
    index 2a9d0f5246..1232c8d191 100644
    --- a/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs
    +++ b/src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs
    @@ -171,6 +171,7 @@ internal sealed partial class UnoSKVulkanView : SurfaceView, ISurfaceHolderCallb
     		_nativeWindow = ANativeWindow_fromSurface(
     			JNIEnv.Handle,
     			surface.Handle);
    +		GC.KeepAlive(surface);
     
     		if (_nativeWindow == IntPtr.Zero)
     			throw new InvalidOperationException("Failed to get ANativeWindow from Surface");

    With this change applied, I no longer see the crash. (I instead see a blank screen, with adb logcat mentioning VK_ERROR_INCOMPATIBLE_DRIVER.)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage/untriaged

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions