点击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
正在加载信息~
推荐阅读
站点信息
- 文章2303
- 用户1336
- 访客11158832
每日一句
There is always a better way.
总有更好的办法。
总有更好的办法。
IntelliJ IDEA2018~2019.1激活码-注册码
C++实现NAT检测程序
Google Play商城将85款恶意App下架
打开显示interface.png 或者显示interface.swf
【黑苹果安装】——如何在windows下操作EFI分区
Android简单树状实现
Android 8.0应用图标适配
Android Studio3.4.1更新及槽点
C/C++通过WMI和系统API函数获取系统硬件配置信息
DuiLib编译出错:成员声明中不允许限定名
Java中的(耦合)控制反转
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is
#ifdef _DEBUG失效问题
新会员