unity通过android adb查看真机日志

wylc123 1年前 ⋅ 961 阅读

   

前几天跑某大公司面试,问我会不会在android真机调试的时候直接输出到控制台,当时有点懵逼,居然不知道控制台是什么东西了,居然理解成了输出到eclipse...我觉得程序没有通过eclipse打包,怎么可能输出到它里面去呢...等面试完了,回公司的路上才回过神来,那个黑框框不就是控制台么!!!

 

adb是androidSDK的一个工具,位置就在sdk目录下的platform-tools文件夹下。

 

通过adb,不仅可以查看在Unity中自己设定的打印信息,包括系统信息和异常都能获取到。是android开发的一个神器!

 

因为最近的某些游戏中的需求在搞android代码,很多都需要再真机上测试,eclipse又不知道怎么看日志,所以就一直用adb

 

打开控制台,输入如下命令:

adb logcat -s Unity -d > xxx.txt

运行以后,unity中的所有输出都会保存到目标文件中(注意填写完整路径)

其中Unity是过滤用的tag,unity中的所有输出都是“Unity”

如果要按等级进行查看,比如说只看错误信息,并且直接显示在控制台,可以这样写

adb logcat -s Unity:e 

要查看所有的错误信息,包括系统的,那就这样写

adb logcat -s *:e 

 

下面是adb logcat的帮助信息:

 

[plain] view plain copy

  1. octopus@octopus:~$ adb logcat --help    

  2. Usage: logcat [options] [filterspecs]    

  3. options include:    

  4.   -s              Set default filter to silent.    

  5.                   Like specifying filterspec '*:s'    

  6.   -f <filename>   Log to file. Default to stdout    

  7.   -r [<kbytes>]   Rotate log every kbytes. (16 if unspecified). Requires -f    

  8.   -n <count>      Sets max number of rotated logs to <count>, default 4    

  9.   -v <format>     Sets the log print format, where <format> is one of:    

  10.     

  11.                   brief process tag thread raw time threadtime long    

  12.     

  13.   -c              clear (flush) the entire log and exit    

  14.   -d              dump the log and then exit (don't block)    

  15.   -t <count>      print only the most recent <count> lines (implies -d)    

  16.   -g              get the size of the log's ring buffer and exit    

  17.   -b <buffer>     Request alternate ring buffer, 'main', 'system', 'radio'    

  18.                   or 'events'. Multiple -b parameters are allowed and the    

  19.                   results are interleaved. The default is -b main -b system.    

  20.   -B              output the log in binary    

  21. filterspecs are a series of     

  22.   <tag>[:priority]    

  23.     

  24. where <tag> is a log component tag (or * for all) and priority is:    

  25.   V    Verbose    

  26.   D    Debug    

  27.   I    Info    

  28.   W    Warn    

  29.   E    Error    

  30.   F    Fatal    

  31.   S    Silent (supress all output)    

  32.     

  33. '*' means '*:d' and <tag> by itself means <tag>:v    

  34.     

  35. If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.    

  36. If no filterspec is found, filter defaults to '*:I'    

  37.     

  38. If not specified with -v, format is set from ANDROID_PRINTF_LOG    

  39. or defaults to "brief"    



没用过的可以尝试一下,注意adb命令,需要配置环境变量,如果不配置环境变量,就直接写adb.exe的完整路径

消除ADB错误“more than one device and emulator”的方法

碰到这种情况,首先要查一下,是不是真的有多个设备或模拟器。
C:\Users\gaojs>adb devices
List of devices attached
emulator-5554   device
4dfadcb86b00cf05        device
发现还真是多个设备,那就需要为ADB命令指定设备的序列号了。
C:\Users\gaojs>adb -s emulator-5554 shell
也就是如上所示,给命令加上-s的参数就可以了!

例如:

adb -s  5LM0215C25003172  logcat -s *:e 

 

Note: log switch off, only log_main and log_events will have logs!手机关闭日志功能。

真机调试不输出日志到logcat的原因是手机厂商默认关闭了调试打印的功能。按照下面的步骤打开日志输出功能即可解决此问题。

  1. 打开设备调试日志输入功能步骤:

    1、在拨号界面输入:*#*#2846579#*#* 进入测试菜单界面。 

    2、Project Menu–后台设置–LOG设置

    3、LOG开关–LOG打开 LOG级别设置–VERBOSE 

    4、Dump&Log– 全部选中 

    5、重启eclipse(如果你已经打开了eclipse的话)

  2. 3

    重新调试应用程序,发现问题解决,logcat已经有日志输出。

    另外,由于手机型号可能不同,本方案不一定保证能够解决所有型号设备的输出日志问题。

  3. 4

    需要注意的

      设置之后,有的手机需要重启之后才能起作用,但是也有的手机(比如华为C8812),重启之后会忘记之前的设置,所以,对于这种机器,每次重启机器,都需要重新设置一遍,才能正常调试!

 

 

更多内容请访问:IT源点

相关文章推荐

全部评论: 0

    我有话说: