Skip to content

Several UnsatisfiedLinkError instantiating service on some devices, the crashes are reported only by Google Play Console. #4557

Closed as not planned

Description

@fernandovm

Steps to Reproduce

Unfortunately I not have know the steps to reproduce the problem, it happens in some devices (near 10% of device users) and are reported only in the Google Play Console, neither in appcenter are showed.

Expected Behavior

All must works fine, the service should run without crashes.

Actual Behavior

I have had many crashes reported only in the Google Play Console, neither in appcenter are showed. The issue happens in Android 7.1, 8, 8.1 and 9.

Version Information

Microsoft Visual Studio Enterprise 2019
Version 16.5.2
VisualStudio.16.Release/16.5.2+29926.136
Microsoft .NET Framework
Version 4.8.03752
Installed Version: Enterprise

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

Mono Debugging for Visual Studio   16.5.514 (c4f36a9)
Support for debugging Mono processes with Visual Studio.

Xamarin   16.5.000.528 (d16-5@2b54082)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.5.0.470 (remotes/origin/d16-5@681de3fd6)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.5.49 (0904f41)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   10.2.0.100 (d16-5/988c811)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: c0c5c78
    Java.Interop: xamarin/java.interop/d16-5@fc18c54
    ProGuard: xamarin/proguard/master@905836d
    SQLite: xamarin/sqlite/3.28.0@46204c4
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-5@9f4ed4b

Xamarin.iOS and Xamarin.Mac SDK   13.16.0.11 (aa73e41)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Crash stack trace (Google Play Console)

java.lang.UnsatisfiedLinkError: 
  at mono.android.Runtime.register (Native Method)
  at studying.mainService.<clinit>
  at java.lang.Class.newInstance (Native Method)
  at android.app.ActivityThread.handleCreateService (ActivityThread.java:3302)
  at android.app.ActivityThread.-wrap5 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1636)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:154)
  at android.app.ActivityThread.main (ActivityThread.java:6351)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:896)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:786)

Appstore build properties

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'AppStore|AnyCPU'">
    <DefineConstants>TRACE;;MODE_APPSTORE;MODE_RELEASE;MODE_ONLINE</DefineConstants>
    <Optimize>true</Optimize>
    <AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
    <AndroidLinkMode>SdkOnly</AndroidLinkMode>
    <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
    <BundleAssemblies>True</BundleAssemblies>
    <AndroidCreatePackagePerAbi>True</AndroidCreatePackagePerAbi>
    <Debugger>Xamarin</Debugger>
    <AotAssemblies>true</AotAssemblies>
    <EnableLLVM>true</EnableLLVM>
    <AndroidEnableMultiDex>false</AndroidEnableMultiDex>
    <DebugSymbols>False</DebugSymbols>
    <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
    <OutputPath>bin\AppStore\</OutputPath>
    <AndroidSupportedAbis>
    </AndroidSupportedAbis>
    <AndroidDexTool>d8</AndroidDexTool>
    <AndroidLinkTool>r8</AndroidLinkTool>
    <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
    <AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
    <AndroidPackageFormat>apk</AndroidPackageFormat>
    <MandroidI18n />
  </PropertyGroup>

Print screen of main related devices

image

image

image

Please, can anyone help me?

