Build juce shared library for Android, stuck

Using JUCE inside a native shared library on Android depends on how your shared library is used by your Android app. There are three common options:

  1. Your android app is a JUCE app. Then you really shouldn’t need to do anything. Let the Projucer create your android project and simply add the shared libraries you want to use to the Projucer. Once your android project is created, you could choose to continue in Android Studio, for example.

  2. You android app is a native kotlin/java app and directly loads your native shared library which uses JUCE. For this, you will probably have created your native android app with Android Studio. For the shared library, create a shared library JUCE project with the Projucer (or cmake). Make sure that your JUCE project compiles fine. Then your native android app will need to load the shared library from Java/Kotlin via System.loadLibrary. After this you will need to call com.roli.juce.Java.initialiseJUCE() from Java on every thread that will call into your native shared library.

  3. Your android app is a native kotlin/java app which loads some third-party shared library which in turn loads your shared library which uses JUCE. Here, in addition to calling com.roli.juce.Java.initialiseJUCE() on every thread, you first need to call JNI_OnLoad (which is defined in JUCE) before calling anything else (including com.roli.juce.Java.initialiseJUCE()). This is because Java/Kotlin’s System.loadLibrary normally does this automatically (as in 2) but here, your shared library isn’t being loaded by Java/Kotlin but by another native library.

See this thread for more information:

1 Like