Import C++ Impulse Library in Android Studio

Question/Issue:
Does anyone could import the C++ Library into an Android Studio native project with java as main language? I’m trying to do that, but I haven’t find the right way to do that. If there is someone who has achieve it, can you help me?
Project ID:

Context/Use case:
I’m trying to build an app with android studio and java as main language. However I have to integrate the Impulse there and I tried with the C++ library.
The project is done with java, because I’m using an Empatica E4 wristband and its SDK is build for java and as an android studio native project. So, I create the Impulse with data from that wristband and the idea is to integrate everything in one app.
If someone can help me, I will be very thankful with you

Hi @djsilverav,

Android dev is not something I’m familiar with. It looks like it’s possible to import a C++ library (Import C++ Impulse Library in Android Studio), but I could not tell you the specifics. My guess would be that you need to modify your C++ SDK library so that it compiles to an object file that you can call from Java and get rid of main.cpp.

I don’t think it matters if you use Java or Kotlin. To call C++ you use FFI.

As a test (without hooking up any calls), I would just include the EdgeImpulse C++ library #include "..\ei_include\edge-impulse-sdk\classifier\ei_run_classifier.h" and see if it will compile.

2 Likes

@djsilverav Did you make any headway on this? I tried using Flutter and failed miserably.

I’m trying yet. I’ve been working on it two weeks and I feel the same as you. But until now I found two things:

  1. I didn’t use Flutter. I tried the method that appears in Android Studio about how to use native library. That way I found that ei_run_classifier.h is the library that show me problems too.
    But the others look fine (apparently).
    2). I exported from the project “my_custom_library” and it has a .tflite file which I could import from Android Studio and maybe It works. (at least, It compiled). So, I wish It works.
    If I get something, I will post it!

Hi! Maybe you’re working to achieve the same objective as me. Here’s my process:

  1. I downloaded the .tflite model from the Dashboard. (Download Custom Deployment)

  2. Then, in Android Studio in Project View, I added a new .tflite model and the software made the process.

  3. Then I Compiled and ran the app.

Looks like it is working.
Right now I’m working on preprocessing part. How to get the DSP analysis and so on to get the input .
Would be really nice if you can import the .tflite file at least and start working again!
C’mon :smiley: I think we can achieve it!

2 Likes

hi,Can you share your experience? I had a hard time developing it

Hi!!
It was really hard and I don’t know if there’s any update, but apparently there’s not.
What I did in that time was to use the Edge-Impulse Web Assembly deployment that they give and I create a WebView object in Android Studio Project.
From there I can run the Edge-Impulse model as if it runs inside a webpage. Then, what I did, it was to connect the model and the app data. It was a mix of javascript, java/kotlin .

Here is the code I used one year ago. I have not done any maintenance, but I hope it’s still working. :slight_smile:

1 Like

Hi, you can compile the edge impulse library with the main.cpp as android static library .so file. download AndroidNativePlugin.unitypackage zip, extract it and import the unitypackage in unity, then you will get a src there which will contain android.mk, application.mk and build_plugin.sh. You can use that to compile edge impulse library. Just add

APP_SHORT_COMMANDS := true
APP_STL := c++_static    # or c++_shared
NDK_TOOLCHAIN_VERSION := clang
APP_CPPFLAGS := -std=c++17 -fexceptions

these commands in application.mk and add all files in the android.mk