Closed rtumelty closed 5 years ago
I changed the title of the issue to "Expose JNI method signatures for Android" which I believe is what we need eventually. I don't want to provide the signature of JNI methods in an issue because if we change the API in the future this will break your code with you knowing.
Exposing more APIs on Android is a feature candidate for v1.5. I don't have timing estimates at the moment for this feature or v1.5 release. There are a few things I can think off.
1- What is the standard way of integrating third-party native libraries into Unity on Android? I would think there is a standard way to use Java API? No? I could wrong. This is the easiest solution. My preferred solution. 2- Use an RPi shared object and build on top of that. This is tricky as RPi is linked to a different libc but might work. You can build your own JNI on top of C API. 3- If this is a commercial application contact Picovocie directly and we might be able to allocate some resources to get this done sooner or provide the JNI under NDA ...
That's a good reason!
Unity allows you to interact with Java libraries as well as C/C+, so yes, a Java wrapper is an option. Calling a Java wrapper to a JNI wrapper to a C library is very messy though, I'd much prefer to wait until I can interact directly with Porcupine in v1.5, as described in the other issue I linked above, bypassing the JNI.
For the time being, I've done an iOS implementation for the proof of concept, and will be pausing development on Android.
Thanks
I've had a chance to look back into this issue. Taking another look at it I think this approach you are trying to take won't work even if we expose the JNI interface. Why? Because each JNI method starts with JNIEnv *env, jobject thiz
which is used by Java. You can't possibly provide the correct parameters. The correct way would be to expose actual library API in the .so which is being tracked here https://github.com/Picovoice/Porcupine/issues/73
Closing the issue for now. Reopen if the above doesn't make sense.
Hi, I've been trying to get Porcupine working from Unity and C# for Android devices. Using the System.Runtime.InteropServices library (for interacting with C and C++ code), I can load the Porcupine library, and was able to determine the JNI function names. I can successfully call functions with no parameters (getFrameLength, getSampleRate). However when I try to call the init function, Porcupine causes a segmentation fault.
I have tried multiple different parameter and return types, and methods of marshalling the types between C# and the shared library, with no success. It's mostly guess work however, as the library contains no debug symbols and I don't know how the functions are defined in the JNI - it is undocumented as far as I can see. I have also (in desperation) tried using the arm builds for linux and raspberry pi, but these seem to be incompatible with armv7 and arm64.
This is a major blocking issue on a product that otherwise Porcupine would be perfect for. There are a couple of things that you might be able to provide that could help:
If you can help with any of these, I'd be very grateful! I realise that this is not the intended use of the JNI wrapper, however short of writing a Java wrapper for the JNI wrapper and calling that, I'm stuck for solutions. I've included a stack trace and some sample C# below. Thanks!
Looking forward to your response, Ronan
Expected behavior
Call Porcupine init from Unity using System.Runtime.InteropServices. Porcupine initialises.
Actual behavior
Segmentation fault when init is called. Stack trace below.
Sample code