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 - Issue when trying to integrate with new app #200

Closed
shbkrm opened this issue May 23, 2017 · 15 comments
Closed

Android - Issue when trying to integrate with new app #200

shbkrm opened this issue May 23, 2017 · 15 comments

Comments

@shbkrm
Copy link

shbkrm commented May 23, 2017

I have created a new Android app.
Modified the SNOWBOYDETECTJAVAPKG and SNOWBOYDETECTJAVAPKGDIR in makefile accordingly.
Generated .so file added the same in jniLibs, modified gradle file. The .so file is picked up properly ( was able to see it when I extract the .apk file)
When I run the app,

I get the below error

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.graspio.myapplication, PID: 25560
java.lang.UnsatisfiedLinkError: No implementation found for long com.graspio.myapplication.snowboyJNI.new_SnowboyDetect(java.lang.String, java.lang.String) (tried Java_com_graspio_myapplication_snowboyJNI_new_1SnowboyDetect and Java_com_graspio_myapplication_snowboyJNI_new_1SnowboyDetect__Ljava_lang_String_2Ljava_lang_String_2)
at com.graspio.myapplication.snowboyJNI.new_SnowboyDetect(Native Method)
at com.graspio.myapplication.SnowboyDetect.(SnowboyDetect.java:0)
at com.graspio.myapplication.audio.RecordingThread.(RecordingThread.java:38)
at com.graspio.myapplication.MainActivity.onCreate(MainActivity.java:18)
at android.app.Activity.performCreate(Activity.java:6672)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
at

I checked the generated snowboy-detect-swig.cc file, in which the function "Java_com_graspio_myapplication_snowboyJNI_new_1SnowboyDetect" is present

@xuchen
Copy link
Collaborator

xuchen commented May 23, 2017

Were you able to compile the default Android demo under examples/Android/SnowboyAlexaDemo OK? What's your target CPU for Android? Armv7, v8, x86, or MIPS? Could you please list your link directories after you make the swig compile?

Could you do:

cd Android/SnowboyAlexaDemo
tree src

I have output:

src
├── ai
│   └── kitt
│       └── snowboy
│           ├── AppResCopy.java
│           ├── Constants.java
│           ├── Demo.java
│           ├── MsgEnum.java
│           ├── SnowboyDetect.java -> ../../../../../../../swig/Android/java/ai/kitt/snowboy/SnowboyDetect.java
│           ├── audio
│           │   ├── AudioDataReceivedListener.java
│           │   ├── AudioDataSaver.java
│           │   ├── PlaybackThread.java
│           │   └── RecordingThread.java
│           └── snowboyJNI.java -> ../../../../../../../swig/Android/java/ai/kitt/snowboy/snowboyJNI.java
└── main
    └── jniLibs -> ../../../../../swig/Android/jniLibs

You have to make sure all files are linked properly.

@shbkrm
Copy link
Author

shbkrm commented May 23, 2017

I am able to compile and run demo app. It runs perfectly.
The issue is when I try to create a new app and integrate the snowboy code to it.
Below is my output

app/src
├── androidTest
│   └── java
│   └── com
│   └── graspio
│   └── hotwordavs
│   └── ExampleInstrumentedTest.java
├── main
│   ├── AndroidManifest.xml
│   ├── cpp
│   │   └── native-lib.cpp
│   ├── java
│   │   └── com
│   │   └── graspio
│   │   └── hotwordavs
│   │   ├── AppResCopy.java
│   │   ├── Constants.java
│   │   ├── MainActivity.java
│   │   ├── MsgEnum.java
│   │   ├── SnowboyDetect.java -> ../../../../../../../swig/Android/java/ai/kitt/snowboy/SnowboyDetect.java
│   │   ├── audio
│   │   │   ├── AudioDataReceivedListener.java
│   │   │   ├── AudioDataSaver.java
│   │   │   ├── PlaybackThread.java
│   │   │   └── RecordingThread.java
│   │   ├── snowboy.java
│   │   └── snowboyJNI.java -> ../../../../../../../swig/Android/java/ai/kitt/snowboy/snowboyJNI.java
│   ├── jniLibs
│   │   └── armeabi-v7a
│   │   └── libsnowboy-detect-android.so
│   └── res
│   ├── drawable
│   ├── layout
│   │   └── activity_main.xml
│   ├── mipmap-hdpi
│   │   ├── ic_launcher.png
│   │   └── ic_launcher_round.png
│   ├── mipmap-mdpi
│   │   ├── ic_launcher.png
│   │   └── ic_launcher_round.png
│   ├── mipmap-xhdpi
│   │   ├── ic_launcher.png
│   │   └── ic_launcher_round.png
│   ├── mipmap-xxhdpi
│   │   ├── ic_launcher.png
│   │   └── ic_launcher_round.png
│   ├── mipmap-xxxhdpi
│   │   ├── ic_launcher.png
│   │   └── ic_launcher_round.png
│   └── values
│   ├── colors.xml
│   ├── strings.xml
│   └── styles.xml
└── test
└── java
└── com
└── graspio
└── hotwordavs
└── ExampleUnitTest.java

