Reputation: 11
I need to debug native C code (ndk-build) on the Android platform.
Is it possible to debug it in Android Studio, and if so how can I do it ?
Upvotes: 1
Views: 164
Reputation: 7653
In your C source code, you could add logs with this function:
__android_log_print(ANDROID_LOG_INFO, "MyTag", "The value is %d", some_variable);
Need this define:
#define <android/log.h>
Logs will be print in LogCat of Android device.
You don't have "step by step" debugger as in Android application.
Upvotes: 1
Reputation: 8847
ndk-build
, make
or whateverWorks for me with the lastest Studio version (1.3 RC3). You don't have to debug via CLI / logcat.
Upvotes: 0
Reputation: 3
As the LaurentY response, In your header file, you could define some logs like this:
#define <android/log.h>
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
Once in your .c/.cpp code you set the TAG as:
#define LOG_TAG "sample.cpp"
And call your logs using:
LOGI("Yes!!, %s, %s", some, some2);
Upvotes: 0