Invoking the native library

As we saw in the application structure, the signal, truncated, and convolved data all come from the native C++ library. To get data from the C++ library, you must create a binding between the Java method and the native library function. In this section of the guide, we show you how to do this using the generateSignal method.

Declare the method in the Java class with an extra native modifier:

public native byte[] generateSignal();

Put the cursor within the method name, in this example the name is generateSignal, to automatically generate a binding.

Click Alt+Enter to display the context help. Choose the Create JNI function for… option as shown in the following screenshot:

Truncation 2

Android Studio supplements the native-lib.cpp with the empty declaration of the C exportable function that looks like this:

extern "C"
JNIEXPORT jbyteArray JNICALL
Java_com_example_neonintrinsicssamples_MainActivity_generateSignal(
    JNIEnv *env, jobject /* this */) {
}
Previous Next