AS中JNI的使用
在
gradle中配置ndk { moduleName "JniTest" ldLibs "log", "z", "m" abiFilters "armeabi", "armeabi-v7a", "x86" }gradle.properties中android.useDeprecatedNdk = truejava类中定义
Native方法public class Jni { static { System.loadLibrary("JniTest"); } public static native String helloWorld(); }src/java目录下打开命令行
javah -jni -encoding UTF-8 xxx.xxx.Jni在生成的
JniTest.c中#include <jni.h> #ifndef _Included_com_king_doubleicon_FlipperFragment #define _Included_com_king_doubleicon_FlipperFragment #ifdef __cplusplus extern "C" { #endif JNIEXPORT jstring JNICALL Java_com_king_doubleicon_FlipperFragment_helloWorld (JNIEnv *env, jclass object){ return (*env)->NewStringUTF(env,"JNI : helloWorld"); } #ifdef __cplusplus } #endif #endif- 运行即可编译.so文件,在
build/intermediates/ndk目录下可以找到对应文件:
607

被折叠的 条评论
为什么被折叠?



