14. ③ C / C++ 用ヘッダファイル生成
jni_test_helloWorldJNI_HelloWorld.h
• javah コマンドで生成
– クラスファイルからヘッダファイルを生成
– jni_test_helloWorldJNI_HelloWorld.h
– C / C++ コードでインクルード
• Eclipse からやる方法は知らない(汗)
$ javah jni_test.helloWorldJNI.HelloWorld
15. 生成されたヘッダファイル
jni_test_helloWorldJNI_HelloWorld.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class jni_test_helloWorldJNI_HelloWorld */
#ifndef _Included_jni_test_helloWorldJNI_HelloWorld
#define _Included_jni_test_helloWorldJNI_HelloWorld
#ifdef __cplusplus
extern quot;Cquot; {
#endif
/*
* Class: jni_test_helloWorldJNI_HelloWorld
* Method: get
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_jni_1test_helloWorldJNI_HelloWorld_get
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
19. HelloWorld のテストコード
HelloWorldJNI.java
package jni_test.helloWorldJNI;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloWorldJNI extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
tv.setText(new HelloWorld().get());
setContentView(tv);
}
}