android: SIGSEGV crash when trying to Debug app with Xamarin.Android SDK 11.0.0.3

Steps to Reproduce

  1. Download repo project: App1.zip
  2. Try to deploy in DEBUG mode

Expected Behavior

No crash

Actual Behavior

Splash screen shows, then app crashes. Happened on two separate Windows machines, on both physical device and emulator.

Version Information

Microsoft Visual Studio Enterprise 2019
Version 16.7.0
VisualStudio.16.Release/16.7.0+30330.147
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Enterprise

Visual C++ 2019   00433-90050-27100-AA005
Microsoft Visual C++ 2019

ASP.NET and Web Tools 2019   16.7.532.28833
ASP.NET and Web Tools 2019

Azure App Service Tools v3.0.0   16.7.532.28833
Azure App Service Tools v3.0.0

C# Tools   3.7.0-6.20375.2+34202cc2f3e869fd70a26d8237f4552cf9e192cf
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   16.7.5 (112c7bc)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.7.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

Visual Basic Tools   3.7.0-6.20375.2+34202cc2f3e869fd70a26d8237f4552cf9e192cf
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.10.0.0 for F# 4.7   16.7.0-beta.20361.3+3ef6f0b514198c0bfa6c2c09fefe41a740b024d5
Microsoft Visual F# Tools 10.10.0.0 for F# 4.7

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.7.000.440 (d16-7@358f3c6)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.7.0.495 (remotes/origin/d16-7@79c0c522c)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.7.85 (1bcbbdf)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.0.0.3 (d16-7/aca845b)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: 83105ba
    Java.Interop: xamarin/java.interop/d16-7@1f3388a
    ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000
    SQLite: xamarin/sqlite/3.32.1@1a3276b
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-7@017078f


Xamarin.iOS and Xamarin.Mac SDK   13.20.2.2 (817b6f72a)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Log File

...
08-06 16:25:25.396 D/Mono    ( 7607): DllImport attempting to load: '__Internal'.
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/App1.dll08-06 16:25:25.397 D/Mono    ( 7607): DllImport error loading library '__Internal': 'Could not load library: Library '/system/lib/libmonodroid.so' not found.'.

08-06 16:25:25.397 W/Mono    ( 7607): DllImport unable to load library '__Internal'.
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Activity.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Annotation.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.AppCompat.AppCompatResources.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.AppCompat.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Arch.Core.Common.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Arch.Core.Runtime.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.CardView.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Collection.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.CoordinatorLayout.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Core.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.CursorAdapter.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.CustomView.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.DrawerLayout.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Fragment.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Interpolator.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Lifecycle.Common.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Lifecycle.LiveData.Core.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Lifecycle.Runtime.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Lifecycle.ViewModel.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Lifecycle.ViewModelSavedState.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Loader.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.MultiDex.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.RecyclerView.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.SavedState.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.Transition.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.VectorDrawable.Animated.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.VectorDrawable.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.VersionedParcelable.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.ViewPager.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.AndroidX.ViewPager2.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.Google.Android.Material.dll [External]
Loaded assembly: Mono.Android.dll [External]
Loaded assembly: Java.Interop.dll [External]
08-06 16:25:25.534 D/Mono    ( 7607): Requesting loading reference 4 (of 8) of Mono.Android.dll
08-06 16:25:25.535 D/Mono    ( 7607): Loading reference 4 of Mono.Android.dll asmctx DEFAULT, looking for System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
08-06 16:25:25.536 D/Mono    ( 7607): Image addref System[0xe6ea8b00] (asmctx DEFAULT) -> System.dll[0xc37ca500]: 2
08-06 16:25:25.537 D/Mono    ( 7607): Prepared to set up assembly 'System' (System.dll)
08-06 16:25:25.537 D/Mono    ( 7607): Assembly System[0xe6ea8b00] added to domain RootDomain, ref_count=1
08-06 16:25:25.540 D/Mono    ( 7607): Config attempting to parse: 'System.dll.config'.
08-06 16:25:25.540 D/Mono    ( 7607): Assembly Ref addref Mono.Android[0xe6ea88c0] -> System[0xe6ea8b00]: 2