Activity

  1. added
    Area: App Runtime
    on Apr 15, 2020
  2. jonpryor commented on Apr 15, 2020

    @jonpryor
    Contributor

    Unfortunately, I know what this error means but not why it occurs, much less how to reliably fix it.

    What the java.lang.UnsatisfiedLinkError means is that libmonodroid.so hasn't been loaded, e.g. a "should have previously executed" System.loadLibrary("monodroid") was not, in fact, executed. Or it was executed, and it didn't fail, but it didn't work right. Or it failed, but it didn't prevent the process from starting. Or…?

    The why is where things get less explainable: why didn't libmonodroid.so get loaded? (See above questions, none of which are answerable with what the Google Play Console provided you.)

    We have also seen instances in which Android doesn't properly handle .apk upgrades when the .apk contains native libraries, e.g. some of the native libraries weren't upgraded.

    You may consider trying setting the @android:extractNativeLibs attribute within the <application/> element to false: https://github.com/xamarin/xamarin-android/blob/f4fc2552299a3174a14dfeb314a2d3867218037d/Documentation/guides/extract-native-libraries.md

  3. added this to the Under Consideration milestone on Apr 15, 2020
  4. added
    need-info
    on Apr 15, 2020
  5. fernandovm commented on Apr 16, 2020

    @fernandovm
    Author

    Hi @jonpryor, thank you for attention.

    I understand, I would like to help to investigate the issue, but it is a bit obscure and never has happens in my development devices. The fact that crash is not reported by appcenter not helps, if it was tracked I would has more informations about the issue.

    I will consider the tip of use the @android:extractNativeLibs attribute but, additionaly, hoping to maybe help, som facts about the issue:

    • Near 95% of affected are LG (K30, K9 and Q6) or Zenfone (3, 4 and 5) devices.

    • Near 98% of the incidence of this issue happens after I migrate for Xamarin Forms 4, enabled the options AOT Compilation / Use LLVM and migration for dx/r8.

  6. moljac commented on May 18, 2020

    @moljac
    Contributor

    @fernandovm
    Please provide some feedback for further investigation. Otherwise we will be forced to close the issue.

    Thanks

  7. fernandovm commented on May 18, 2020

    @fernandovm
    Author

    @moljac, the issue continue, mainly with the same cited devices, but I not have new technical details to add. It never has happens in my development devices, neither in appcenter it are showed. See, in the last 7 days:

    image

    image

  8. fernandovm commented on May 19, 2020

    @fernandovm
    Author

    @moljac, if there is any other tests that I can do to help identify the issue, I will do it, but until now I couldn't think new ideas. :((

  9. MarvinFrankenfeld commented on Jun 5, 2020

    @MarvinFrankenfeld

    @jonpryor , android:extractNativeLibs is only relevant when using apk and not aab, right?

  10. fernandovm commented on Jun 12, 2020

    @fernandovm
    Author

    Guys, in the last night I made some tests alternating the android options AOT Compilation and Use LLVM and I have noted that several times afeter an app update alternating this options (from/to, on->off, off->on) I get "abnormally" erros, such as:

    06-10 15:10:34.028 23157 23157 I art : Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList .....

    Could this be related with this issue also?

  11. moljac commented on Jun 13, 2020

    @moljac
    Contributor
  12. fernandovm commented on Jun 14, 2020

    @fernandovm
    Author

    Ok, thanks, I will try.

  13. radekdoulik commented on Jul 15, 2020

    @radekdoulik
    Member

    Did @moljac suggestion work?

  14. fernandovm commented on Jul 15, 2020

    @fernandovm
    Author

    Yes, it works, but it is about OnUnhandledKeyEventListener, not about the main issue, this continue generating bad indicators in Google Play Console.

  15. removed
    need-info
    on Jul 21, 2020
  16. holecekp commented on Sep 24, 2020

    @holecekp

    Any update? I have similar crash reports in Google Play - the error is UnsatisfiedLinkError but the stack trace is different. I have thought that it is a Xamarin.Forms problem so I posted the issue details there: xamarin/Xamarin.Forms#12218

  17. alexcohn commented on May 6, 2021

    @alexcohn

    @jonpryor , android:extractNativeLibs is only relevant when using apk and not aab, right?

    Quite contrary. The trouble with LG is that they don't correctly handle the @android:extractNativeLibs="false" attribute within the when the app is installed on the sd-card. Some Xiaomi (and other) devices fail with extractNativeLibs="false" even if the app is installed in the primary storage.

    This is especially relevant for aab because there extractNativeLibs="false" has always been the default, so you must explicitly set @android:extractNativeLibs="true" to make sure your app works smoothly on all devices . Note that the default for apk has silently changed (it's same as aab now) with introduction of Android Gradle plugin 3.6.0 in February 2020.

    It's very unfortunate that this still haunts us 5 years after the optimization was introduced for Android 6. IMHO, part of the problem is an unintuitive choice of the attribute name.

  18. grendello commented on Aug 2, 2021

    @grendello
    Contributor

    @alexcohn The issue of @android:extractNativeLibs="false" being unreliable has been addressed in bf657e8 (it wasn't just LG devices). We no longer trust it in any shape or form.

  19. holecekp commented on May 12, 2022

    @holecekp

    Occasional UnsatisfiedLinkError crashes are still reported by Google Play Console. I am using Xamarin.Forms version 5.0.0.2337.

    java.lang.UnsatisfiedLinkError: 
      at java.lang.Runtime.loadLibrary0 (Runtime.java:1067)
      at java.lang.Runtime.loadLibrary0 (Runtime.java:1007)
      at java.lang.System.loadLibrary (System.java:1667)
      at mono.MonoPackageManager.LoadApplication (Unknown Source:115)
      at mono.MonoRuntimeProvider.attachInfo (Unknown Source:41)
      at android.app.ActivityThread.installProvider (ActivityThread.java:7211)
      at android.app.ActivityThread.installContentProviders (ActivityThread.java:6694)
      at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6589)
      at android.app.ActivityThread.access$1400 (ActivityThread.java:227)
      at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1890)
      at android.os.Handler.dispatchMessage (Handler.java:107)
      at android.os.Looper.loop (Looper.java:224)
      at android.app.ActivityThread.main (ActivityThread.java:7590)
      at java.lang.reflect.Method.invoke (Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:539)
      at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950)
    
  20. DiebBlue commented on Jul 18, 2022

    @DiebBlue

    I had nearly the same crash report on the google play console as @holecekp. I also use Xamarin Forms 5.0.0.2337. This error occurred in a peak only on 07/15/2022 on Samsung Galaxy J6, Samsung Galaxy M20 and Huawai Mate 20 lite devices, not otherwise. Neither before nor after. Could maintenance work at Google be behind this?

    java.lang.UnsatisfiedLinkError: at java.lang.Runtime.loadLibrary0 (Runtime.java:1067) at java.lang.Runtime.loadLibrary0 (Runtime.java:1007) at java.lang.System.loadLibrary (System.java:1667) at mono.MonoPackageManager.LoadApplication (MonoPackageManager.java:78) at mono.MonoRuntimeProvider.attachInfo (MonoRuntimeProvider.java:35) at android.app.ActivityThread.installProvider (ActivityThread.java:7545) at android.app.ActivityThread.installContentProviders (ActivityThread.java:7090) at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6978) at android.app.ActivityThread.access$1300 (ActivityThread.java:270) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2051) at android.os.Handler.dispatchMessage (Handler.java:107) at android.os.Looper.loop (Looper.java:237) at android.app.ActivityThread.main (ActivityThread.java:7948) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1075)

  21. holecekp commented on Aug 10, 2022

    @holecekp

    Is there any progress? I am getting occasionally crash reports also for my app installed directly from Google Play:

    Exception java.lang.UnsatisfiedLinkError: dlopen failed: library "libmonosgen-2.0.so" not found
      at java.lang.Runtime.loadLibrary0 (Runtime.java:1087)
      at java.lang.Runtime.loadLibrary0 (Runtime.java:1008)
      at java.lang.System.loadLibrary (System.java:1664)
      at mono.MonoPackageManager.LoadApplication (MonoPackageManager.java:89)
      at mono.MonoRuntimeProvider.attachInfo (MonoRuntimeProvider.java:35)
      at android.app.ActivityThread.installProvider (ActivityThread.java:7674)
      at android.app.ActivityThread.installContentProviders (ActivityThread.java:7153)
      at android.app.ActivityThread.handleBindApplication (ActivityThread.java:7026)
      at android.app.ActivityThread.access$1600 (ActivityThread.java:257)
      at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2001)
      at android.os.Handler.dispatchMessage (Handler.java:106)
      at android.os.Looper.loop (Looper.java:236)
      at android.app.ActivityThread.main (ActivityThread.java:8107)
      at java.lang.reflect.Method.invoke (Method.java)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:656)
      at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:967)
    
  22. jpobst commented on May 13, 2024

    @jpobst
    Contributor

    With support for Classic Xamarin.Android ended May 1st, 2024, this issue is likely no longer relevant.

    If this still persists in .NET 8+, please open a new issue with updated information based on net8.0-android or greater. Please include a link to this issue for context.

  23. locked and limited conversation to collaborators on Jun 13, 2024
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

    Area: App Runtime

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions