alphacep / vosk-android-demo

Offline speech recognition for Android with Vosk library.
Apache License 2.0
755 stars 207 forks source link

Cannot run demo due to UnsatisfiedLinkError #201

Closed xekl closed 1 year ago

xekl commented 1 year ago

When I load the demo project in Android Studio and try to run it on a connected device, it starts but immediately crashes. I'm working on a Mac with a 2,6 GHz 6-Core Intel Core i7 and Ventura 13.2.1 and from the logs, I gather there is some problem with libjnidispatch.so:

Install successfully finished in 9 s 276 ms.
$ adb shell am start -n "org.vosk.demo/org.vosk.demo.VoskActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 14165 on device 'samsung-sm_t510-R52N600LKBT'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
D/ActivityThread: handleBindApplication()++ app=org.vosk.demo
D/LoadedApk: LoadedApk::makeApplication() appContext=android.app.ContextImpl@f7447f1 appContext.mOpPackageName=org.vosk.demo appContext.mBasePackageName=org.vosk.demo appContext.mPackageInfo=android.app.LoadedApk@7d43fd6
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/ActivityThread: handleBindApplication() -- skipGraphicsSupport=false
I/DecorView: [INFO] isPopOver=false, config=true
I/DecorView: updateCaptionType >> DecorView@fd30429[], isFloating=false, isApplication=true, hasWindowDecorCaption=false, hasWindowControllerCallback=true
D/DecorView: setCaptionType = 0, this = DecorView@fd30429[]
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.vosk.demo, PID: 14165
    java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-arm/libjnidispatch.so) not found in resource path (.)
        at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:962)
        at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:922)
        at com.sun.jna.Native.<clinit>(Native.java:190)
        at com.sun.jna.Native.register(Native.java:1641)
        at org.vosk.LibVosk.<clinit>(LibVosk.java:16)
        at org.vosk.LibVosk.setLogLevel(LibVosk.java:70)
        at org.vosk.demo.VoskActivity.onCreate(VoskActivity.java:74)
        at android.app.Activity.performCreate(Activity.java:8207)
        at android.app.Activity.performCreate(Activity.java:8191)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3819)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4022)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2336)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:246)
        at android.app.ActivityThread.main(ActivityThread.java:8653)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
I/Process: Sending signal. PID: 14165 SIG: 9

Simply commenting out the line in question, VoskActivity.java:74 (which is just LibVosk.setLogLevel(LogLevel.INFO);) fixes this particular error and, in fact, lets the app show its interface, but problems with JNA remain and it crashes shortly after:

V/StorageService: Copy model-en-us/ivector/splice.conf to /storage/emulated/0/Android/data/org.vosk.demo/files/model
V/StorageService: Copy model-en-us/uuid to /storage/emulated/0/Android/data/org.vosk.demo/files/model
E/AndroidRuntime: FATAL EXCEPTION: pool-3-thread-1
    Process: org.vosk.demo, PID: 14660
    java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-arm/libjnidispatch.so) not found in resource path (.)
        at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:962)
        at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:922)
        at com.sun.jna.Native.<clinit>(Native.java:190)
        at com.sun.jna.Native.register(Native.java:1641)
        at org.vosk.LibVosk.<clinit>(LibVosk.java:16)
        at org.vosk.LibVosk.vosk_model_new(Native Method)
        at org.vosk.Model.<init>(Model.java:11)
        at org.vosk.android.StorageService.lambda$unpack$2(StorageService.java:56)
        at org.vosk.android.StorageService$$ExternalSyntheticLambda2.run(Unknown Source:12)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
I/ViewRootImpl@2bc7788[VoskActivity]: MSG_WINDOW_FOCUS_CHANGED 0 1
I/Process: Sending signal. PID: 14660 SIG: 9
nshmyrev commented 1 year ago

Same as

https://github.com/alphacep/vosk-api/issues/1277

please return back jna dependency

nshmyrev commented 1 year ago

I just pushed a fix, simply update