Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Release apk throw UnsatisfiedLinkError #222

Closed
mmhmofu opened this issue Aug 19, 2024 · 7 comments
Closed

Android Release apk throw UnsatisfiedLinkError #222

mmhmofu opened this issue Aug 19, 2024 · 7 comments

Comments

@mmhmofu
Copy link

mmhmofu commented Aug 19, 2024

vosk run successfully on debug,but release apk crush.
Error Detail:
java.lang.UnsatisfiedLinkError: Can't obtain class com.sun.jna.Pointer
at com.sun.jna.Native.initIDs(Native Method)
at com.sun.jna.Native.(:7)
at com.sun.jna.Native.a()
at org.vosk.LibVosk.()
at org.vosk.LibVosk.vosk_model_new(Native Method)
at e.b.a.()
at e.b.c.k.a()
at e.b.c.f.run(lambda)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)

Dependency already implementation 'net.java.dev.jna:jna:5.13.0@aar'
implementation 'com.alphacephei:vosk-android:0.3.47@aar'

@mmhmofu
Copy link
Author

mmhmofu commented Aug 19, 2024

after add rule -keep class com.sun.jna.** { *; } in proguard-rules.pro file.it turns to another exception
java.lang.ExceptionInInitializerError
at org.vosk.LibVosk.vosk_model_new(Native Method)
at e.b.a.()
at e.b.c.k.a()
at e.b.c.f.run(lambda)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.IllegalArgumentException: Can't create an instance of class e.b.a, requires a public no-arg constructor: java.lang.NoSuchMethodException: []
at com.sun.jna.Klass.newInstance()
at com.sun.jna.NativeMappedConverter.defaultValue()
at com.sun.jna.NativeMappedConverter.()
at com.sun.jna.NativeMappedConverter.getInstance()
at com.sun.jna.Structure$FFIType.get()
at com.sun.jna.Structure$FFIType.get()
at com.sun.jna.Native.register()
at com.sun.jna.Native.register()
at org.vosk.LibVosk.()
... 7 more
Caused by: java.lang.NoSuchMethodException: []
at java.lang.Class.getConstructor0(Class.java:2204)
at java.lang.Class.getDeclaredConstructor(Class.java:2050)
... 16 more

@nshmyrev
Copy link
Collaborator

Hi

You likely need to edit minify project properties to keep required jni files. See here

https://stackoverflow.com/questions/57005617/java-lang-unsatisfiedlinkerror-cant-obtain-class-com-sun-jna-pointer-neurotec

@mmhmofu
Copy link
Author

mmhmofu commented Aug 20, 2024

Hi

You likely need to edit minify project properties to keep required jni files. See here

https://stackoverflow.com/questions/57005617/java-lang-unsatisfiedlinkerror-cant-obtain-class-com-sun-jna-pointer-neurotec

I already edit proguard-rules.pro file,it turns into another exception
QZZ)NM{WE4 %XD}H{8A`6R4

@mmhmofu
Copy link
Author

mmhmofu commented Aug 20, 2024

Hi

You likely need to edit minify project properties to keep required jni files. See here

https://stackoverflow.com/questions/57005617/java-lang-unsatisfiedlinkerror-cant-obtain-class-com-sun-jna-pointer-neurotec

same question in vosk-android-demo

@mmhmofu
Copy link
Author

mmhmofu commented Aug 20, 2024

Hi

You likely need to edit minify project properties to keep required jni files. See here

https://stackoverflow.com/questions/57005617/java-lang-unsatisfiedlinkerror-cant-obtain-class-com-sun-jna-pointer-neurotec

should add blew rule both
-keep class com.sun.jna.* { ; }
-keepclassmembers class * extends com.sun.jna.
{ public *; }
this can be help,thanks

@mmhmofu mmhmofu closed this as completed Aug 20, 2024
@dr0-dev
Copy link

dr0-dev commented Oct 21, 2024

this is not enough, I tried adding it and it still crashes

Native library (com/sun/jna/android-arm/libjnidispatch.so) not found in resource path (.)

@mmhmofu
Copy link
Author

mmhmofu commented Oct 24, 2024

this is not enough, I tried adding it and it still crashes

Native library (com/sun/jna/android-arm/libjnidispatch.so) not found in resource path (.)

try clean your project and rebuild , check the dependency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants