11

I downloaded SDL 1.3 and tested it together with OpenGL ES on my android 2.2 device. It works fine but I don't get the outputs from the printf calls. I tried the commands below as mentioned at the android developer page but neither DDMS in Eclipse nor adb logcat reports the strings that the program writes using printf. I made sure to filter for the stdout tag.

$ adb shell stop
$ adb shell setprop log.redirect-stdio true
$ adb shell start

What am I missing or doing wrong?

trenki
  • 7,133
  • 7
  • 49
  • 61
  • FWIW, this causes the Dalvik VM to create a thread that copies stdout/stderr to the log file. You need to be root to stop/start the app framework. See also http://stackoverflow.com/questions/17188987/android-native-code-debugging/17199704#17199704 . – fadden Jan 10 '14 at 06:36

2 Answers2

2

According to this presentation, log.redirect-stdio is for Dalvik output, to redirect C/C++ output (such as printf), you must install busybox on the device and use its xargs utility like this:

myprogram | xargs log

This obviously works for code that gets called as a standalone executable. If it's only for debugging purposes, you can write a tiny program to call your library and call that from your application using xargs.

gfour
  • 959
  • 6
  • 9
  • 1
    See my answer to http://stackoverflow.com/questions/9192749/capturing-stdout-stderr-with-ndk for a solution with pipes instead of busybox. – James Moore Jun 13 '12 at 17:12
1

Another way of doing this is having a file /data/local.prop, containing just the line log.redirect-stdio=true. Maybe this works better? Also, note that stdout is buffered, so it could be that your output is still sitting in the buffer, waiting to be flushed. You can call fflush manually to check this.

svdree
  • 13,298
  • 4
  • 28
  • 21
  • adb push local.prop /data/local.prop does not work because of permissions. Do I have to root my device? – trenki Apr 06 '11 at 07:37
  • 1
    Hmm, I didn't realize that this would give you trouble on a device. It works fine on the emulator though. I know the emulator is a pain to use, especially with OpenGL, but maybe it's an option for incidental trouble shooting? According to a message by David Turner on the NDK group (see http://groups.google.com/group/android-ndk/msg/0d37b24df6df7cde ) the stop/setprop/start should be considered unsupported. – svdree Apr 06 '11 at 10:30
  • Does this work from C? I see stderr output to logcat from java when I do this, but I don't see output from C calls to something like fprintf(stderr, "something"). – James Moore May 03 '12 at 17:45