@xuchen
Copy link
Collaborator

xuchen commented May 23, 2017

Maybe this won't solve the issue, but shouldn't you put libsnowboy-detect-android.so under the armeabi-v7a folder?

@shbkrm
Copy link
Author

shbkrm commented May 24, 2017

libsnowboy-detect-android.so is present under armeabi-v7a folder.
The formatting is getting disturbed when copy paste from the terminal.

@xuchen
Copy link
Collaborator

xuchen commented May 24, 2017

It still looks like a linking problem for me. This could come from two sources: either swig is wrong (version 3.0.10 and above is required), or the .so file doesn't get incorporated in Android Studio (even though it packaged it).

@shbkrm
Copy link
Author

shbkrm commented May 24, 2017

Am using latest swig version.
May be .so file is not Incorporated. How can I validate it from my end?

@xuchen
Copy link
Collaborator

xuchen commented May 24, 2017

did it appear in the build/intermediates folder? if yes, then it should be fine...

@shbkrm
Copy link
Author

shbkrm commented May 24, 2017

It is present in build/intermediates/jniLibs/debug/armeabi-v7a
The swig version which I have us 3.0.12

@xuchen
Copy link
Collaborator

xuchen commented May 24, 2017

Good news is that you can compile the Android Alexa demo. I guess the rest is that you'll have to compare 2 projects head by head to dig out what went wrong. I'll ping back once I run into something similar.

@aspratyush
Copy link

@shuaibakram This works fine if one creates soft links to SnowboyDetect.java and snowboyJNI.java as per their project structure and modifies the Makefile accordingly. For e.g., in your case:

  1. soft links should point java/com/graspio/hotwordavs.
SnowboyDetect.java -> ../../../../../../../swig/Android/java/com/graspio/hotwordavs/SnowboyDetect.java
snowboyJNI.java -> ../../../../../../../swig/Android/java/com/graspio/hotwordavs/snowboyJNI.java
jniLibs -> ../../../../../../../swig/Android/jniLibs
  1. Modify Makefile to point to java/com/graspio/hotwordavs and packagename : com.graspio.hotwordavs

@ankitmaisuriya
Copy link

ankitmaisuriya commented Feb 16, 2018

Hi..Please help me out to integrate the Snowboy wakeword demo app with my android application..SnowboyALexaDemo is working very fine..But how to integrate with my current android application to use alexa wakeword..
I am beginner in this..Please help me out.
Any sample application sample is great to understand for me.
Thanks

@lovish888
Copy link

@shuaibakram How can I create soft links. Can you please explain? Thanks.

@lovish888
Copy link

@xuchen I am able to run Android SnowboyAlexaDemo and it works perfectly but how can I integrate it into some other Android project with different package name than 'ai.kitt.snowboy'. Please help. Thanks.

@chenguoguo
Copy link
Collaborator

I submitted a PR for it, hopefully it resolves the issue.

@oth-libs
Copy link

oth-libs commented Feb 8, 2019

For people still facing the same issue, I found the solution, it's not a problem per se, because the files generated are symlinked, which HAVE to be symlinked in your own project as well.

  • don't create your own jniLibs but instead create a symbolic link (on mac):
    ln -s "/path to/Snowboy/swig/Android/jniLibs" "/path to your app/app/src/main/"
  • DON'T COPY the java files, instead create a symbolic link for them as well, same as above.
  • USE ABSOLUTE PATHS AND NOT RELATIVE PATHS otherwise you'll face the error 'Too many levels of symbolic links'

it should now work. the whole idea is to use the files generated and not copy them into your own project.

not sure if I explained this properly so if not please let me know.

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

No branches or pull requests

7 participants