NDK 응용 프로그램에서 "인쇄" 메시지를 작성하려면 어떻게 해야 합니까?
자바 파일에서 이러한 함수를 정의하는 경우
/**
* Adds two integers, returning their sum
*/
public native int add( int v1, int v2 );
그래서 나는 c파일로 코드를 해야 한다.
JNIEXPORT jint JNICALL Java_com_marakana_NativeLib_add
(JNIEnv * env, jobject obj, jint value1, jint value2) {
printf("\n this is log messge \n");
return (value1 + value2);
}
그러면 이 printf는 어디에서 메시지를 출력합니까?logcate에서 이해 못 하겠어?
로그 메시지를 저장하여 NDK 응용 프로그램을 디버깅하려면 어떻게 해야 합니까?
사용하다__android_log_print()
대신.헤더를 포함해야 합니다.<android/log.h>
샘플 예시 __android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "\n this is log messge \n");
printf와 같은 형식 지정자를 사용할 수도 있습니다.
__android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "Need to print : %d %s",int_var, str_var);
Android.mk 파일에 있는 로깅라이브러리에 대한 링크도 확인해 주세요.
LOCAL_LDLIBS := -llog
아..잊어버렸어..출력은 에 나타냅니다.Logcat
태그 부착LOG_TAG
간단한 접근
공통 헤더 파일에 다음 행을 추가합니다.
#include <android/log.h>
#define LOG_TAG "your-log-tag"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
// If you want you can add other log definition for info, warning etc
전화나 해LOGD("Hello world") or LOGE("Number = %d", any_int)
맘에 들다printf in c
.
공통 헤더 파일 포함을 잊지 마십시오.
로그를 삭제합니다.
정의하면LOGD(...)
비어 있으면 모든 로그가 사라집니다.다음에 코멘트만 해 주세요LOGD(...)
.
#define LOGD(...) // __android_log..... rest of the code
root 디바이스는 필요 없습니다.아래의 http://developer.android.com/guide/developing/debugging/debugging-log.html#viewingStd, 에의 어크로잉은 현지에 따라 동작합니다.
$ adb shell
$ su
$ stop
$ setprop log.redirect-stdio true
$ start
알았어!
두 가지 옵션이 있습니다.
1) printf를 __print_log_print로 바꿉니다.코드 선두에 있는 정의를 사용하면 쉽게 이 작업을 수행할 수 있습니다.
#define printf(...) __android_log_print(ANDROID_LOG_DEBUG, "TAG", __VA_ARGS__);
물론 printf가 있는 모든 소스 코드를 변경해야 합니다.
2) stdout 및 stderr을 Android logcat으로 리다이렉트합니다(루트 이외의 디바이스에서는 동작할지는 불명).http://developer.android.com/guide/developing/debugging/debugging-log.html#viewingStd
언급URL : https://stackoverflow.com/questions/10274920/how-to-get-printf-messages-written-in-ndk-application
'sourcecode' 카테고리의 다른 글
vue.js 2의 입력 유형 텍스트에 연산자 3진수를 추가하려면 어떻게 해야 합니까? (0) | 2022.08.13 |
---|---|
Vue 인라인 템플릿이 메서드 또는 데이터를 찾을 수 없음 (0) | 2022.08.13 |
Vue.js의 컴포넌트 라이프 사이클 메서드에서 믹스인 메서드 내 기능에 액세스하는 방법 (0) | 2022.08.12 |
webpack-simple 설정 전송 오류와 함께 비동기/대기 사용: RegeneratorRuntime이 정의되지 않음 (0) | 2022.08.12 |
인터뷰 질문:한 문자열이 다른 문자열의 회전인지 확인합니다. (0) | 2022.08.12 |