I want to modify globals declared in java SDK via an NDK C function, eg:
public class NDKTest extends Activity
{
static int myglobal = 0;
static { System.loadLibrary("MyCLib"); }
static public native void incrementmyglobal();
....
and in MyCLib:
#include "NDKTest.h"
JNIEXPORT void JNICALL Java_NDKTest_incrementmyglobal
(JNIEnv * env, jobject jObj)
{
/*
this next line is obviously wrong, but illustrates how it would have
been done had it been a purely C program
*/
M.myglobal = M.myglobal + 1;
return;
}
So my question is:
a/ What is the correct syntax of the offending line?
b/ How should the C header file look?
c/ How should the Android.mk file look?
I can compile and run various ‘helloworld’ NDK examples, but I find none that illustrate
how to modify a global declared in java. A supersimple example would be greatly appreciated!
I am programming using Linux command line (ant debug), and simple text editor (emacs).
Im not using Eclipse; have been programming C for years, and am a Java noob.
Destination platform is Android.
Cheers!
The method is static, so its second parameter is a
jclasspointer for the current class, not the current object pointer. Also note that the name of the native method must include the package name:There’s no need for a C header. The Android.mk should look like that of any helloworld example, with LOCAL_SRC_FILES changed to reflect yours.