标签:
在Android Studio下有很多方法:
在Android Studio中,可以打开命令终端并将目录切换到app/build/intermediates/classes/debug(编译生成的.class文件的存放路径)下:
终端上的命令:
cd app/build/intermediates/classes/debug
点击回车,再输入要>javah -jni 该类所在的包+该类名称,示例如下:
javah -jni com.x.mp4player.TestNdk
生成的.h文件代码:
/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class com_x_mp4player_TestNdk */ #ifndef _Included_com_x_mp4player_TestNdk #define _Included_com_x_mp4player_TestNdk #ifdef __cplusplus extern "C" { #endif /* * Class: com_x_mp4player_TestNdk * Method: getStringFromNative * Signature: ()I */ JNIEXPORT jint JNICALL Java_com_x_mp4player_TestNdk_getStringFromNative (JNIEnv *, jclass); #ifdef __cplusplus } #endif #endif
编写的.cpp文件代码:
#include <jni.h> #include <com_x_mp4player_TestNdk.h> JNIEXPORT jint JNICALL Java_com_x_mp4player_TestNdk_getStringFromNative (JNIEnv *env, jclass cls) { return 1; }
static { System.loadLibrary("MyJni");//导入生成的链接库文件 }
标签:
原文地址:http://www.cnblogs.com/xiezie/p/5929996.html