我已经更改了 android ndk 的 HelloJni 示例,我想在标准输出中写一些东西。这是 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。感谢谁提供了解决方案__android_log_print。