标题: 上哪儿查看System.err.println()的输出
https://scz.617.cn/android/201701161610.txt
Q:
APK中有如下代码:
try { System.loadLibrary( "sczutiljni" ); } catch ( UnsatisfiedLinkError e ) { System.err.println( "Cannot load sczutiljni [" + e.toString() + "]" ); }
上哪儿查看System.err.println()的输出?
A: scz
对于Android开发,不建议使用System.err.println(),应该直接使用logcat机制
https://developer.android.com/studio/command-line/logcat.html https://developer.android.com/reference/android/util/Log.html
import android.util.Log;
Log.
v d i w e
从Android SDK Build-tools 21.0.3开始,TAG被限制在23个字符以内。
System.err.println()相当于:
Log.w( "System.err", "..." )
System.out.println相当于:
Log.i( "System.out", "..." )
这个与log.redirect-stdio属性无关。
$ adb shell "ps | grep com.anything.crackmegui_jni" u0_a47 1789 27933 326008 28104 ffffffff b7700827 S com.anything.crackmegui_jni
$ adb shell "logcat -d -v brief -s System.err:W | grep -E \"W/System.err( 1789):\"" $ adb logcat -d -v brief -s "System.err:W" | grep -E "W/System.err( 1789):" W/System.err( 1789): Cannot load sczutiljni [java.lang.UnsatisfiedLinkError: Couldn't load sczutiljni from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.anything.crackmegui_jni-1.apk,libraryPath=/data/app-lib/com.anything.crackmegui_jni-1]: findLibrary returned null]
与之类似:
$ adb shell "logcat -d -v brief -s System.out:I | grep -E \"I/System.out( 1789):\"" $ adb logcat -d -v brief -s "System.out:I" | grep -E "I/System.out( 1789):" I/System.out( 1789): ...
注意PID固定占5个字节,不足5个字节时左侧用空格补齐。
在Android Studio中使用logcat更方便。在左下角选中Android Monitor标签页, "Edit Filter Configuration"可以设置很细粒度的过滤规则,包括:
Log Tag Log Message Package Name PID Log Level
未被捕捉的UnsatisfiedLinkError异常:
$ adb shell "logcat -d -v brief -s AndroidRuntime:E" E/AndroidRuntime( 3141): FATAL EXCEPTION: main E/AndroidRuntime( 3141): java.lang.UnsatisfiedLinkError: Native method not found: com.anything.sczutil.HashUtility.gethash_via_jni:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; E/AndroidRuntime( 3141): at com.anything.sczutil.HashUtility.gethash_via_jni(Native Method) E/AndroidRuntime( 3141): at com.anything.sczutil.HashUtility.VerifyHash(HashUtility.java:65) E/AndroidRuntime( 3141): at com.anything.crackmegui_jni.SecretActivity$2.onClick(SecretActivity.java:73) E/AndroidRuntime( 3141): at android.view.View.performClick(View.java:4204) E/AndroidRuntime( 3141): at android.view.View$PerformClick.run(View.java:17355) E/AndroidRuntime( 3141): at android.os.Handler.handleCallback(Handler.java:725) E/AndroidRuntime( 3141): at android.os.Handler.dispatchMessage(Handler.java:92) E/AndroidRuntime( 3141): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime( 3141): at android.app.ActivityThread.main(ActivityThread.java:5041) E/AndroidRuntime( 3141): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 3141): at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime( 3141): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) E/AndroidRuntime( 3141): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) E/AndroidRuntime( 3141): at dalvik.system.NativeStart.main(Native Method)