Use printk(“Message you want to display”); in the code.
And then you can see those logs with the following command:
$ adb shell dmesg
Note that this command will not work like a regular terminal, as it will essentially print out every message displayed by the kernel since the time the system booted.
So you may want to save the output of this command to a file, to better interpret the information:
$ adb shell dmesg > kernelOutput.out
Alternatively you can just read the output of your emulator's terminal window.
There are two ways you can redirect your native code prints to logcat.
The first was covered here, and if you want to use this approach you better follow that page in terms of build.gradle file configurations.
Essentially in our code you must:
#include <string.h> #include <android/log.h>
#define APPNAME "YourAppName" #define printToLogcat(...) __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, __VA_ARGS__)
printToLogcat("Message you want to display to Java #%d\n", 10);
The second way you can redirect your native prints to logcat is perhaps simpler.
After launching your emulator, open a terminal and follow these commands:
$ adb shell stop $ adb shell setprop log.redirect-stdio true $ adb shell start
Your emulator should then restart and then you can use traditional prints on your code that will then appear on logcat:
printf("Message you want to display\n"); fflush(stdout);
If you want to use printf, you need to use the flush function after.
Alternatively you can write to stderr:
fprintf(stderr, "Message you want to display in case of an error");