How to use the android demo

I got some error, while using “make apk” instruction.

How can I fix it?
thanks a lot.

(deepspeech-venv) wmlab@wmlab-317server:~/deepvoice/DeepSpeech/native_client/java$ make apk
./gradlew clean

Configure project :libdeepspeech
arm64-v8a armeabi-v7a x86_64
Task :libdeepspeech:externalNativeBuildCleanDebug
Clean deepspeech-jni armeabi-v7a,deepspeech-lib armeabi-v7a
Cleaning… 0 files.
Clean deepspeech-lib arm64-v8a,deepspeech-jni arm64-v8a
Cleaning… 0 files.
Clean deepspeech-jni x86_64,deepspeech-lib x86_64
Cleaning… 0 files.

BUILD SUCCESSFUL in 0s
5 actionable tasks: 2 executed, 3 up-to-date
rm -rf *.java jni/deepspeech_wrap.cpp
swig -c++ -java -package org.mozilla.deepspeech.libdeepspeech -outdir libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech/ -o jni/deepspeech_wrap.cpp jni/deepspeech.i
./gradlew build

Configure project :libdeepspeech
arm64-v8a armeabi-v7a x86_64
Task :libdeepspeech:externalNativeBuildDebug FAILED
Build deepspeech-jni x86_64
[1/2] Building CXX object CMakeFiles/deepspeech-jni.dir/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp.o
[2/2] Linking CXX shared library …/…/…/…/build/intermediates/cmake/debug/obj/x86_64/libdeepspeech-jni.so
FAILED: : && /home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=x86_64-none-linux-android21 --gcc-toolchain=/home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,–noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,–exclude-libs,libgcc.a -Wl,–exclude-libs,libatomic.a -static-libstdc++ -Wl,–build-id -Wl,–warn-shared-textrel -Wl,–fatal-warnings -Wl,–no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libdeepspeech-jni.so -o …/…/…/…/build/intermediates/cmake/debug/obj/x86_64/libdeepspeech-jni.so CMakeFiles/deepspeech-jni.dir/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp.o …/…/…/…/libs/x86_64/libdeepspeech.so /home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21/liblog.so -latomic -lm && cd /home/wmlab/deepvoice/DeepSpeech/native_client/java/libdeepspeech/.externalNativeBuild/cmake/debug/x86_64 && /home/wmlab/Android/Sdk/cmake/3.6.4111459/bin/cmake -E copy /home/wmlab/deepvoice/DeepSpeech/native_client/java/libdeepspeech/libs/x86_64/libdeepspeech.so /home/wmlab/deepvoice/DeepSpeech/native_client/java/libdeepspeech/build/intermediates/cmake/debug/obj/x86_64/libdeepspeech.so
/home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/…/…/…/…/x86_64-linux-android/bin/ld: error: …/…/…/…/libs/x86_64/libdeepspeech.so: incompatible target
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:919: error: undefined reference to ‘DS_FreeMetadata’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1517: error: undefined reference to ‘DS_CreateModel’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1531: error: undefined reference to ‘DS_DestroyModel’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1565: error: undefined reference to ‘DS_EnableDecoderWithLM’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1589: error: undefined reference to ‘DS_SpeechToText’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1593: error: undefined reference to ‘DS_FreeString’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1613: error: undefined reference to ‘DS_SpeechToTextWithMetadata’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1633: error: undefined reference to ‘DS_SetupStream’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1650: error: undefined reference to ‘DS_FeedAudioContent’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1664: error: undefined reference to ‘DS_IntermediateDecode’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1666: error: undefined reference to ‘DS_FreeString’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1679: error: undefined reference to ‘DS_FinishStream’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1681: error: undefined reference to ‘DS_FreeString’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1694: error: undefined reference to ‘DS_FinishStreamWithMetadata’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1706: error: undefined reference to ‘DS_DiscardStream’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1717: error: undefined reference to ‘DS_FreeMetadata’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1731: error: undefined reference to ‘DS_FreeString’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1739: error: undefined reference to ‘DS_PrintVersions’
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:libdeepspeech:externalNativeBuildDebug’.

