11.Android of the JNI implementation function log Print __ function

Source: Internet
Author: User
When using JNI in a Java environment, you can easily print information using the printf function, and in the Eclipse Console console view it is easy to observe that if you use JNI in an Android environment, the printf function will not work. No output is visible in the Logcat view and the console view. But we can use the log method of Android itself to implement the following steps:

1, in the JNI implementation code file (. C or. cpp), add the following code containing the log header file:
#include <android/log.h>

2, in the need to print the method to add printing code, such as:
__android_log_print (Android_log_info, "Jnix431filetest", "Lsx_init");

Android_log_info: is the log level;
"Jnix431filetest": the label to filter, which can be filtered in the Logcat view.
"Lsx_init": is the actual log content.

3. Add the following content to the Android.mk file in the Android project:
Local_ldlibs + =-l$ (sysroot)/usr/lib-llog

4, OK, now you can print the information.

As for how to implement an Android project called JNI Local/C + + functions can refer to the previous blog:
http://blog.csdn.net/jjunjoe/article/details/7007052

Related Article

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.