alphacep / vosk-api

Offline speech recognition API for Android, iOS, Raspberry Pi and servers with Python, Java, C# and Node
Apache License 2.0
7.7k stars 1.08k forks source link

JNA problems #1277

Closed Maivand closed 1 year ago

Maivand commented 1 year ago

I get this error directly after downloading the code trying to demo it.

E/AndroidRuntime: FATAL EXCEPTION: main Process: org.vosk.demo, PID: 29261 java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-x86/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.(Native.java:190) at com.sun.jna.Native.register(Native.java:1641) at org.vosk.LibVosk.(LibVosk.java:16) at org.vosk.LibVosk.setLogLevel(LibVosk.java:70) at org.vosk.demo.VoskActivity.onCreate(VoskActivity.java:72) at android.app.Activity.performCreate(Activity.java:7994) at android.app.Activity.performCreate(Activity.java:7978) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 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:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

nshmyrev commented 1 year ago

Please add jna to dependencies

implementation 'net.java.dev.jna:jna:5.8.0@aar'

reverting this change:

https://github.com/alphacep/vosk-android-demo/commit/a4febb28ef9b508a59b88d4b4124c0461f3df5ee

nshmyrev commented 1 year ago

This should be fixed in https://github.com/alphacep/vosk-android-demo/commit/443b293e623dfd8753196c67a0dc3231f6839993

xekl commented 1 year ago

Thanks, that was fast! Unfortunately, it did not fix everything for me, I now cannot build instead due to a "duplicate class".

Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.sun.jna.AltCallingConvention found in modules jetified-jna-5.13.0 (net.java.dev.jna:jna:5.13.0) and jetified-jna-5.13.0-runtime (net.java.dev.jna:jna:5.13.0)
     Duplicate class com.sun.jna.Callback found in modules jetified-jna-5.13.0 (net.java.dev.jna:jna:5.13.0) and jetified-jna-5.13.0-runtime (net.java.dev.jna:jna:5.13.0)
     Duplicate class com.sun.jna.Callback$UncaughtExceptionHandler found in modules jetified-jna-5.13.0 (net.java.dev.jna:jna:5.13.0) and jetified-jna-5.13.0-runtime (net.java.dev.jna:jna:5.13.0)
     .... (and many more)

The same happens when using 5.8.0, as suggested in https://github.com/alphacep/vosk-api/issues/1277 (thanks for the link, though, I was thinking I had seen this somewhere before!).

nshmyrev commented 1 year ago

Ok, I need to investigate more I suppose

xekl commented 1 year ago

Thank you for looking into this! The suggestions I find online mostly consist of using gradle's "exclude group" feature

{
    exclude group: "net.java.dev.jna", module: "jna"
}

but this does not seem to work for implementation project(':models') whose LibVosk model apparently uses the "duplicate" JNA.

nshmyrev commented 1 year ago

check contents of apk file, does it include jna libraries?

xekl commented 1 year ago

According to Android Studio's APK viewer, yes, I think so:

grafik
nshmyrev commented 1 year ago

Thats strange, it seems to include some unrelated architectures, it should have armv7 instead, not darwin. How come so?

nshmyrev commented 1 year ago

Take a look inside https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.13.0/jna-5.13.0.aar for example

xekl commented 1 year ago

Thats strange, it seems to include some unrelated architectures, it should have armv7 instead, not darwin. How come so?

I don't know and I don't know how to find out. Maybe it has something to do with me working on a Mac? Something under the hood that gradle just "manages" without asking?

nshmyrev commented 1 year ago

@xekl I've just released 0.3.47 and pushed a dependency update here. Could you please update and check?

xekl commented 1 year ago

Yes, it works now with the new version. Awesome, thanks for the troubleshooting!

nshmyrev commented 1 year ago

Ok, good

Maivand commented 1 year ago

Ill give it a try later tonight to see if it works for me aswell.

Den tors 16 mars 2023 12:55Nickolay V. Shmyrev @.***> skrev:

Closed #1277 https://github.com/alphacep/vosk-api/issues/1277 as completed.

— Reply to this email directly, view it on GitHub https://github.com/alphacep/vosk-api/issues/1277#event-8766392833, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC36DMP2HDY6YTEEEKHFSOLW4L5TRANCNFSM6AAAAAAVCAQDIM . You are receiving this because you authored the thread.Message ID: @.***>

zooyf commented 4 months ago

0.3.47

Where is the 0.3.47 version? Neither in release nor in tags...

nshmyrev commented 4 months ago

@zooyf in maven

https://repo1.maven.org/maven2/com/alphacephei/vosk-android/0.3.47/

it will not help you likely if your problem about M1, I wrote you already