Can logcat be used to log NDK code in Android? Or what are logging options from NDK?

巧了我就是萌 提交于 2019-12-02 23:16:59
AnkitSomani

You can use the Android logging

#include <android/log.h>

#define APPNAME "MyApp"

__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "My Log");

Also Make sure you also link against the logging library, in your Android.mk file:

LOCAL_LDLIBS := -llog

It has already been discussed at Any simple way to log in Android NDK code?

If you are using the newer Android Studio versions (2.2+) that use CMake, then you will find the following automatically added to your CMakeLists.txt file when you generate 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} )
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!