android: AOT application doesn't launch on x86_64 emulator
Steps to Reproduce
- Create a sample Xamarin.Android application
- For Release configuration Enable AOT, LLVM Optimizing compiler and check only armeabi-v7a and x86_64 architecture
- Create Release .apk
- Drag and drop on a x86_64 emulator
- Launch the application and see it doesn’t launch
Version Information
Visual Studio Enterprise 2017 for Mac
Version 7.5.2 (build 40)
Installation UUID: 1ede8c5d-9d75-419f-82a5-a4e553d2c07f
Runtime:
Mono 5.10.1.57 (2017-12/ea8a24b1bbf) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)
Package version: 510010057
NuGet
Version: 4.3.1.4445
.NET Core
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.0.5
2.0.0
1.1.2
1.0.5
SDK: /usr/local/share/dotnet/sdk/2.1.4/Sdks
SDK Versions:
2.1.4
2.0.0
1.0.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/msbuild/15.0/bin/Sdks
Xamarin.Profiler
Version: 1.6.2
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
Xamarin.Android
Version: 8.3.3.2 (Visual Studio Enterprise)
Android SDK: /Users/cosminstirbu/Documents/sdk
Supported Android versions:
5.1 (API level 22)
6.0 (API level 23)
7.0 (API level 24)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 27.0.1
SDK Build Tools Version: 27.0.3
Java SDK: /usr
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Apple Developer Tools
Xcode 9.4 (14160)
Build 9F1027a
Xamarin.Mac
Version: 4.4.1.193 (Visual Studio Enterprise)
Xamarin.iOS
Version: 11.12.0.4 (Visual Studio Enterprise)
Hash: 64fece5f
Branch: d15-7
Build date: 2018-05-29 20:00:44-0400
Xamarin Inspector
Version: 1.4.0
Hash: b3f92f9
Branch: master
Build date: Fri, 19 Jan 2018 22:00:34 GMT
Client compatibility: 1
Build Information
Release ID: 705020040
Git revision: cfe2fc0566bc4db990242959de40505a13f58352
Build date: 2018-05-30 11:24:18-04
Xamarin addins: 3ac7413ef51a88e06367313c27aec8f7292752a6
Build lane: monodevelop-lion-d15-7
Operating System
Mac OS X 10.13.5
Darwin 17.6.0 Darwin Kernel Version 17.6.0
Tue May 8 15:22:16 PDT 2018
root:xnu-4570.61.1~1/RELEASE_X86_64 x86_64
Enabled user installed addins
AddinMaker 1.4.2
FileNesting 0.1.1
Macaque Tips 0.1.2
StyleCop Support 1.1.0.0
xUnit.NET 2 testing framework support 0.7.5
Straight8's SpecFlow Integration 1.11.2.0
NDK Version 17.0.4754217
Log File
06-18 16:32:26.742 1699-1723/system_process I/ActivityManager: Start proc 8249:com.myapp/u0a86 for activity com.myapp/md56ddbe9b70b1931e00ea94b862e0da07e.SplashActivity
06-18 16:32:26.838 8249-8249/? W/monodroid: Trying to load sgen from: /data/app/com.bca.buyerapp.uat-1/lib/x86_64/libmonosgen-2.0.so
06-18 16:32:26.884 8249-8249/? W/monodroid-gc: GREF GC Threshold: 46080
06-18 16:32:26.885 8249-8249/? W/monodroid: Calling into managed runtime init
06-18 16:32:26.935 8249-8249/? E/mono: Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Java.Interop.JniRuntime' threw an exception. ---> System.ArgumentException: Type provided must be an Enum.
Parameter name: enumType
at System.RuntimeType.GetEnumUnderlyingType () <0x7c1f99569e30 + 0x00049> in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at System.Enum.GetUnderlyingType (System.Type enumType) <0x7c1f9954cb80 + 0x0000e> in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at System.Collections.Generic.EqualityComparer`1[T].CreateComparer () [0x000e1] in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at System.Collections.Generic.EqualityComparer`1[T].get_Default () [0x0000b] in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue]..ctor (System.Int32 concurrencyLevel, System.Int32 capacity, System.Boolean growLockArray, System.Collections.Generic.IEqualityComparer`1[T] comparer) [0x00072] in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue]..ctor () [0x00006] in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at Java.Interop.JniRuntime..cctor () <0x7c1f994540b0 + 0x0001c> in <aa533aa4af8445f3b8f28f77ce0333e9>:0
--- End of inner exception stack trace ---
at Android.Runtime.AndroidRuntime..ctor (System.IntPtr jnienv, System.IntPtr vm, System.Boolean allocNewObjectSupported, System.IntPtr classLoader, System.IntPtr classLoader_loadClass) <0x7c1f989158e0 + 0x00054> in <2b050e7f433043c2acff8fe2c18b5767>:0
at Android.Runtime.JNIEnv.Initialize (Android.Runtime.JnienvInitializeArgs* args) <0x7c1f989222c0 + 0x003fc> in <2b050e7f433043c2acff8fe2c18b5767>:0
06-18 16:32:26.935 8249-8249/? E/mono-rt: [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Java.Interop.JniRuntime' threw an exception. ---> System.ArgumentException: Type provided must be an Enum.
Parameter name: enumType
at System.RuntimeType.GetEnumUnderlyingType () <0x7c1f99569e30 + 0x00049> in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at System.Enum.GetUnderlyingType (System.Type enumType) <0x7c1f9954cb80 + 0x0000e> in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at System.Collections.Generic.EqualityComparer`1[T].CreateComparer () [0x000e1] in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at System.Collections.Generic.EqualityComparer`1[T].get_Default () [0x0000b] in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue]..ctor (System.Int32 concurrencyLevel, System.Int32 capacity, System.Boolean growLockArray, System.Collections.Generic.IEqualityComparer`1[T] comparer) [0x00072] in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue]..ctor () [0x00006] in <31333f1e9cc74ec2914f4912ea8af6e7>:0
at Java.Interop.JniRuntime..cctor () <0x7c1f994540b0 + 0x0001c> in <aa533aa4af8445f3b8f28f77ce0333e9>:0
--- End of inner exception stack trace ---
at Android.Runtime.AndroidRuntime..ctor (System.IntPtr jnienv, System.IntPtr vm, System.Boolean allocNewObjectSupported, System.IntPtr classLoader, System.IntPtr classLoader_loadClass) <0x7c1f989158e0 + 0x00054> in <2b050e7f433043c2acff8fe2c18b5767>:0
at Android.Runtime.JNIEnv.Initialize (Android.Runtime.JnienvInitializeArgs* args) <0x7c1f989222c0 + 0x003fc> in <2b050e7f433043c2acff8fe2c18b5767>:0
06-18 16:32:26.986 1402-1402/? I/Zygote: Process 8249 exited cleanly (1)
06-18 16:32:26.989 1699-1798/system_process I/ActivityManager: Process com.myapp (pid 8249) has died
06-18 16:32:26.989 1699-1798/system_process D/ActivityManager: cleanUpApplicationRecord -- 8249
06-18 16:32:26.996 8266-8266/? W/art: Unexpected CPU variant for X86 using defaults: x86_64
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 8
- Comments: 19 (4 by maintainers)
Commits related to this issue
- Fix Android LLVM Bug Causing Crash on x86_64 https://github.com/xamarin/xamarin-android/issues/1842 — committed to TheCodeTraveler/GitTrends by TheCodeTraveler 5 years ago
I can verify this behavior on VS Windows 15.7.4, just using a
File | New Project.If I follow the stacktrace, starting in
JniRuntime:https://github.com/xamarin/java.interop/blob/3acf556b0e39b9863953e6f18277a5e6f36a6aa1/src/Java.Interop/Java.Interop/JniRuntime.cs#L92
Then to
ConcurrentDictionary:https://github.com/mono/mono/blob/43b0fa6261b6a264a846da9a9358be9050d510b2/mcs/class/referencesource/mscorlib/system/collections/Concurrent/ConcurrentDictionary.cs#L178
Then to
EqualityComparer:https://github.com/mono/mono/blob/43b0fa6261b6a264a846da9a9358be9050d510b2/mcs/class/referencesource/mscorlib/system/collections/generic/equalitycomparer.cs#L88
I believe this is an issue w/ Mono + AOT + LLVM, but it only breaks when you enable LLVM.
What happens in my app is a white screen and an infinite loop, prints this forever:
It’s likely crashing the activity on start, and repeats by restarting the activity.
This is a total showstopper as it’s quite common to run release builds in the emulator, and it’s also common to make the emulator run x86_64. When a Xamarin.Forms app is started you just get a random error.
This is an absolutely horrible user experience, and it’s been known for two years.
I urge you guys to either fix the issue or prevent creating x86_64 emulators. Of course it’d be best to just fix the issue as it would then also work on real hardware. Please put some urgency into these issues that waste an immense amount of time @jonathanpeppers.
Thank you again.
I was experiencing a very similar problem in issue #4291. It’s a bit frustrating to see that even though this has been known for over 2 years, there seems to be no efforts to fix it. In my case, there is no equality comparer needed in order for the issue to occur. Turning off LLVM and increasing the app size by over 25% for the majority of my users is not viable workaround for me. I (and many of my app users) would highly appreciate if this could get fixed!
Lost some time again because I forgot about this issue and created an x86_64 emulator. Waited for all the builds, ran into this issue and started investigating. Probably for the tenth time.
There’s so many issues in so many parts of the Microsoft technology stack that I’m starting to forget about all the issues and limitations, and now am starting to re-investigate things I have already acknowledged and found a workaround for.
@jonathanpeppers Could this bug please be fixed, or if you guys will never fix it could you please add something in the tooling that prevents from using combinations that just won’t work? It’s incredibly time consuming to just get a random runtime error and try to figure out what is broken.
Like don’t even allow to pick X86_64 abi in Visual Studio as it just won’t work.
Thank you.
I’ve been able to reproduce @jonathanpeppers 's issue - it seems to be happening when initializing an equality comparer for a custom value type. Here is the repository with the sample app which crashes only with AOT + LLVM and x86_64: https://github.com/akravch/mono_aot_llvm
https://github.com/akravch/mono_aot_llvm/blob/master/MonoAotLlvm/MainActivity.cs#L20
Any updates?
I confirm that the problem is still occuring on the latest stable version with the same kind of logs.