=================================================================
	Native Crash Reporting
=================================================================
Got a SEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

No native Android stacktrace (see debuggerd output).

=================================================================
	Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0xf0953dfb):0xf0953deb  cc cc cc cc cc 8b 54 24 04 8b 44 24 08 0f b6 08  ......T$..D$....
0xf0953dfb  38 0a 0f 85 4d 14 00 00 83 f9 00 0f 84 4e 14 00  8...M........N..
0xf0953e0b  00 0f b6 48 01 38 4a 01 0f 85 37 14 00 00 83 f9  ...H.8J...7.....
0xf0953e1b  00 0f 84 38 14 00 00 0f b6 48 02 38 4a 02 0f 85  ...8.....H.8J...

=================================================================
	Managed Stacktrace:
=================================================================08-06 16:25:25.541 D/Mono    ( 7607): Requesting loading reference 0 (of 5) of System.dll


=================================================================08-06 16:25:25.541 D/Mono    ( 7607): Loading reference 0 of System.dll asmctx DEFAULT, looking for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e

08-06 16:25:25.542 F/libc    ( 7607): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6f63736d in tid 7607 (ompanyname.app1), pid 7607 (ompanyname.app1)

VS bug <span>#</span>1171752

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 45 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for reporting everybody! It appears to be a bug in Android 10 on both devices and emulators and at least Android 9 issue on devices. The issue is as follows:

  1. Since API 23 Android supports running applications without extracting shared libraries (the .so) files form the apk, the dlopen call is able to find them there and load
  2. Enabling the feature requires setting the android:extractNativeLibs="false" attribute to false on the <application> element in AndroidManifest.xml (this is done by default by the Android toolchain if the application targets API >= 23 and doesn’t set the flag explicitly)
  3. The attribute value is then reflected in the flags field of ApplicationInfo on the runtime
  4. On install time Android creates the architecture-specific directory but does NOT extract the .so files into it, if told so. Otherwise, it sets the flag and extracts the .so files to the lib directory.
  5. Xamarin.Android runtime checks the flag (trusting it) and, if it’s NOT set (which means the shared libraries are in the .apk), it sets up its internal search path for DSOs to point to the application APKs

What happens here, however, is that Android 10 (and 9, for devices - possibly other versions/combinations too) will correctly accept the false value of the attribute and it will NOT extract the .so files, but it WILL set the flag, thus misleading Xamarin.Android in step 5 to not set up the search path to point to the apk and thus, later on, fail to load the shared libraries, leading to the crash.

It follows that we can’t trust the flag and need another way to deal with the situation. I have the fix planned, working on implementing it ASAP. As a workaround, you can set android:extractNativeLibs=true and things should work fine.

I would appreciate if anyone affected by this took a moment, if possible, to test the fix using these installers (16.8 branch builds with the fix cherry-picked):

Thanks in advance!

It appears that the reason only 16.7 update saw this issue is the update of manifest-merger, which with that version started to set android:extractNativeLibs=false when minSdkVersion is 23 or higher. If your application AndroidX components, it enables use of the manifest merger feature. However, the real bug still remains in Android which sets the flag described previously when it should not be set.

Release status update

The corresponding version is also now available in Visual Studio 2019 for Mac version 8.7.3.

A new Release version of Xamarin.Android has now been published that includes the fix for this item.

Fix included in Xamarin.Android SDK version 11.0.2.0

Fix included on Windows in Visual Studio 2019 version 16.7.2. To get the new version that includes the fix, check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/.

Fix included on macOS in Visual Studio 2019 for Mac version 8.7.3. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

I can confirm the above (setting android:extractNativeLibs=true) works with Emulator. Havent tested on devices yet. Thank you @grendello for the workaround. Dont sweat you guys are working hard just like everyone else.

Thanks!

