juce_CreateApplication for console app in Android

It seems there is a problem making a console app (using IntroJucer) for Android:

The code in juce_android_Windowing.cpp is trying to get the address of juce_CreateApplication, which has not been defined because the 
START_JUCE_APPLICATION macro does not get used when creating a non-GUI app:

JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, launchApp, void, (JNIEnv* env, jobject activity, jstring appFile, jstring appDataDir)) { 
android.initialise (env, activity, appFile, appDataDir);
DBG (SystemStats::getJUCEVersion());
JUCEApplicationBase::createInstance = &juce_CreateApplication;

This obviously causes a link problem...

Any suggestion to fix this ?


As far as I can tell it suffices to add a dummy class that derives from JUCEApplication:

        class MyJuceApp : public juce::JUCEApplication
            MyJuceApp()  {}
            ~MyJuceApp() {}    
            void initialise(const std::string& commandLine) override {}
            void shutdown() override{}
            const std::string getApplicationName() override    {return "myapp";}
            const std::string getApplicationVersion() override{    return "1.0";}

In case you are curious: the real startup code is in the java Android launch activity that IntroJucer generates for you and normally is included in your Android build already.

The java code in there will then call a native JNI C function called launchApp which bootstraps the Juce android system. It's also this function that will instantiate your dummy application class.

the native launchApp function will be using JNI naming convention and will be prefixed with the namespace you have chosen for the Android launch activity in Introjucer, eg:

extern void JNICALL Java_com_your_namespace_YourJuceActivity_launchApp(JNIEnv *env, jobject, jstring publicSourceDir, jstring dataDir);

There are also related native functions named quitApp(), suspendApp() and resumeApp() that can be used to manage app state after creation.



Thank you for your comment, mucoder.

I also have workarounds using dummy GUI app 


However IMHO this should be fixed in Juce framework.

Jules, wouldn't you agree ?

Thanks for letting us know about this!

We'll fix it ASAP.

Thanks Joshua. Will there be a new commit or will it be in JUCE 4 release ?

Upvote this thread. It is still one of the problems we have to deal with when building a static library for Android.

1 Like