Android: Native Juce function not called


#1

I have a Juce application which is used for windowing, rendering and HTTP requests around our own library. Everything is working as it should on Windows and now I have started setting it up for Android. The code compiles for Android, the APK is installed and the application can be started, but the native functions are never called, hence this question.

Info:

  1. The code is built using cmake since all our code is built using cmake.

  2. The compiled Juce code (libmQATool.so) is linked to our internal library (libFoo.so), so we have two shared objects in the APK.

  3. The lifecycle functions in Android (onCreate(), onResume(), etc.) are called, but the native calls therein never reaches the C++ code.

  4. Running nm libmQATool.so reveals that the functions are in the shared object with the proper JNI names (as far as I can tell):

    00301320 T Java_com_mycompany_mqatool_mQATool_launchApp
    00301440 T Java_com_mycompany_mqatool_mQATool_quitApp
    00301410 T Java_com_mycompany_mqatool_mQATool_resumeApp
    0031c140 T Java_com_mycompany_mqatool_mQATool_setScreenSize
    003013e0 T Java_com_mycompany_mqatool_mQATool_suspendApp

  5. I use the Activity class created by Introjucer as main class. By putting Log.i() statements in the lifecycle callbacks, I can see that these functions are called by using adb logcat. These functions call directly to the native functions (that are not called).

  6. Inside the JNI function definitions I have tried printing stuff in various ways, but nothing is ever printed by logcat. For example:

    JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, launchApp, void, (JNIEnv* env, jobject activity, jstring appFile, jstring appDataDir))
    {
    fprintf(stderr, “%s\n”, PRETTY_FUNCTION);
    juce::FileLogger::outputDebugString(“I am never called :/”);
    DBG(“I am never called :/”);
    android.initialise(env, activity, appFile, appDataDir);

    }

  7. The JUCE version I currently use is 3.2.0. I should probably update the libraries, but I don’t think that this error is related.

  8. There is no Native method not found error as one would expect if the function is not found/does not exist.

Can anyone see what I am missing or give me any hints for how to investigate this further? Any comments and hints are highly appreciated! This might just be some silly error.

mQATool.java (created by Introjucer):

public class mQATool   extends Activity
{
    //==============================================================================
    static
    {
        System.loadLibrary ("mQATool"); // This is loaded without errors, it includes the Juce code.
    }

    @Override
    public void onCreate (Bundle savedInstanceState)
    {
        super.onCreate (savedInstanceState);
        Log.i("ThisIsAlwaysCalled", "onCreate()!");

        viewHolder = new ViewHolder (this);
        setContentView (viewHolder);

        setVolumeControlStream (AudioManager.STREAM_MUSIC);
    }

    @Override
    protected void onDestroy()
    {
        quitApp();
        super.onDestroy();
        Log.i("ThisIsAlwaysCalled", "onDestroy()!");

        clearDataCache();
    }

    @Override
    protected void onPause()
    {
        if (viewHolder != null)
            viewHolder.onPause();
        Log.i("ThisIsAlwaysCalled", "onPause()!");

        suspendApp();
        super.onPause();
    }

    @Override
    protected void onResume()
    {
        super.onResume();
        Log.i("ThisIsAlwaysCalled", "onResume()!");

        if (viewHolder != null)
            viewHolder.onResume();

        resumeApp();
    }

    @Override
    public void onConfigurationChanged (Configuration cfg)
    {
        super.onConfigurationChanged (cfg);
        setContentView (viewHolder);
    }

    private void callAppLauncher()
    {
        Log.i("ThisIsAlwaysCalled", "callAppLauncher()!");
        launchApp (getApplicationInfo().publicSourceDir,
                   getApplicationInfo().dataDir);
    }

    //==============================================================================
    private native void launchApp (String appFile, String appDataDir);
    private native void quitApp();
    private native void suspendApp();
    private native void resumeApp();
    private native void setScreenSize (int screenWidth, int screenHeight, int dpi);
    ...

Not sure which other files can be of interest. Let me know if you want to see more files. All cmake files, AndroidManifest.xml and the likes are very basic.


#2

Ok guys. Always remember to use the latest compiled shared object.

Sigh.