Android NDK console print C/C++ – Chirag Patel

When your Android app has C/C++ code using NDK tools and you want printing output to serial port console, here’s the solution.

// change sharing first
chmod(“/dev/console”, S_IRWXG | S_IRWXO | S_IRWXU);
// open file
int serialFd = open(“/dev/console”, O_RDWR | O_NONBLOCK | O_NDELAY | O_NOCTTY | O_APPEND);
__android_log_print(ANDROID_LOG_DEBUG, “Serial”, “Serial console fd=%d errno=%d(%s)”, serialFd, errno, strerror(errno));
if (serialFd >= 0) {
    write(serialFd, my_buffer, buffer_length);
    close(serialFd);
}

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.