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

后端 未结 3 1436
一个人的身影
一个人的身影 2021-01-14 10:37

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

3条回答
  •  长情又很酷
    2021-01-14 11:38

    I suggest creating an External Tool.

    Go to File->Settings->Tools->External Tools and add a new tool. Fill the dialog form (use "Insert Macro" button )

    • Name: javah
    • Description: Generates the jni header file
    • Program: $JDKPath$\bin\javah
    • Arguments: -d $SourcepathEntry$..\cpp\ -v $FileClass$
    • Working Directory. $SourcepathEntry$

    Leave the other options unmodified.

    Now you can select your class in the Project Explorer, right click and, from the context menu, launch the External Tool->javah.

    The header file will be created in the cpp folder of your project (as suggested for Android Studio Native development) but you will need to browse the folder in order to see it.

    Credits to http://kn-gloryo.github.io/Build_NDK_AndroidStudio_detail/ (modified to be more consistent with more recent SDK and Android Studio) and to Javah: Error: cannot access android.support.v7.app.ActionBarActivity

提交回复
热议问题