-
Notifications
You must be signed in to change notification settings - Fork 556
Description
Android framework version
net10.0-android (Preview)
Affected platform version
dotnet/android commit 0520997
Description
When constructing an object of a class implementing Java.Lang.Object on a thread other than the main thread, or possible a thread that does not have a looper registered(not possible to test since loopers are java objects and you can't create them on dotnet thread due to this issue), the app crashes with a Java.Lang.ClassNotFoundException
exception, showing a message similar to the following;
com.companyname.android_naot I Android Exception: Java.Lang.ClassNotFoundException: Didn't find class "crc64644ab4d403a62c42.TestRunnable" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64, /system/lib64, /system_ext/lib64]]
at Java.Interop.JniEnvironment.Types.TryFindClass(String classname, Boolean throwOnError) + 0x6d4
at Java.Interop.JniEnvironment.Types.FindClass(String classname) + 0x44
at Java.Interop.JniType..ctor(String classname) + 0x30
at Java.Interop.JniPeerMembers.JniInstanceMethods..ctor(Type declaringType) + 0x1a0
at Java.Interop.JniPeerMembers.JniInstanceMethods.GetConstructorsForType(Type declaringType) + 0xf8
at Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance(String constructorSignature, Type declaringType, JniArgumentValue* parameters) + 0xd4
at Java.Lang.Object..ctor() + 0xd8
at android_naot.TestRunnable..ctor(Action action) + 0x28
at android_naot.MainActivity.<OnCreate>b__0_1(Object _) + 0x110
This crash will occur on Timers and other dotnet api that uses threads.
Steps to Reproduce
- Clone and checkout
failing_repro
branch from https://github.com/emmauss/AndroidNativeAOTTest/tree/failing_repro - Build and run with
dotnet-local.cmd build -t:Run
, withdotnet-local.cmd
being the batch file for locally built dotnet runtime - When app runs, tap the "Hello" button. It fills up the visible space in the activity.
- App crashes.
Did you find any workaround?
Creating the object on the main thread and passing the reference to the thread you want bypasses the issue, as seen here https://github.com/emmauss/AndroidNativeAOTTest/blob/7de8ab27f77eb2f86670ca30c12620f4040b0c6e/MainActivity.cs#L12. The app runs a timer that output Button Clicked
in logcat using the main thread.