alphacep / vosk-android-demo

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

Model initialization error with minifyEnabled #183

Closed prechtelm closed 2 years ago

prechtelm commented 2 years ago

Hi, when initializing the Model with StorageService.unpack(), I receive the following error:

    java.lang.UnsatisfiedLinkError: Can't obtain peer field ID for class com.sun.jna.Pointer
        at com.sun.jna.Native.initIDs(Native Method)
        at com.sun.jna.Native.<clinit>(:248)
        at com.sun.jna.Native.H(:1773)
        at org.vosk.LibVosk.<clinit>(:16)
        at org.vosk.LibVosk.vosk_model_new(Native Method)
        at org.vosk.Model.<init>(:10)
        at dy.k.i(:56)
        at dy.k.c(Unknown Source:0)
        at dy.h.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:919)](url)

The model is stored in the asset folder as described in the demo, everything runs smoothly when not using minifyEnabled option. Following versions are used, proguard file is updated as follows.

    implementation 'net.java.dev.jna:jna:5.11.0@aar'
    implementation (group: 'com.alphacephei', name: 'vosk-android', version: '0.3.37') {
        exclude group: 'net.java.dev.jna', module: 'jna'
    }
-keep class com.sun.jna.** { *; }
-keepclassmembers  class com.sun.jna.** {*;}

Any idea what could cause this issue or fix it?

nshmyrev commented 2 years ago

https://stackoverflow.com/questions/10557146/how-to-tell-proguard-to-avoid-obfuscating-jna-library-classes suggests also

    -keep class * implements com.sun.jna.** { *; }

probably it should help

prechtelm commented 2 years ago

That didn't fix the crash. Any other idea?

nshmyrev commented 2 years ago

Go inside the APK and check the class names are kept inact. If names are obfuscated, check that rules file actually apply.

prechtelm commented 2 years ago

oh boy, the dubug build was not using the proguard rules file. Thanks for your help!