NDK問題 : Javah 生成.h檔案

心鑫發表於2013-08-16

cmd 下:

javah -classpath bin/classes -bootclasspath D:\Android\android-sdk\platforms\android-17\android.jar -d jni com.example.hellojni.HelloJni


Eclipse 下:

test.java如下:
package test;

public class test {
	public native String  stringFromJNI();

    /* This is another native method declaration that is *not*
     * implemented by 'hello-jni'. This is simply to show that
     * you can declare as many native methods in your Java code
     * as you want, their implementation is searched in the
     * currently loaded native libraries only the first time
     * you call them.
     *
     * Trying to call this function will result in a
     * java.lang.UnsatisfiedLinkError exception !
     */
    public native String  unimplementedStringFromJNI();

    /* this is used to load the 'hello-jni' library on application
     * startup. The library has already been unpacked into
     * /data/data/com.example.hellojni/lib/libhello-jni.so at
     * installation time by the package manager.
     */
    static {
        System.loadLibrary("hello-jni");
    }
}

點下拉箭頭

普通java專案:設定如下:
-verbose
-d ${project_loc}\jni
-classpath ${project_loc}\bin
${java_type_name}

linux下的修改

/home/proud/KuaiPan/Android/jdk1.6.0_45/bin/javah

${project_loc}/bin

-verbose
-d ${project_loc}/jni
-classpath ${project_loc}/bin
${java_type_name}
android 專案要稍微修改下:

-verbose
-d ${project_loc}\jni
-classpath ${project_loc}\bin\classes
-bootclasspath D:\Android\android-sdk\platforms\android-17\android.jar
${java_type_name}

選中test.java .從下拉選單中選擇新建的tools configure


重新整理 專案 :jni下就會生成。h檔案

注:控制檯列印出亂碼處理:


相關文章