Android SpeechConfig.fromSubscription(subscriptionKey, region) java.lang.UnsatisfiedLinkError

Kamil Poplawski 0 Reputation points
2024-07-30T11:02:56.5333333+00:00

The Android app crashes with the error java.lang.UnsatisfiedLinkError: dlopen failed: library "libMicrosoft.CognitiveServices.Speech.java.bindings.so" not found when trying to load the native libraries for Microsoft Cognitive Services Speech SDK in an Android application.

The issue occurs consistently on the first run after installation but does not occur on subsequent runs. Additionally, logs show a FileNotFoundException for the library files.

The crash specifically happens when calling SpeechConfig.fromSubscription(subscriptionKey, region). Even when wrapping this call in a try-catch block, the application still crashes. I also tried manually loading the library using System.loadLibrary("Microsoft.CognitiveServices.Speech.core"). This throws an error, this same result. Subsequent calls to this method do not cause an error. The application works correctly when run directly from Android Studio, but the error occurs when running the signed and bundled version.

Steps to reproduce the behavior:

  • Create a new Android project using Kotlin.
  • Add Microsoft Cognitive Services Speech SDK to the project.
  • Call the method SpeechConfig.fromSubscription(subscriptionKey, region).
  • Generate Signed App Bundle (App crash only with App Bundle)
  • Upload app to Play console or Play Internal App Sharing
  • Install and run the application on an Android device.
  • Observe the crash on the first run.

Expected behavior
The libraries should load without errors, and the application should initialize the SpeechConfig object without crashing.

Error messages, stack trace:

Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/app/~~1CywurgSdGhS2cDMajgORA==/com.kkk.english_words-HlTbCWv0RojPkHln29utGg==/split_config.arm64_v8a.apk!/lib/arm64-v8a/libMicrosoft.CognitiveServices.Speech.java.bindings.so" not found at java.lang.Runtime.loadLibrary0(Runtime.java:1082) at java.lang.Runtime.loadLibrary0(Runtime.java:1003) at java.lang.System.loadLibrary(System.java:1661) at com.microsoft.cognitiveservices.speech.SpeechConfig.<clinit>(SpeechConfig.java:21) at org.livango.ui.lesson.general.LessonViewModel$init$2$1.invokeSuspend(LessonViewModel.kt:266) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8762) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

The app configuration:

  • minSdk: 28
  • targetSdk: 34
  • compileSdkVersion: 34
  • Version of the Cognitive Services Speech SDK 1.36.0

Additional information:
The issue occurs on the first run after installation. Subsequent runs do not exhibit the issue. The problem occurs on multiple devices and is logged in Firebase Crashlytics.
The error only occurs when I Generate Signed App Bundle in release mode. When I run app from Android Studio or build APK isntead of Bundle, everything works fine.

I think that there is some problem with loading library in Bundle app.

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,655 questions
{count} votes