Similarities and differences between Android4.2.2NDK and jni for source code development

Source: Internet
Author: User

C/C ++ development: How to output Log information in NDK and source code!

NDK:
1. include header files
# Include
2. Android. mk contains libraries.
LOCAL_LDLIBS + =-L $ (SYSROOT)/usr/lib-llog
The above is required, otherwise error: undefined reference to '_ android_log_print' will appear'
LOCAL_SHARED_LIBRARIES: = libdl \
Liblog \ # tested that NDK compilation in Eclipse is dispensable and useless! But it must be him in the source code, so add them all!
Libpre_AppUpgrade \
Libpre_AppArea \
3. Define in your jni File
# Define LOGD (...) _ android_log_print (ANDROID_LOG_DEBUG, LOG_TAG, __va_args _) // define the LOGD type
# Define LOGI (...) _ android_log_print (ANDROID_LOG_INFO, LOG_TAG, __va_args _) // define the LOGI type
# Define LOGW (...) _ android_log_print (ANDROID_LOG_WARN, LOG_TAG, __va_args _) // define the LOGW type
# Define LOGE (...) _ android_log_print (ANDROID_LOG_ERROR, LOG_TAG, __va_args _) // define the LOGE type
# Define LOGF (...) _ android_log_print (ANDROID_LOG_FATAL, LOG_TAG, __va_args _) // define the LOGF type

The source code of adnroid4.2 has added a header for all LOGD and so on,
# Define ALOGD (...) _ android_log_print (ANDROID_LOG_DEBUG, LOG_TAG, __va_args _) // define the LOGD type
# Define ALOGI (...) _ android_log_print (ANDROID_LOG_INFO, LOG_TAG, __va_args _) // define the LOGI type
# Define ALOGW (...) _ android_log_print (ANDROID_LOG_WARN, LOG_TAG, __va_args _) // define the LOGW type
# Define ALOGE (...) _ android_log_print (ANDROID_LOG_ERROR, LOG_TAG, __va_args _) // define the LOGE type
# Define ALOGF (...) _ android_log_print (ANDROID_LOG_FATAL, LOG_TAG, __va_args _) // define the LOGF type

Note that if you do not want to define the above Macros in every jni file, the speculative method can be defined in: D: \ android-ndk-r9d \ platforms \ android-19 \ arch-arm \ usr \ include \ android \ log. h in progress! Of course, this compilation can only be used on your local machine ~

Source code development:
1. Android. mk contains libraries.
LOCAL_LDLIBS + =-L $ (SYSROOT)/usr/lib-llog
LOCAL_SHARED_LIBRARIES: = libdl \
Liblog \ // must be added to the source code
Libpre_AppUpgrade \
Libpre_AppArea \
2. include header files # include
3. Remember to include the library header file when using it.

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.