DeepSpeech-examples icon indicating copy to clipboard operation
DeepSpeech-examples copied to clipboard

DeepSpeechDemo App works with Gradle cli but crashes in Android Studio

Open zaptrem opened this issue 5 years ago • 10 comments

The android-mic-streaming demo works off-the-shelf using ./gradlew installDebug, but when the play button in Android Studio is used to compile and install the exact same project it crashes with the following after tapping record:

2020-08-19 00:44:24.862 12872-12872/org.deepspeechdemo E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.deepspeechdemo, PID: 12872
    java.lang.IllegalStateException: Could not execute method for android:onClick
        at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
        at android.view.View.performClick(View.java:7448)
        at android.view.View.performClickInternal(View.java:7425)
        at android.view.View.access$3600(View.java:810)
        at android.view.View$PerformClick.run(View.java:28296)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        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)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
        at android.view.View.performClick(View.java:7448) 
        at android.view.View.performClickInternal(View.java:7425) 
        at android.view.View.access$3600(View.java:810) 
        at android.view.View$PerformClick.run(View.java:28296) 
        at android.os.Handler.handleCallback(Handler.java:938) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        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) 
     Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: library "libdeepspeech-jni.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
        at java.lang.System.loadLibrary(System.java:1664)
        at org.mozilla.deepspeech.libdeepspeech.DeepSpeechModel.<clinit>(DeepSpeechModel.java:9)
        at org.deepspeechdemo.MainActivity.createModel(MainActivity.kt:90)
        at org.deepspeechdemo.MainActivity.onRecordClick(MainActivity.kt:120)
        at java.lang.reflect.Method.invoke(Native Method) 
        at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) 
        at android.view.View.performClick(View.java:7448) 
        at android.view.View.performClickInternal(View.java:7425) 
        at android.view.View.access$3600(View.java:810) 
        at android.view.View$PerformClick.run(View.java:28296) 
        at android.os.Handler.handleCallback(Handler.java:938) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        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) 


The issue seems to be related to libdeepspeech-jni.so not being included when Android Studio is used. I am completely new to Android development (I'm building a Mozilla-STT React Native module and only supporting iOS is useless) so this is especially confusing.

Thanks!

zaptrem avatar Aug 19 '20 05:08 zaptrem

@zaptrem could you describe your achievement in using of this library on iOS? Is it possible to have some similar functionality as in DeepSpeechDemo app on iOS using tflite and scorer models?

imart avatar Aug 19 '20 10:08 imart

@imart The test project here does nearly the same thing without the live updates.

zaptrem avatar Aug 19 '20 16:08 zaptrem

@reuben Any idea what could be causing this? The same thing is happening in the DeepSpeech React Native module I'm building and I bet it's caused by whatever is causing this issue.

zaptrem avatar Aug 19 '20 20:08 zaptrem

@zaptrem I don't know much about Android Studio but I was able to use that project just fine with the play button as recently as two weeks ago.

reuben avatar Aug 19 '20 23:08 reuben

Probably some dependencies are missed, you can check it in File->Project Structure. If everything declared correct maybe File->Invalidate Caches/Restart (use both actions) could help.

imart avatar Aug 20 '20 04:08 imart

Probably some dependencies are missed, you can check it in File->Project Structure. If everything declared correct maybe File->Invalidate Caches/Restart (use both actions) could help.

Thanks for the suggestions! The project dependencies in AS seem to match the build.gradle (which, I assume, is what ./gradlew installDebug uses). image

I tried invalidating the caches and restarting and got the same result. Works fine with the terminal command but crashes with the missing .so file when using the Android Studio output.

zaptrem avatar Aug 20 '20 04:08 zaptrem

@reuben Hours of random trial and error later: Changing this option from "Default APK" to "APK from app bundle" in Android Studio made the demo start working Screen Shot 2020-08-21 at 12 26 56 AM

However, doing the same on my example app for the React Native module (which has a dependency android project containing JS->Java interface code which finally depends on the actual libdeepspeech) didn't work. What about the way this lib is bundled causes libdeepspeech-jni.so to not be bundled/found under certain circumstances?

zaptrem avatar Aug 21 '20 04:08 zaptrem

It looks like x86 libdeepspeech-jni.so and libdeepspeech.so are not being bundled with the project, so it crashes on 32bit phones. However, other architecture versions of these libraries are. What could be causing this? Screen Shot 2020-08-21 at 5 05 48 PM

zaptrem avatar Aug 21 '20 21:08 zaptrem

I have the same issues when I'm trying to use the app on an emulator (Pixel 2, API 24) Try to start the app from Android Studio on a real device, it works for me. Seems the issue is reproducible on emulators only.

imart avatar Aug 30 '20 10:08 imart

I had this problem too, I think it's because the emulator is 32-bit x86 and our library doesn't include a binary for that arch. There's some new experimental x86_64 emulator on the latest Android SDK that is even supposed to do ARM code translation and run mixed architecture code but I couldn't get it to work.

Am 30.08.2020 um 12:25 schrieb imart [email protected]:

 I have the same issues when I'm trying to use the app on an emulator (Pixel 2, API 24):

2020-08-30 13:19:59.805 10783-10783/org.harman.offlinerecognizer E/AndroidRuntime: FATAL EXCEPTION: main Process: org.harman.offlinerecognizer, PID: 10783 java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.harman.offlinerecognizer-2/base.apk"],nativeLibraryDirectories=[/data/app/org.harman.offlinerecognizer-2/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libdeepspeech-jni.so" at java.lang.Runtime.loadLibrary0(Runtime.java:972) at java.lang.System.loadLibrary(System.java:1530) at org.mozilla.deepspeech.libdeepspeech.DeepSpeechModel.(DeepSpeechModel.java:9) at org.harman.offlinerecognizer.RecognizerActivity.createModel(RecognizerActivity.kt:207) at org.harman.offlinerecognizer.RecognizerActivity.startListening(RecognizerActivity.kt:182) at org.harman.offlinerecognizer.RecognizerActivity.access$startListening(RecognizerActivity.kt:23) at org.harman.offlinerecognizer.RecognizerActivity$onCreate$1.onClick(RecognizerActivity.kt:44) at android.view.View.performClick(View.java:5610) at android.view.View$PerformClick.run(View.java:22265) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

Try to start the app from Android Studio on a real device, it works for me. Seems the issue is reproducible on emulators only.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

reuben avatar Aug 30 '20 11:08 reuben