How to change the Android NDK jni calls dynamically?

| | August 10, 2015

Some people are using NativeActivity for working with Android projects exclusively in C++, but this also carries some disadvantages, so I, like many others, decided that I’d use instead a Java glue code; just a single Java file wrapping all things I need from C++, where pretty much everything runs.

With this said, as far as I know, using this Java code forces me to implement the native function calls in Java, where the Java calls a function that is actually called within the C++ part of the project, with the JNI.

In C++, the native function being called has a prototype like this:

JNIEXPORT void Java_com_package_name_nativeTouchDown( JNIEnv*  env, jobject thiz, jfloat x, jfloat y );

My problem is that I started working with scripts exclusively and would like to find a way to not having to recompile the C++ code anymore. So when I want to make a new project, I just copy-paste my C++ compiled code and change the scripts and be allowed to change the package name of the app without any recompilation.

Is this possible somehow? At the point I am at, I simply have to recompile my C++ to conform to a new package name (the one in the format com.company.game). Can’t I make C++ fully abstracted from this package name or change it dynamically?

One Response to “How to change the Android NDK jni calls dynamically?”

  1. Your package name doesn’t need to match the package where you put your classes.

    When you write your AndroidManifest.xml you specify both the package for the game and the path to your activity. So use something like com.company.engine for your activity and your C++ and just create a new package name for the game.

Leave a Reply