JNI variable Printing

Source: Internet
Author: User

1. Package Log.h

#ifndef __multi_trace_h__
#define __multi_trace_h__

#ifdef Android_ndk_build
#define LOG_TAG "NATIVE NDK INFO"

#include <android/log.h>//only use in NDK

#define LOGE (...) (void) __android_log_print (Android_log_error, Log_tag, __va_args__))
#define LOGD (...) (void) __android_log_print (Android_log_debug, Log_tag, __va_args__))
#define Logi (...) (void) __android_log_print (Android_log_info, Log_tag, __va_args__))
#define LOGW (...) (void) __android_log_print (Android_log_warn, Log_tag, __va_args__))
#elif defined Android_source_build
#define LOG_TAG "NATIVE SRC INFO"

extern "C" {
#include <cutils/log.h>//Only use in ANDROID SOURCE
}

#define LOGE (...) LOG (Log_error, Log_tag, __va_args__)
#define LOGD (...) LOG (Log_debug, Log_tag, __va_args__)
#define Logi (...) LOG (Log_info, Log_tag, __va_args__)
#define LOGW (...) LOG (Log_warn, Log_tag, __va_args__)
#elif defined Ios_platform_build
#define LOGE printf
#define LOGD printf
#define Logi printf
#define LOGW printf
#elif defined Wp_platform_build
#define LOG_TAG "NATIVE WINDOWS PHONE"
#define LOG_ERROR "ERROR"
#define LOG_DEBUG "DEBUG"
#define LOG_INFOR "INFOR"
#define Log_warn "WARN"

void LOG (const char* status, const char* tag, const char* format, ...);

#define LOGE (...) LOG (Log_error, Log_tag, __va_args__)
#define LOGD (...) LOG (Log_debug, Log_tag, __va_args__)
#define Logi (...) LOG (Log_info, Log_tag, __va_args__)
#define LOGW (...) LOG (Log_warn, Log_tag, __va_args__)
#else
#define LOGE printf
#define LOGD printf
#define Logi printf
#define LOGW printf
#endif

#endif

2. Configuring in Android.mk

Local_path: = $ (call My-dir)//Set as current folder

Include $ (clear_vars)//Empty variable

Local_module: = apkpatchlibrary///finally generated. So file will be the second name of the wallet Lib (if this name is Libxxx, the generated. So file package name is this name)
Local_cflags =-dandroid_ndk_build-d__stdc_format_macros-d__stdc_int64__//Set this sentence is equivalent to the declaration of XXXXX (-DXXXXX) in each of the C + + files.

Local_cxxflags: =

Local_c_includes: = $ (Local_path)

Local_src_files: = COM_LIB_UTILS_PATCH.C//compiled C + + file
Local_ldlibs: =-lz-llog//need to add this log to print out,-l is a fixed statement, (such as:-lz marked loading system z.so package. -llog Flag Loading System log.so pack)

Include $ (build_shared_library)//Set Declaration dynamic Library


3. Print the log. Take a look at the examples:

Jniexport jint jnicall java_com_lib_utils_patchutils_patch (jnienv *env,
Jobject obj, jstring old, jstring new, jstring patch) {
char * ch[4];
Ch[0] = "Bspatch";
CH[1] = (char*) ((*env)->getstringutfchars (env, old, 0));
CH[2] = (char*) ((*env)->getstringutfchars (env, new, 0));
CH[3] = (char*) ((*env)->getstringutfchars (env, patch, 0));


LOGD ("11111111111111111111");
const char *STR = (*env)->getstringutfchars (env, old, 0);
const char *strnew = (*env)->getstringutfchars (env, new, 0);
const char *strpatch = (*env)->getstringutfchars (env, patch, 0);


LOGD ("The first is%s", str);
LOGD ("The second is%s", strnew);
LOGD ("The third is%s", Strpatch);
LOGD ("11111111111111111111");


int ret = Applypatch (4, CH);
(*env)->releasestringutfchars (env, old, ch[1]);
(*env)->releasestringutfchars (env, New, ch[2]);
(*env)->releasestringutfchars (env, Patch, ch[3]);

return ret;
}


This allows you to print out old, new. Patch the value of these three parameters (variables) that.


Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

JNI variable Printing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.