Azure-Samples / cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

DonKamillo2905 opened this issue · comments

Describe the bug
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 APK 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, but the application does not close. 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.

To Reproduce

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).
  • Build and sign the APK.
  • Install and run the application on an Android device.
  • Observe the crash on the first run.

Expected behavior

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

Version of the Cognitive Services Speech SDK

Version 1.36.0

Platform, Operating System, and Programming Language

OS: Android
Programming language: Kotlin

Additional context

  • 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)

  • Any 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 application configuration is:
minSdk: 28
targetSdk: 34
compileSdkVersion: 34

I followed the steps that you mentioned. I could not reproduce this.

The error only occurs when I Generate Signed App Bundle in release mode. When I run app from Android Studio, everything works fine.
Maybe code minification or resource shrinking removes something. Do I need to add anything special to ProGuard? I didn't see anything in the Sample code.

It seems that the exact same app built as APK works but built as Android App Bundle doesn't work.
Is there any solution for this?