標籤:android style blog http color io 使用 ar java
查看程式執行過程中所列印的log資訊,用於輔助調試排除代碼錯誤。
一、採用NDK安裝包下Samples/hello-jni工程做實驗
1)修改jni/hello-jni.c檔案
#include <android/log.h>__android_log_print(ANDROID_LOG_INFO, "HelloJniTag", "The value is %d", 1000);
2)修改jni/Android.mk檔案
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := hello-jniLOCAL_SRC_FILES := hello-jni.cLOCAL_LDLIBS := -lloginclude $(BUILD_SHARED_LIBRARY)
3)使用eclipse開啟當前項目,運行測試,Debug As...
4)在eclipse的logcat監控視窗觀察日誌資訊
二、NDK開發的一般步驟
1)啟動eclipse建立android application工程;
2)建立activity應用類(可仿照HelloJni中HelloJni.java);
3)在activity應用類中加入native函式宣告及調用;
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("HelloJni1"); }
4)在命令列模式下使用javah產生jni標頭檔,並建立c或c++實現檔案;
javah -jni -d jni -cp bin/classes:Android-20.jar com.example.hellojni.HelloJni
5)在jni目錄下建立Android.mk、Application.mk編輯指令碼
#Android.mkLOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := hello-jniLOCAL_SRC_FILES := hello-jni.cLOCAL_LDLIBS := -lloginclude $(BUILD_SHARED_LIBRARY)
#Application.mkAPP_ABI := all
6)修改AndroidManifest.xml檔案,仿照HelloJni添加工程啟動的Activity配置項。
7)eclipse啟動Debug As...進行調試。
Android NDK調試方式之一: adb logcat