我已经修改了Android NDK的HelloJni示例,我想要向stdout写入一些东西。这里是JNI代码:
#include <stdlib.h>
#include <jni.h>
#include <stdio.h>
jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
jobject thiz )
{
printf("Hello from C !\n");
return (*env)->NewStringUTF(env, "Hello from JNI !");
}
这是我的日志:
09-28 13:07:02.906: I/ActivityManager(1650): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.hellojni/.HelloJni u=0} from pid 1790
09-28 13:07:03.007: D/dalvikvm(1650): GC_FOR_ALLOC freed 687K, 10% free 9300K/10247K, paused 62ms, total 62ms
09-28 13:07:03.070: D/dalvikvm(3562): Not late-enabling CheckJNI (already on)
09-28 13:07:03.085: I/ActivityManager(1650): Start proc com.example.hellojni for activity com.example.hellojni/.HelloJni: pid=3562 uid=10052 gids={1015, 1028}
09-28 13:07:03.101: I/dalvikvm(3562): Turning on JNI app bug workarounds for target SDK version 3...
09-28 13:07:03.132: D/dalvikvm(3562): Debugger has detached; object registry had 1 entries
09-28 13:07:03.171: D/dalvikvm(3562): Trying to load lib /data/data/com.example.hellojni/lib/libhello-jni.so 0x414af318
09-28 13:07:03.179: D/dalvikvm(3562): Added shared lib /data/data/com.example.hellojni/lib/libhello-jni.so 0x414af318
09-28 13:07:03.179: D/dalvikvm(3562): No JNI_OnLoad found in /data/data/com.example.hellojni/lib/libhello-jni.so 0x414af318, skipping init
09-28 13:07:03.265: V/TabletStatusBar(1715): setLightsOn(true)
09-28 13:07:03.328: I/ActivityManager(1650): Displayed com.example.hellojni/.HelloJni: +279ms
09-28 13:07:07.078: E/ThrottleService(1650): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
我已将log.redirect-stdio设置为true,这样我就能在LogCat中看到“Hello”行。
有人知道如何使它起作用吗?谢谢。
更明确地说,我想要看到我的输出在stdout中。没有什么问题,我只是想知道是否可以输出到stdout。感谢提供解决方案的人使用__android_log_print。