Android:NDK:Debugging
Android NDK 디버깅 방법 (Using the NDK plugin).
ADT 20 includes an NDK plugin that provides support for building and debugging NDK projects in Eclipse. This document describes how to install and use the NDK plugin.
Installation
- The NDK plugin currently works with CDT 7.0.2 or CDT 8.0.2.
- Download Eclipse for Java.
- Install CDT from Eclipse update site http://download.eclipse.org/tools/cdt/releases/indigo.
- Install Android SDK + NDK Plugins from Eclipse update site https://dl-ssl.google.com/android/eclipse/
- Using the NDK Plugin
First set the path to SDK and NDK:
- Eclipse -> Window -> Preferences -> Android -> set path to SDK
- Eclipse -> Window -> Preferences -> Android -> NDK -> set path to the NDK
Right click on an Android project and select Android Tools -> Add native support.
- Note that you will not be able to add native support if the project already has C/C++ nature.
At this point, you will be able to build your applications using Project -> Build All. Debugging native applications
- Update your build config to include
NDK_DEBUG = 1
. - Right click project -> properties -> C/C++ Build > Builder Settings > Builder > Build command:
ndk-build NDK_DEBUG=1
- Set a breakpoint in your C code.
- Right click on your project, select Debug As -> Android Native Application
Note: There is a delay of a few seconds between when the activity is launched and when native debugging starts. If your code is already executed by that point, then you won’t see the breakpoint being hit. So either put a breakpoint in code that is called repetitively, or make sure that you call JNI code after you see that ndk-gdb has connected.
Known Issues:
- Eclipse does not automatically find the include paths to all the NDK headers on Windows. This issue will be fixed in the next update (20.0.1) when it is released.
- Eclipse does not automatically find the include paths with CDT 8.1.0 (Juno). This issue is tracked in Bug 33788.
Android JNI LogCat 출력방법
안드로이드 Java 단에서의 android.util.Log 클래스에서 제공하는 로그 기능을 Native단에서도 이용할 수 있다. 보통 LOGX (X는 severity를 지정) 라는 매크로를 정의해서 쓰며 해당 소스에서 이게 정의가 되어 있지 않다면 다음과 같이 소스에 정의하고 쓰면 된다.
#ifndef __INCLUDE__ANDROID__JNI_LOG_H__
#define __INCLUDE__ANDROID__JNI_LOG_H__
#include <android/log.h>
#define LOG_TAG "JNI_LOG_TAG"
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
#endif // __INCLUDE__ANDROID__JNI_LOG_H__
그리고 빌드시에 Android.mk 파일에 아래와 같이 라이브러리를 추가해 줘야 한다.
See also
- Android
- NDK
- Android:Debugging:Wireless - 무선 디버깅 방법
Favorite site
References
-
Android_debugging_native_code.pdf ↩