点击AS的File->Settings或者快捷键Ctrl+Alt+S,打开设置界面,如下图
参数
-d $ModuleFileDir$\src\main\cpp\ -bootclasspath $ModuleSdkPath$\platforms\android-26\android.jar -classpath $ModuleFileDir$\build\intermediates\classes\debug com.app.jni.SdkNative
创建完之后,点OK保存。最后在菜单栏Tools->External Tools->Javah就会自动生成你要的头文件了。
自动生成method和signature工具类
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; /** * JNI动态注册方法生成器 * 这是一个J2SE工具类 */ public class JniMethodsGenerator { static List<Method> list; public static void main(String[] args) { String path = ".\\src\\main\\cpp\\com_jni_Native.h";//javah生成的头文件路径 try { list = new ArrayList<>(); FileInputStream in = new FileInputStream(new File(path)); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = reader.readLine(); Method method = null; while (line != null) { if (line.contains("Method:")) { method = new Method(); method.method = line.substring(line.lastIndexOf(":") + 1).trim(); } else if (line.contains("Signature:")) { method.signature = line.substring(line.lastIndexOf(":") + 1).trim(); list.add(method); reader.readLine();// line = reader.readLine();//JNIEXPORT void JNICALL Java_com_jni_Fjsmthlib_debug int l = "JNIEXPORT ".length(); method.type = line.substring(l, line.indexOf(" ", l + 1)).trim(); line = reader.readLine(); method.params = line; } line = reader.readLine(); } reader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } List<Method> methods = new ArrayList<>(); methods.addAll(list); while (list.size() > 0) { Method method = list.remove(0); String jni = String.format("{\"%s\", \"%s\", (void *) jni_%s},", method.method, method.signature, method.method); System.out.println(jni); } while (methods.size() > 0) { Method method = methods.remove(0); System.out.println(String.format("extern %s jni_%s %s", method.type, method.method, method.params.trim())); } } static class Method { String type; String method; String signature; String params; } }
收藏的用户(0) X
正在加载信息~
推荐阅读
站点信息
- 文章2281
- 用户1336
- 访客9580219
每日一句
Great hopes make great men.
伟大的理想造就伟大的人。
伟大的理想造就伟大的人。
- 使用MyBatis_Generator生成Dto、Dao、Mapping
- 解决vue动态生成el-table-column按钮点击事件
- Android Studio创建进程通信简单例子
- 简单利用Clover四叶草安装U盘安装黑苹果
- 为什么数据结构和算法很重要?
- 仙剑奇侠传3d回合-PC端辅助
- 谷歌Pixel正在开始起飞?
- 新手安装黑苹果OS X 10.11教程
- 通过HOOK技术破解Assembly-CSharp.dll
- How to Ungroup Icons on Windows 11 Taskbar With a Registry Hack (and 2 More Ways)
- NDK cmake报错:asm/types.h not found
- 【源码】Pixel Dungeon
- thinkpad t470p装黑苹果系统10.13.2
新会员