I would appreciate if anyone affected by this took a moment, if possible, to test the fix using these installers (16.8 branch builds with the fix cherry-picked):

Thanks in advance!

Confirmed on Windows. Previous crashing, now works well. Thank you so much.

I would appreciate if anyone affected by this took a moment, if possible, to test the fix using these installers (16.8 branch builds with the fix cherry-picked):

Thanks in advance!

Solved the problem on Windows.

I would appreciate if anyone affected by this took a moment, if possible, to test the fix using these installers (16.8 branch builds with the fix cherry-picked).

Tested on macOS using VS 8.7. I can confirm that it works where 11.0.0.3 did not work before.

Ok, the fix is rolled out to public with 16.7.2 update:

Top Issues Fixed from Developer Community in Visual Studio 2019 version 16.7.2 Visual Studio 2019 v16.7 Xamarin Android crash on start up in debug.

https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes#16.7.2

I would appreciate if anyone affected by this took a moment, if possible, to test the fix using these installers (16.8 branch builds with the fix cherry-picked):

Thanks in advance!

This fix works for me on Windows. Before I had to use the AndroidManifest.xml workaround mentioned above. Thanks for releasing that installer!

I would appreciate if anyone affected by this took a moment, if possible, to test the fix using these installers (16.8 branch builds with the fix cherry-picked):

Thanks in advance!

works for me too, VS for Mac, device running Android 10, was not working before

I would appreciate if anyone affected by this took a moment, if possible, to test the fix using these installers (16.8 branch builds with the fix cherry-picked):

Thanks in advance!

this solved for me on macOS. thanks

I can confirm the above (setting android:extractNativeLibs=true) works with Device (Pixel 4) and API 29. Thank you for all your support!

@MagicAndre1981 you can update to 16.7 and add the android:extractNativeLibs="true" attribute to work around the bug or wait till 16.8 (where the fix should be released). The attribute doesn’t have to always be present, it’s just a workaround for right now (or your choice as the app developer if you want to force Android to always extract your native libraries)

android:extractNativeLibs="true" works for me on a API level 27 device (compiling against 29), too. Thanks for that and the quick handling of it!

@grendello It’s all good. Just seemed odd that several of us all ran into after upgrading to 16.7, but worked fine on 16.6.x the day before. I guess a new test case for your tests. 😄

This appears to be a bug somewhere between the Android package manager (which installs the application) and the runtime/loader (which should set the flag as appropriate), possibly buggy data in the app database? Many Android components are now updatable via the Play Store, so the update with the bug could have found its way to Android 9 devices (the assumption supported by the fact that Android 9 emulators work fine - they don’t receive updates via the usual chanels)

Everyone experiencing this, do you happen to be using a device/emulator with Android 10 (API 29) by chance? If yes, could you please try with API 28 (or earlier), instead and see if you still experience the issue?

With API 29 - issue with both emulator and device. With API 28 - OK on emulator but issue with device

Actually, here’s what I simplified the workaround down to:

  1. Download the previous release (link taken from the Readme, though that download section doesn’t seem to be updated, so the version numbers are different compared to what the release page lists, and it’s saying the previous release is still the current one).
  2. Just extract the downloaded .vsix file as if it’s a zip.
  3. Take the $MSBuild\Xamarin folder of the extracted folder and use it to replace C:\Program Files (x86)\Microsoft Visual Studio\2019\<Edition>\MSBuild\Xamarin. (Make sure to backup the existing folder of course.)
  4. Restart Visual Studio and do a rebuild of the project (not sure if this is necessary).
  5. Run from Visual Studio without problems.

In my case I’m only building for arm64-v8a, but only replacing $MSBuild\Xamarin\Android\lib\arm64-v8a doesn’t help, so I took that whole root folder instead. There is no need to replace any other folder/file as far as I can see.

Perhaps this helps in the process of identifying what’s going wrong here and allows others to work around for now.

Same issue here. I had to manually roll back just the Xamarin.Android extension for Visual Studio for now, after I attempted a repair of VS.