Android NDK調試方式之一: adb logcat

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.