Logcat won't display Log.d messages

2020-02-09 02:44发布

I'm developing an Android application and I would like to have some way to print debug statements as my code runs. Fortunately for me, Logcat was able to print out Log.d messages when I run my application on an Android 2.3.3 (API 10) emulator.

However, when I tested the same exact application on a physical device (Samsung Galaxy S4 Android 4.2.2) I was unable to see anything other than dalvikvm and AndroidRuntime messages.

com.android.internal.os.RuntimeInit <<<<<<
07-28 04:49:24.165: DEBUG/AndroidRuntime(6378): CheckJNI is OFF
07-28 04:49:24.165: DEBUG/AndroidRuntime(6378): setted country_code = USA
07-28 04:49:24.165: DEBUG/AndroidRuntime(6378): setted countryiso_code = US
07-28 04:49:24.175: DEBUG/AndroidRuntime(6378): setted sales_code = VZW
07-28 04:49:24.175: DEBUG/AndroidRuntime(6378): readGMSProperty: start
07-28 04:49:24.175: DEBUG/AndroidRuntime(6378): readGMSProperty: already setted!!
07-28 04:49:24.175: DEBUG/AndroidRuntime(6378): readGMSProperty: end
07-28 04:49:24.175: DEBUG/AndroidRuntime(6378): addProductProperty: start
07-28 04:49:24.185: DEBUG/dalvikvm(6378): Trying to load lib libjavacore.so 0x0
07-28 04:49:24.185: DEBUG/dalvikvm(6378): Added shared lib libjavacore.so 0x0
07-28 04:49:24.195: DEBUG/dalvikvm(6378): Trying to load lib libnativehelper.so 0x0
07-28 04:49:24.195: DEBUG/dalvikvm(6378): Added shared lib libnativehelper.so 0x0
07-28 04:49:24.385: DEBUG/AndroidRuntime(6378): Calling main entry com.android.commands.pm.Pm
07-28 04:49:26.978: DEBUG/AndroidRuntime(6378): Shutting down VM
07-28 04:49:26.988: DEBUG/dalvikvm(6378): GC_CONCURRENT freed 157K, 21% free 627K/788K, paused 1ms+0ms, total 4ms
07-28 04:49:26.988: DEBUG/jdwp(6378): Got wake-up signal, bailing out of select
07-28 04:49:26.988: DEBUG/dalvikvm(6378): Debugger has detached; object registry had 1 entries
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): CheckJNI is OFF
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): setted country_code = USA
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): setted countryiso_code = US
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): setted sales_code = VZW
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): readGMSProperty: start
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): readGMSProperty: already setted!!
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): readGMSProperty: end
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): addProductProperty: start
07-28 04:49:27.468: DEBUG/dalvikvm(6420): Trying to load lib libjavacore.so 0x0
07-28 04:49:27.478: DEBUG/dalvikvm(6420): Added shared lib libjavacore.so 0x0
07-28 04:49:27.478: DEBUG/dalvikvm(6420): Trying to load lib libnativehelper.so 0x0
07-28 04:49:27.478: DEBUG/dalvikvm(6420): Added shared lib libnativehelper.so 0x0
07-28 04:49:27.649: DEBUG/AndroidRuntime(6420): Calling main entry com.android.commands.am.Am
07-28 04:49:27.659: DEBUG/dalvikvm(6420): Note: class Landroid/app/ActivityManagerNative; has 169 unimplemented (abstract) methods
07-28 04:49:27.719: DEBUG/AndroidRuntime(6420): Shutting down VM
07-28 04:49:27.729: DEBUG/dalvikvm(6420): GC_CONCURRENT freed 157K, 20% free 666K/828K, paused 0ms+1ms, total 3ms
07-28 04:49:27.729: DEBUG/jdwp(6420): Got wake-up signal, bailing out of select
07-28 04:49:27.729: DEBUG/dalvikvm(6420): Debugger has detached; object registry had 1 entries

I'm not exactly sure what is going on since Logcat is correctly targeting my physical device, it shows up on adb devices, and USB Debugging is on.

I've tried using Log.e but that had no effect on the output.

I even set android:debuggable="true" in AndroidManifest.xml.

Is there something I'm missing here? Why won't Logcat display my debug messages when running my app on my physical device?

EDIT: I tried the same app on a Android 4.2.2 emulator and Logcat works as expected with the emulator, but there's still the problem with Logcat through the USB device. Instead of the verbosity of a normal Logcat printout, the block I posted is the only thing I see on the Verbose log level.

6条回答
唯我独甜
2楼-- · 2020-02-09 03:18

Did you have enabled USB debugging for logcat ? (if your physical device is connected by USB cable). Go to "settings", then "applications", then "development", then check "USB debugging".

Then it should appear in DDMS. Just select it to debug/see logs.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2020-02-09 03:19

You need to set logging (to the desired level) through the adb shell as follows:

  1. Navigate to the platform-tools in your android sdk folder.
  2. Open the adb shell using ./adb shell for linux/mac/windows powershell or just adb shell for windows cmd.
  3. Issue the following commands:

     stop
     setprop log.tag.MYTAG VERBOSE
     start 
    

查看更多
Animai°情兽
4楼-- · 2020-02-09 03:22

On some models you have to go to the developer options, and select "Allow all", on "Advanced logging".

The following screenshot is from my Meizu MX 4 Pro:

enter image description here

查看更多
老娘就宠你
5楼-- · 2020-02-09 03:27

Today, I faced the same issue. Nothing worked for me as mentioned solutions. But what worked for me is in Android Studio Right side at the bottom as mentioned in the image. Select the option as mentioned in the image. After that everything was working as expected. Now posting my solution it may help others.

enter image description here

Hope that helps others

查看更多
够拽才男人
6楼-- · 2020-02-09 03:31

Maybe not an answer, but need to show pictures. Try to set a Filter for Your TAG like this:

enter image description here

and select verbose option:

enter image description here

does this help?

查看更多
霸刀☆藐视天下
7楼-- · 2020-02-09 03:41

It might because of some phones disabled log to enhance performance.

For example, my phone HUAWEI P9 lite, i have to do the following steps to make Log.d works:

  1. Dial *#*#2846579#*#*
    • The number might vary, you should do some search to get secret code for your phone.
  2. Come to ProjectMenu page
  3. Click Background Settings
  4. Click LOG Settings
  5. Check AP Log.
  6. For unknown reason, it automatically checked all logs when reopen LOG Settings.

enter image description here

[UPDATE]

Just now it happen again after I pull from git, adb shell shows this:

open '/dev/hwlog_switch' fail -1, 13. Permission denied
log switch off, only log_main and log_events will have logs!

I test with new project and it got log, only this old project has issue. I tried rebuild the app, re-enable the log steps above, and even reboot phone, but still no luck.

Then I uninstall the app (Or all relevant productFlavors apps) in phone and reinstall, the log was back.

查看更多
登录 后发表回答