1.定义JAVA类,内部具有native关键字函数
如:
package com.jni.jnitest;
public class Algorithm {
static {
System.loadLibrary("Algorithm");
}
public native int add(int a,int b);
public native int subtract(int a,int b);
}
2.用javah命令生成.h文件。
cd 到工程目录下,执行javah -classpath bin -d jni com.jni.jnitest.Algorithm 生成
bin目录同时生成com.jni.jnitest.Algorithm.h文件
如:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_jni_jnitest_Algorithm */
#ifndef _Included_com_jni_jnitest_Algorithm
#define _Included_com_jni_jnitest_Algorithm
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_jni_jnitest_Algorithm
如:
package com.jni.jnitest;
public class Algorithm {
static {
System.loadLibrary("Algorithm");
}
public native int add(int a,int b);
public native int subtract(int a,int b);
}
2.用javah命令生成.h文件。
cd 到工程目录下,执行javah -classpath bin -d jni com.jni.jnitest.Algorithm 生成
bin目录同时生成com.jni.jnitest.Algorithm.h文件
如:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_jni_jnitest_Algorithm */
#ifndef _Included_com_jni_jnitest_Algorithm
#define _Included_com_jni_jnitest_Algorithm
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_jni_jnitest_Algorithm