-
Notifications
You must be signed in to change notification settings - Fork 5
Properly supporting Android ARM devices
This article by Xamarin's Jonathan Pryor was originally posted to the mono-android mailing list. It is copied here for convenience.
The armeabi runtime is not thread safe. For the sanity of yourselves (as developers) and of your users, please, with utmost speed, update your .apk's to do one of the following:
- Only include the armeabi-v7a runtime, NOT the armeabi runtime.
- Manually update your .csproj file so that the element lists armeabi-v7a before armeabi:
https://bugzilla.xamarin.com/show_bug.cgi?id=7013#c15
http://docs.xamarin.com/android/advanced_topics/CPU_Architecture
Life...is complicated.
A long time ago, there was armeabi (ARMv5) and armeabi-v7a (ARMv7). Most devices are ARMv5, a few were ARMv7, and the only real difference between the two were hardware floating point support and SMP support.
At that time there were few SMP phones, so the lack of SMP support in ARMv5 libraries was...undesirable, but not terrible, given the rarity of SMP devices:
https://bugzilla.xamarin.com/show_bug.cgi?id=281
We fixed this so that the armeabi (ARMv5) runtime would function on ARMv7 SMP devices by using the sched_setaffinity() Linux call to tie the process to a single core, thus preventing "real" multithreading within the process. The fix was good enough for me to run a test app for several hours on my Xoom running Android 3.x (it would normally crash within a minute), so it appeared to be fixed and was first released in Mono for Android 4.0:
http://docs.xamarin.com/android/Releases/Mono_For_Android_4/Mono_For_Android_4.0.0#Bug_Fixes
Unfortunately, we're human, so we inadvertently removed that support in the 4.2.0 release; oops:
https://bugzilla.xamarin.com/show_bug.cgi?id=6654#c5
Then things get...rather more complicated. The sched_setaffinity()-based fix which worked in Android 3.x didn't work on Android 4.0:
https://bugzilla.xamarin.com/show_bug.cgi?id=7013
I'm still not sure why it doesn't work anymore, but without the sched_setaffinity() fix a proper fix is...rather more complicated, and hasn't been completed yet. Consequently, at this time (and for the foreseeable future) you CANNOT reliably use the armeabi runtime on SMP devices...which constitutes pretty much every "advanced" Android device on the market today, afaict. (Perhaps some of the free phones still have a single core... Some actual numbers would be interesting.)
So for the sanity of all involved, please include the armeabi-v7a runtime with your app.
Unfortunately, on Android 4.0-4.0.3, adding the armeabi-v7a runtime isn't enough. Due to an Android bug, in some circumstances Android will install armeabi native libraries even when armeabi-v7a native libraries are present in the .apk:
http://code.google.com/p/android/issues/detail?id=25321
This is...unfortunate, because a primary reason to want the armeabi-v7a runtime is so that things will function properly on those devices, and Android is not being helpful.
Fortunately, there's a workaround. Unfortunately, it'll only help for libmonodroid.so, not any other native libraries that are included with your app, and the workaround requires manually editing your .csproj:
https://bugzilla.xamarin.com/show_bug.cgi?id=7013#c15
A better implementation of the workaround will be in the forthcoming Mono for Android 4.2.8 release, which will add libraries to the .apk so that the armeabi-v7a version is added to the .apk before the armeabi version, thus appeasing Android 4.0-4.0.3.
- Jon