点击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
正在加载信息~
推荐阅读
站点信息
- 文章2312
- 用户1336
- 访客11622688
每日一句
Compliment yourself daily.
每天夸自己一句。
每天夸自己一句。
How to Ungroup Icons on Windows 11 Taskbar With a Registry Hack (and 2 More Ways)
反编译修改class文件变量
如何在大学成为一名优秀的程序员?
VMware NAT端口映射外网访问虚拟机linux
ubuntu下提取DSDT SSDT
使用HTML和CSS设计磨砂玻璃效果
解决android studio 4.4使用javah失败
vscode使用eslint自动代码格式化
c++浮点运算能力附安卓版
【源码】两种仪表盘
P2P中NAT之间的打洞可能性
jQuery的load方法Cannot read property 'indexOf' of undefined
【开源Roguelike游戏】素地牢源码
新会员