简体   繁体   English

LogCat不在真实设备中显示我自己的日志

[英]LogCat doesn't show my own logs in real device

I have little test app in Android Studio with strange behavior regarding LogCat: For example I have logs like this: 我在Android Studio中几乎没有测试应用程序,但它与LogCat有关的行为却很奇怪:例如,我有这样的日志:

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate(Bundle) called");
        ...

If I try to start my app in emulator, all my logs work fine. 如果我尝试在模拟器中启动我的应用程序,则所有日志都可以正常工作。 But if I try to start my app on a real device, I can see a lot of system logs from my device(for example from BatteryService), but there are none of my own logs here. 但是,如果我尝试在真实设备上启动应用程序,则可以从设备上看到很多系统日志(例如,来自BatteryService),但是这里没有我自己的日志。

I have enabled ADB integration and source of logs in LogCat choosed right(my device). 我已启用ADB集成,并且LogCat中的日志源选择正确(我的设备)。

Assuming you already have USB debugging activated(othervise it will not work). 假设您已经激活了USB调试(否则将无法工作)。
Open logcat and press the launch button. 打开logcat并按启动按钮。 and as it goes to your device it should work normally. 并且随着它进入您的设备,它应该可以正常工作。 Now, if you are using the APK from google drive, the app store or anywhere else it will not work as debug access isn't there. 现在,如果您使用的是Google云端硬盘中的APK,则应用商店或其他任何地方都无法使用,因为那里没有调试访问权限。

If you have done the above, you can try this method: 如果您已完成上述操作,则可以尝试以下方法:

As you can see, there is a search box next to the 'Log level' dropdown menu. 如您所见,“日志级别”下拉菜单旁边有一个搜索框。 Search for your app(in format of a package name) and it will show up. 搜索您的应用程序(以程序包名称的格式),它将显示出来。 From there, you can select a log level(if you feel like it). 从那里,您可以选择一个日志级别(如果您愿意)。 If you do not chose a log level and set it to verbose, all logs will show up, all types of log level. 如果您没有选择日志级别并将其设置为“ verbose”,则将显示所有日志以及所有类型的日志级别。

And if that does not work, we can definitivly conclude with the fact that it is NOT USB debugging related. 如果还是不行,我们可以definitivly的事实,它不是 USB调试相关的结论。 Then it might be because of configurations in build.gradle files, the Android Manifest, or maybe in the code. 则可能是由于build.gradle文件,Android Manifest或代码中的配置所致。 Also, in my experience, Proguard prevents log output, but you get output just not from your app. 另外,以我的经验,Proguard会阻止日志输出,但是您只是从应用程序中获取输出。 So if none of the above worked, check: 因此,如果以上方法均无效,请检查:

  • Android min version(by what your app can handle) Android最低版本(根据您的应用可以处理的版本)
  • Android target version(in comparison with the newest current API which is right now 24) Android目标版本(与最新的当前API(目前为24)相比)
  • (the same in build.gradle on app level) (在应用程序级别的build.gradle中相同)
  • Proguard on/off Proguard开/关

And finally, if none of that works, download ACRA and convert the logs using the simplest backend(10 lines) and you have the logs on your website upon crash in .txt format. 最后,如果这些都不起作用,请下载ACRA并使用最简单的后端(10行)转换日志,当崩溃时,您会将日志以.txt格式保存在网站上。 It is a hard workaround but at least you will be able to read any crashes. 这是一个艰难的解决方法,但至少您将能够读取任何崩溃信息。

Check for the dropdown in LogCat and change the option to Debug or D. 检查LogCatdropdown ,然后将选项更改为Debug或D。
Being you have put your logs in Log.d("TAG","MSG"); 正在将日志放入Log.d("TAG","MSG");

Options are 选项是

  1. Verbose 详细
  2. debug . 调试 Your logs will appear in this case 您的日志将在这种情况下出现
  3. info 信息
  4. warn 警告
  5. error 错误
  6. assert 断言

I found problem. 我发现了问题。 Strange behavior of LogCat was because of API version of my device Android was lower than required API version of my app. LogCat的异常行为是因为我的设备的API版本Android低于我的应用程序所需的API版本。

try this on your andorid device! 在您的Andorid设备上尝试!

Performance Optimization - Advanced Log Output 性能优化-高级日志输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM