Shared libraries on Android

Hi, has anyone implemented a shared library on android?

Edit: I’ve not got the shared library installed and loading.

However, when making calls into the library I get an assertion in

JNIEnv* getEnv() noexcept

// You did not call Thread::initialiseJUCE which must be called at least once in your apk
    // before using any JUCE APIs. The Projucer will automatically generate java code
    // which will invoke Thread::initialiseJUCE for you.

This comes from a call to juce::MessageManager::getInstance() which is the first thing I do when calling into the shared library to init the message manager for the library (needed on all platforms).

So, the question is what do we need to do in order to setup the JNIEnv when calling into a shared library.

The app loading the shared library will not be a JUCE app.

@t0m - who is the resident Android expert on the team these days? thx

Thx

For the purposes of creating a test harness to load the library, I’ve managed to get hold of the jni env by calling getEnv() in juce_JNIHelpers_android.h which is what I need.

However, calling getAppContext() returns a global ref id rather than the original pointer to the context which is what I need - is there some way of getting back from the global ref to the pointer passed in at app startup?

thx

So, I’ve been playing with this and hacked together a version JUCE so that I can get the original context that is passed into Thread::initialiseJUCE() when the app is started - I’m now passing the jni env and this context over to my shared library so I can call Thread::initialiseJUCE() inside the library when it is loaded.

However, this calls JuceActivityWatcher::getInstance() which ultimately makes a call to getAppContext() which calls

if (env->IsInstanceOf (context, AndroidApplication) != 0)

which fails as AndroidApplication is evaluating to null.

So, I’ve tried making a call to

juce::JNIClassBase::initialiseAllClasses( (JNIEnv *)p_jni_env, (jobject)p_context );

before the call to Thread::initialiseJUCE() as happens in juce_JavainitialiseJUCE(), but then this fails in a call to getAndroidSDKVersion which calls getEnv() which fails as no VM has been set yet.

I then hacked together a call to juce::JNI_OnLoad( (JavaVM *)p_vm, nullptr ) by passing the vm over into the library and this then fails in obscure code beneath it.

I feel I’ve gone down the rabbit hole here as android shared libraries are officially supported so there must be a simple way of initialising juce in one?

Thx for any pointers on this.