Build command failed.
Error while executing process /home/wmlab/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {–build /home/wmlab/deepvoice/DeepSpeech/native_client/java/libdeepspeech/.externalNativeBuild/cmake/debug/x86_64 --target deepspeech-jni}
[1/2] Building CXX object CMakeFiles/deepspeech-jni.dir/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp.o
[2/2] Linking CXX shared library …/…/…/…/build/intermediates/cmake/debug/obj/x86_64/libdeepspeech-jni.so
FAILED: : && /home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=x86_64-none-linux-android21 --gcc-toolchain=/home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,–noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,–exclude-libs,libgcc.a -Wl,–exclude-libs,libatomic.a -static-libstdc++ -Wl,–build-id -Wl,–warn-shared-textrel -Wl,–fatal-warnings -Wl,–no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libdeepspeech-jni.so -o …/…/…/…/build/intermediates/cmake/debug/obj/x86_64/libdeepspeech-jni.so CMakeFiles/deepspeech-jni.dir/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp.o …/…/…/…/libs/x86_64/libdeepspeech.so /home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21/liblog.so -latomic -lm && cd /home/wmlab/deepvoice/DeepSpeech/native_client/java/libdeepspeech/.externalNativeBuild/cmake/debug/x86_64 && /home/wmlab/Android/Sdk/cmake/3.6.4111459/bin/cmake -E copy /home/wmlab/deepvoice/DeepSpeech/native_client/java/libdeepspeech/libs/x86_64/libdeepspeech.so /home/wmlab/deepvoice/DeepSpeech/native_client/java/libdeepspeech/build/intermediates/cmake/debug/obj/x86_64/libdeepspeech.so
/home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/…/…/…/…/x86_64-linux-android/bin/ld: error: …/…/…/…/libs/x86_64/libdeepspeech.so: incompatible target
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:919: error: undefined reference to ‘DS_FreeMetadata’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1517: error: undefined reference to ‘DS_CreateModel’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1531: error: undefined reference to ‘DS_DestroyModel’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1565: error: undefined reference to ‘DS_EnableDecoderWithLM’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1589: error: undefined reference to ‘DS_SpeechToText’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1593: error: undefined reference to ‘DS_FreeString’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1613: error: undefined reference to ‘DS_SpeechToTextWithMetadata’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1633: error: undefined reference to ‘DS_SetupStream’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1650: error: undefined reference to ‘DS_FeedAudioContent’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1664: error: undefined reference to ‘DS_IntermediateDecode’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1666: error: undefined reference to ‘DS_FreeString’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1679: error: undefined reference to ‘DS_FinishStream’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1681: error: undefined reference to ‘DS_FreeString’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1694: error: undefined reference to ‘DS_FinishStreamWithMetadata’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1706: error: undefined reference to ‘DS_DiscardStream’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1717: error: undefined reference to ‘DS_FreeMetadata’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1731: error: undefined reference to ‘DS_FreeString’
/home/wmlab/deepvoice/DeepSpeech/native_client/java/jni/deepspeech_wrap.cpp:1739: error: undefined reference to ‘DS_PrintVersions’
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 2s
38 actionable tasks: 35 executed, 3 up-to-date
Makefile:23: recipe for target ‘apk’ failed
make: *** [apk] Error 1

It seems to be your issue.

Can you give more context on your setup ? What does file /home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/…/…/…/…/x86_64-linux-android/bin/ld: error: …/…/…/…/libs/x86_64/libdeepspeech.so returns ?

Thanks for reply. :slight_smile:

My setup is ubuntu16.04 LTS
I use swig 3.0.12 and I put the libdeepspeech.so which is from the native_client.arm64.cpu.linux.tar.xz of 0.5.1 release, into three directories (/native client/java/libdeepspeech/libs/{arm64-v8a,armeabi-v7a, x86_64} )
I think the Android/Sdk directory was generated by Android studio.

By the way, I type in the instruction “file /home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/…/…/…/…/x86_64-linux-android/bin/ld: error: …/…/…/…/libs/x86_64/libdeepspeech.so” and got some message below.

wmlab@wmlab-317server:~/deepvoice/DeepSpeech/native_client/java$ file /home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/…/…/…/…/x86_64-linux-android/bin/ld: error: …/…/…/…/libs/x86_64/libdeepspeech.so
/home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/…/…/…/…/x86_64-linux-android/bin/ld:: cannot open /home/wmlab/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/…/…/…/…/x86_64-linux-android/bin/ld:' (No such file or directory) error:: cannot openerror:’ (No such file or directory)
…/…/…/…/libs/x86_64/libdeepspeech.so: cannot open `…/…/…/…/libs/x86_64/libdeepspeech.so’ (No such file or directory)

Thank you very much.

You need to download each arch, they are different binaries. If you put ARM64 into those three directories, then no surprise.

Thanks for reply again.

I finally put libdeepspeech.so from “native_client.arm64.cpu.android.tar.xz” to “/native client/java/libdeepspeech/libs/arm64-v8a”,
libdeepspeech.so from “native_client.amd64.cpu.linux.tar.xz” to “/native client/java/libdeepspeech/libs/x86_64”,
libdeepspeech.so from “native_client.armv7.cpu.android.tar.xz” to “/native client/java/libdeepspeech/libs/armeabi-v7a”,

so finally it build successful, and I got an .apk file in “/native client/java/app/build/outputs/apk/release/app-0.6.0-alpha.5-release-unsigned.apk”

I have not test the apk file, but I will do it as soon as possible.
If some error comes out while testing apk on my android device, i will post it on this forum.

Thank you very much.:smiley:

I’m surprised that you got tricked, if you can identify what is unclear in the current documentation, please send a PR to improve it.