2008年5月27日 星期二

android JNI debug method

這是一篇小小的心得, 當時我正在寫 android的 jni 準備放在 /system/lib 裡面讓 java的 application 呼叫.

但是苦於沒有辦法知道 android's java application 是否呼叫到了 jni 所以一直很苦惱,
後來靈機一動, 直覺的認為可能是 權限的問題所以想到的解法. 請各位不要笑我 因為我剛開始接觸 linux也不超過一年.

  • adb shell
  • chmod 777 /dev/pts/0

in c code write below this to generate debug message

  • char message[] = "hello android jni interface.";
  • int tty = open ("/dev/pts/0", O_RDWR);
  • write ( tty, message, sizeof(message) );
補充一下 /dev/pts/x 是在使用模擬器的時候使用 adb shell 會自動建立的 device node , 第一次使用時編號為0 第二次為1 以此類推.

所以這個 debug 方法只是用在 emulator 上面.
另外前面可以加上 access("/dev/pts/0", R_OK | W_OK | X_OK ) 作判斷看看檔案是否存在

沒有留言: