DLL/Shared Library Project

I’m trying to create a project that has builds for both a windows DLL and an Android AAR

The project has a common code base using JUCE

but I can’t figure out a way to have single projucer for these

currently, I have them in seperate projucer projects (a windows DLL projucer and an android App projucer that I’ve hacked into a Shared Libray solution)

But this isn’t easy for code management.

Does anyone have any suggestions how I can manage to get them into a single solution?

The Projucer “Dynamic library” template doesn’t work as expected on Android? (I only have experience about that on Windows and macOs.)

I have JUCE Dynamic Library projects working on Android. They are architecture-specific .so files, not AAR.

I also have an example JUCE Dynamic Library project that targets Android, Windows and Mac/iOS which I can send you if you wish.

that would be great Adam, muchly appreciated

Thanks for sharing your project. It starting to make sense!

One of the reasons I couldn’t combine the two libraries into a single projucer is that my hacky attempts to make an android library were to take a working GUI application and change the application to a library, e.g. apply plugin: 'com.android.library', and comment out //applicationId "com.acme.myapp" while, in my host, setting the object to com.roli.juce.JuceApp and calling the OnCreate function on the currentActivity of the host.

Now, when I change it to Dynamic Library in Projucer, the build doesn’t include com.roli.juce.JuceApp, which obviously makes sense becaue its no longer a GUI App.

I tried then to create my own version of com.acme.JuceApp (duplicating the code, with changes to package) – this works when my libray is hacked from the GUI App approach – but when I’m building a Dynamic Library this always results in assert error I/JUCE: JUCE Assertion failure in juce_android_Threads.cpp:321 which comes from the getAppContext() method

    // 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.

Any ideas what am I missing in my Dynamic Library that would solve this?

I just published the project on GitHub: https://github.com/adamski/audioengine-demo

It sounds like you might be missing the call to initialise JUCE. A handy way to do this is to use the ScopedJuceInitialiser_GUI. See https://github.com/adamski/audioengine-demo/blob/dfc110ea349c86610f55823005889dcf615f38a8/DemoAudioEngine/Source/AndroidBindings.cpp#L29

Also you do not need (and should not have) a Custom Activity defined in Projucer, if creating a Dynamic Library. Your main Android app will contain the Activities.

1 Like

Yes, my main android app has the activity (probably not too clear above)

this is being used in a Unity3D App

AndroidJavaObject bridge = new AndroidJavaObject("com.acme.JuceApp");
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject act = jc.GetStatic<AndroidJavaObject>("currentActivity");
act.Call("runOnUiThread", new AndroidJavaRunnable(() =>

It seems so. I think one of my ongoing confusions is the same code (my code) works when I build a GUI App (that is hacked into a library) but not when I build a Library. So is projucer adding some code that does the initialisation in the App form that is missing when in the Lib?

If so, and it is the ScopedJuceInitialiser_GUI. where should I include this?

You would include the ScopedJuceInitialiser_GUI instance in a class that will remain alive for the lifetime of your app, or at least the JUCE part of it anyway. I would recommend following the pattern in the linked project.