简体   繁体   English

在jni文件夹android中生成文件的最简单方法

[英]easiest way to generate files in jni folder android

I am wondered if there is a way to generate the .h files in the jni folder easier than command like this 我想知道是否有一种方法来生成jni文件夹中的.h文件比这样的命令更容易

javah -jni -classpath bin/classes/ -d jni/ com.example.test_ndk.FibLib

I mean I want to automate this step so I have to write only 我的意思是我想自动化这一步,所以我只能写

public native static long fibNR(long n);

and then eclipse will generate the .h files in jni folder for me 然后eclipse将为我生成jni文件夹中的.h文件

How can I do that ? 我怎样才能做到这一点 ?

Option 1: 选项1:

If it makes a difference, you do not have to include the -jni option. 如果它有所不同,则不必包含-jni选项。 It's the default option for javah . 这是javah的默认选项。

javah -classpath bin/classes/ -d jni/ com.example.test_ndk.FibLib

Option 2: 选项2:

The other alternative would be to create the header file yourself, but this is not an easier option. 另一种方法是自己创建头文件,但这不是一个更容易的选择。 Your header would look like this (there's a 1 before ndk in test_1ndk because you used an _ character in the package name. If we don't put it, the caller will look for a folder called ndk inside a folder called test , therefore, I wouldn't recommend using test_ndk as your package name. Instead use testNdk or something with the underscore): 你的标题看起来像这样(在test_1ndk ndk之前有一个1,因为你在包名中使用了_字符。如果我们不放它,调用者会在名为test的文件夹中查找名为ndk的文件夹,因此,我不建议使用test_ndk作为您的包名。而是使用testNdk或带下划线的东西):

#include <jni.h>
JNIEXPORT jlong JNICALL Java_com_example_test_1ndk_FibLib(JNIEnv*, jclass, jlong);
// use jobject instead of jclass if your method is non-static

And the general format is: 一般格式是:

JNIEXPORT [returnType] JNICALL Java_[package name with folders separated by _]_[class name]_[method name] (JNIEnv*, jclass, jtype arguments);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM