How to call JNI through Juce?

Juce has its own JNI_Onload so I cannot/should not write mine. I see no interfaces for getting an JNIEnv*. Is there a way to? I need to do a JNI call on my android app

If you define JUCE_CORE_INCLUDE_JNI_HELPERS before including any JUCE headers, you can call getEnv() to get a pointer to the JNIEnv. There’s also a bunch of helpful methods in that file for dealing with JNI. You’ll obviously need to guard code that calls this with #if JUCE_ANDROID.

I did


on CMake and I’m getting

juce_app/JUCE_SDK/modules/juce_core/juce_core.h:350:35: error: invalid token at start of a preprocessor expression

on this line:

 #include <jni.h>
 #include "native/juce_android_JNIHelpers.h"

Try add_definitions(-DJUCE_CORE_INCLUDE_JNI_HELPERS=1). Macro toggles like this are based on being flags (defined to 1 or 0, where not being defined/being undefined equates to 0 by default). Notice that the the #if condition doesn’t simply check for macros being defined.

this worked. However, I did

#include <juce_core/juce_core.h>

and then


but it does not exist.

On juce_android_Threads.cpp, there is

JNIEnv* getEnv() noexcept

but this is not defined on the juce_android_Threads.h.

I’m not sure I understand the error; can you copy/paste the error(s) you’re getting here?

I see the getEnv function being defined here on the master branch: JUCE/juce_android_JNIHelpers.h at master · juce-framework/JUCE · GitHub