JNI学习笔记(javah命令使用)

一.javah命令使用

  • jdk1.6在工程的classes目录下执行,生成头文件
  • > javah com.study.resultfromc.MainActivity
    
  • jdk1.7在工程的src目录下执行,生成头文件

    > javah com.study.resultfromc.MainActivity
    

二.不带包名生成的结果

这里写图片描述

java代码

public class Test
{   
    public native int result_from_c(int a,int b);
    public native String hello();
}

生产的C代码

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Test */

#ifndef _Included_Test
#define _Included_Test
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     Test
 * Method:    result_from_c
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_Test_result_1from_1c
  (JNIEnv *, jobject, jint, jint);

/*
 * Class:     Test
 * Method:    hello
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_Test_hello
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

带包名生成的结果

这里写图片描述

java代码

package com.study.test;

public class Test
{
    public native int result_from_c(int a,int b);
    public native String hello();
}

生产的C代码

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_study_test_Test */

#ifndef _Included_com_study_test_Test
#define _Included_com_study_test_Test
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_study_test_Test
 * Method:    result_from_c
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_com_study_test_Test_result_1from_1c
  (JNIEnv *, jobject, jint, jint);

/*
 * Class:     com_study_test_Test
 * Method:    hello
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_com_study_test_Test_hello
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

猜你喜欢

转载自blog.csdn.net/jiang_xinxing/article/details/79359090