{"id":345,"date":"2023-02-25T07:02:15","date_gmt":"2023-02-24T23:02:15","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=345"},"modified":"2023-04-30T14:47:42","modified_gmt":"2023-04-30T06:47:42","slug":"android-ndk-development-using-android-log-library","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/android-ndk-development-using-android-log-library\/","title":{"rendered":"Android NDK \u5f00\u53d1\u4f7f\u7528 ANDROID_LOG \u65e5\u5fd7\u5e93"},"content":{"rendered":"<h2>\u5b9a\u4e49\u5934\u6587\u4ef6<\/h2>\n<p>common.h<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-h\">#ifndef CZXING_COMMON_H\n#define CZXING_COMMON_H\n\n#include &lt;jni.h&gt;\n\n#ifdef NDK_DEBUG\n#define LOG_TAG &quot;yezhou&quot;\n#include &lt;android\/log.h&gt;\n\n#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)\n#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)\n#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)\n#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)\n#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__)\n#endif\n\n#endif<\/code><\/pre>\n<h2>\u8c03\u7528\u65b9\u5f0f<\/h2>\n<pre><code class=\"language-cpp\">#include &quot;common.h&quot;\n\nextern &quot;C&quot;\nJNIEXPORT jint JNICALL\nJava_cc_androidx_zxing_code_NativeSdk_writeCode(JNIEnv *env, jobject instance, jstring jcontent,\n                                                jint width, jint height, jint color,\n                                                jstring jformat, jobjectArray result) {\n    const char *content = env-&gt;GetStringUTFChars(jcontent, 0);\n    const char *format = env-&gt;GetStringUTFChars(jformat, 0);\n    LOGE(&quot;writeCode.content [%s]&quot;, content);\n    ...\n    return 0;\n}<\/code><\/pre>\n<h2>\u5f15\u5165log\u5e93<\/h2>\n<h3>CMakeLists.txt<\/h3>\n<pre><code>find_library(\n        log-lib\n        log)\n\ntarget_link_libraries(\n        czxing\n        ZXingCore\n\n        jnigraphics\n        android\n        z\n        ${log-lib})<\/code><\/pre>\n<h3>Android.mk<\/h3>\n<pre><code>LOCAL_MODULE     := ccrypto\nLOCAL_LDLIBS     := -llog \\\n                    -lm<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9a\u4e49\u5934\u6587\u4ef6 common.h #ifndef CZXING_COMMON_H #define CZXING_C [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-345","post","type-post","status-publish","format-standard","hentry","category-android-ndk"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=345"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/345\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}