androidgradleheaderjava-native-interfacejavah

Generate C header file (*.h) for native method implementation JNI in android studio


How to generate C header file (*.h) containing the function prototype for the native method implementation JNI in Android studio while build automatically?

Thank You


Solution

  • Assume you have a project HelloNative

    HelloNative
       |-build/intermediate/classes/debug  (you get this directory upon project build)
       |-app/src/main/jni
            /src/main/java/com/planets/mercury/HelloNativeActivity.java
    

    And you want to generate the header file for HelloNativeActivity.java --> do this

    cd HelloNative
    
    javah -d app/src/main/jni -classpath /Users/john-smith/Android/sdk/platforms/android-19/android.jar:app/build/intermediates/classes/debug com.planets.mercury.HelloNativeActivity
    

    Replace john-smith and android sdk path with what it is on your own machine. For the android jar file. You can use whatever is your choice.

    Eg. android-19, or android-21