Can logcat be used to register NDK code in Android? Or what are the registration parameters from NDK?

How to write logs from internal code in Android (NDK)? What are the available options? For example, can logcat be used from within the NDK to write logs? Or, since its higher level in android, it cannot be accessed from NDK?

At the moment, I just know how to write times from C code: millis = System.currentTimeMillis();

And with a function that will write this time plus any messages to the user log file.

+12
android android-ndk android-logcat logcat
source share
2 answers

You can use Android logging

 #include <android/log.h> #define APPNAME "MyApp" __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "My Log"); 

Also make sure that you also reference the log library in your Android.mk file:

 LOCAL_LDLIBS := -llog 

This has already been discussed on . Is there an easy way to get into the Android NDK code?

+27
source share

If you are using new versions of Android Studio (2.2+) that use CMake, then you will find the following automatically added to your CMakeLists.txt when creating a new project with C ++ support:

 find_library( # Sets the name of the path variable. log-lib # Specifies the name of the NDK library that # you want CMake to locate. log ) 

and

 target_link_libraries( # Specifies the target library. your-lib1 your-lib2 ... # Links the target library to the log library # included in the NDK. ${log-lib} ) 
+17
source share

All Articles