Search code examples
androidsdkandroid-ndkjava-native-interface

how to call javah from ADT ide


screenshot

Took the basic example from NDK. Added a function, which doesn't exist yet at native side. Now I am looking a way to call javah from ADT IDE and expect to be generated the function header to my file, near the others:

extern "C" {
JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_init(JNIEnv * env, jobject obj, jint width, jint height);
JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_step(JNIEnv * env, jobject obj);
}
;

JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_init(JNIEnv * env, jobject obj, jint width, jint height) {
    setupGraphics(width, height);
}

JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_step(JNIEnv * env, jobject obj) {
    renderFrame();
}

at least to extern "C" section.

Is there any way to do it? What is the best practice?

  • generate with a tool to gl2jni.cpp than Cut and Paste to gl_code.cpp, to keep the existing code in gl_code.cpp ? - or do I miss a basic environment setup?

Do I need to write some build configuration? - like always generate those headers to an empty file?

Is there any plugin which can do it from IDE?


Solution

  • Since you are using the Eclipse IDE, running javah can be easily automated to put header files anywhere you want them whenever your Java code is compiled. See my answer on SO here.