jni javah
如何通过javah生成jni头文件
1.javah的使用说明:

-classpath 给出包含native接口的java类的.class文件路径
-d / –o 指定生成的头文件的,-d只给出文件不指定文件名, -o直接指定文件的路径给名字
-jni 给出包含native接口的java类的包名和类名
2.例子
2.1 java文件代码
1 package com.eostek.serialport;
2
3 import java.io.FileDescriptor;
4
5 public class SerialPort {
6 static {
7 System.loadLibrary("serialport_jni");
8 }
9
10 public static native FileDescriptor open(String path, int baudrate);
11
12 public static native void close(FileDescriptor fd);
13 }2.2 在终端先编译好java文件,然后通过javah生成jni头文件
例如:(路径根据实际项目修改)
javah -classpath ../../../out/target/common/obj/APPS/SerialPort_intermediates/classes/ -o jni/SerialPort.h -jni com.eostek.serialport.SerialPort
执行命令后 在当前目录的jni子目录生成一个SerialPort.h文件,文件内容如下:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>/* Header for class com_eostek_serialport_SerialPort */
#ifndef _Included_com_eostek_serialport_SerialPort
#define _Included_com_eostek_serialport_SerialPort#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_eostek_serialport_SerialPort
* Method: open
* Signature: (Ljava/lang/String;I)Ljava/io/FileDescriptor;
*/
JNIEXPORT jobject JNICALL Java_com_eostek_serialport_SerialPort_open
(JNIEnv *, jclass, jstring, jint);
/*
* Class: com_eostek_serialport_SerialPort* Method: close
* Signature: (Ljava/io/FileDescriptor;)V
*/
JNIEXPORT void JNICALL Java_com_eostek_serialport_SerialPort_close
(JNIEnv *, jclass, jobject);
#ifdef __cplusplus
}#endif
#endif
jni javah的更多相关文章
- Android Studio JNI javah遇到的问题
好久没写博客了.持之以恒的勋章也被收回了.以后要好好坚持.. 最近在学习jni,但是遇到了一点麻烦的问题.好在终于解决了,便记下来解决一下. 其他入门的jni文章有很多,这里便不在累赘,直接上我遇到的 ...
- jni.h头文件详解二
作者:左少华 博客:http://blog.csdn.net/shaohuazuo/article/details/42932813 转载请注明出处:http://blog.csdn.net/shao ...
- 【转】 jni.h头文件详解(二)
原文网址:http://blog.csdn.net/shaohuazuo/article/details/42932813 作者:左少华 博客:http://blog.csdn.net/shaohua ...
- 解决javah生成c头文件时找不到android类库的问题
问题描述: cmd下面进入工程的bin/classes下面,执行 javah xxx.xxx.A 生成头文件, 一般来说都是可以成功执行的,但是如果xxx.xxx.A类里面引用了android类库里面 ...
- java native方法及JNI实例 (转)
转自:http://blog.csdn.net/xw13106209/article/details/6989415 1.参考文献: http://blog.csdn.net/youjianbo_ha ...
- java native方法与JNI实现
native方法定义: 简单地讲,一个Native Method就是一个java调用非java代码的接口.一个Native Method是这样一个java的方法:该方法的实现由非java语言实现,比如 ...
- ok6410 android driver(7)
This article talk about how to test device driver on JNI. There are two ways to test the device driv ...
- ndk-gdb 对java/native code联合调试(升级版)
之前写过一篇 关于android native 开发,调试的文章(http://www.cnblogs.com/yaozhongxiao/archive/2012/03/13/2393959.html ...
- java初探native
最近碰见一个java中一个native关键字,不知道是干什么的,如下: public native String FileName(String strURL); static{ ...
随机推荐
- 01背包问题(回溯法)python实现
接上一篇,相同的01背包问题,上一篇採用动态规划的方法,如今用回溯法解决. 回溯法採用深度优先策略搜索问题的解.不多说.代码例如以下: bestV=0 curW=0 curV=0 bestx=None ...
- 网页爬虫框架jsoup介绍
序言:在不知道jsoup框架前,因为项目需求.须要定时抓取其它站点上的内容.便想到用HttpClient方式获取指定站点的内容.这样的方法比較笨,就是通过url请求指定站点.依据指定站点返回文本解析. ...
- c2
#include <stdio.h> int main() { // 整型常量 ; // 实型常量(小数) // 单精度float / 双精度double // 注意: 默认情况下编写的小 ...
- PHP中出现Notice: Undefined index的三种解决办法
前一段做的一个PHP程序在服务器运行正常,被别人拿到本机测试的时候总是出现“Notice: Undefined index:”这样的警告,这只是一个因为PHP版本不同而产生的警告(NOTICE或者WA ...
- 匹配替换指定文本为html标签
最近看了一道前端面试题,是关于正则的,用尽可能低复杂度的函数,匹配替换指定文本为html标签,题目是这样的: 特定语法匹配替换 说明:匹配字符串中形如 =g文字文字= 的语法,并将相应部分转化为对应的 ...
- 19. Remove Nth Node From End of List[M]删除链表的倒数第N个节点
题目 Given a linked list, remove the n-th node from the end of list and return its head. *Example: Giv ...
- android编译ffmpeg+x264
下载最新版的x264ftp://ftp.videolan.org/pub/videolan/x264/snapshots/1.解压到指定的目录2.切换当前目录为该目录3.创建一个shell脚本buil ...
- 实现SSRS订阅
以前曾经搞过SSRS的订阅,使用的是公司的邮件服务器,最近QQ群中有妹子问到同样的问题,虽然没能帮人家搞定,下面写出自己参考的资料,以供各位参考: 一.订阅前准备工作(转载自http://blog.s ...
- (转载)Android快速开发偷懒必备,一句话搞定所有ViewGroup的Adapter . 支持自定义ViewGroup
[置顶] [Android]快速开发偷懒必备,一句话搞定所有ViewGroup的Adapter . 支持自定义ViewGroup 标签: androidAdapter快速开发0耦合 2016-12-1 ...
- Failed reading log event, reconnecting to retry
数据库版本:5.6.16 系统:CentOS 6.5 搭建数据库从库报错:160411 14:30:39 [Note] Slave I/O thread: Failed reading log eve ...
