我无法让我的Nexus S(运行Android 4.0)将本地stdout消息重定向到logcat.我读过我需要这样做:
$ adb shell stop
$ adb shell setprop log.redirect-stdio true
$ adb shell start
Run Code Online (Sandbox Code Playgroud)
但是,这似乎不起作用.(它确实打破了JUnit,如这里所提到的,所以它并非没有效果.)
作为参考,这是我的代码:
package com.mayastudios;
import android.util.Log;
public class JniTester {
public static void test() {
Log.e("---------", "Start of test");
System.err.println("This message comes from Java.");
void printCMessage();
Log.e("---------", "End of test");
}
private static native int printCMessage();
static {
System.loadLibrary("jni_test");
}
}
Run Code Online (Sandbox Code Playgroud)
和JNI .c文件:
JNIEXPORT void JNICALL
Java_com_mayastudios_JniTester_printCMessage(JNIEnv *env, jclass cls) {
setvbuf(stdout, NULL, _IONBF, 0);
printf("This message comes from C (JNI).\n"); …Run Code Online (Sandbox Code Playgroud) 由于调试原生android代码非常困难,我将采用"printf trace"方法.
所以,我的问题是,在本机代码中,运行Android应用程序时会出现"printf("something")"标准吗?
我下载了SDL 1.3并在我的Android 2.2设备上与OpenGL ES一起测试了它.它工作正常,但我没有得到printf呼叫的输出.我尝试了android开发者页面中提到的下面的命令,但是DDMS在Eclipse中都没有adb logcat报告程序使用的字符串printf.我确保过滤stdout标签.
$ adb shell stop
$ adb shell setprop log.redirect-stdio true
$ adb shell start
Run Code Online (Sandbox Code Playgroud)
我错过了什么或做错了什么?