一、之前面临的困境
Unity的程序build到android一体机后,仿佛进入了一个黑箱子,你既看不到脚本的debug报错信息,也看不到任务管理器里的内存和CPU使用情况?如果黑屏、闪屏、花屏怎么办?
最近面临的一个问题就是:APP在android一体机上频繁闪退和卡死,卡死的时候,出现黑屏甚至花屏!
也知道需要用到adb工具,但是每次打印log信息,只能打印系统级别的log信息,没有脚本级别的debug信息,所以想管中窥豹也不行了!
二、如何读取Android上App中的脚本调试(Debug)信息
1、如何安装adb工具(用usb连接到device)
- 本机安装adb工具
- 电脑和VR一体机采用usb连接
- VR一体机里面,android打开【USB调试】功能
- 注:关于adb的安装和简单使用,大家自行搜索,也可以参考之前的一篇blog
安装adb,读取android设备上的log日志并保存到电脑中
2、使用adb命令查看log信息,或者保存信息到电脑目录中
举例:读取一体机日志并保存到指定目录[d:\myLog.txt]里
adb shell logcat -v time > d:\myLog.txt
3、如何查看android上某Unity APP的debug信息
- (1) 一体机上有一个用unity开发的app(它的报名叫xinnengyuan),如何只读取这个app的log信息
adb logcat -s Unity ActivityManager PackageManager xinnengyuan
- (2) 在Build设置里进行设置(非常重要)
我之前就是没有开启这个build设置,所以一直读不到脚本的debug信息
参考资料:
详细信息请前往:Build Settings
常用的BuildSettings选项
设置的项目 | 作用 |
---|---|
Development Build | Enable this setting to include scripting debug symbols and the Profiler in your build. When you enable this, Unity sets the DEVELOPMENT_BUILD scripting define. You should use this setting when you want to test your application |
Autoconnect Profiler | Enable this setting to automatically connect the Unity Profiler to your build. This setting is only available if you enable Development Build. |
Deep Profiling Support | Enable this setting to turn on Deep Profiling in the Profiler. This makes the Profiler instrument every function call in your application and returns more detailed profiling data. When you enable Deep Profiling Support, it might slow down script execution. This setting is only available if you enable Development Build. |
Script debugging | Enable this setting to allow your script code to be debugged. Not available on WebGL. This setting is only available if you enable Development Build. |
Scripts Only Build | Enable this setting to only rebuild the scripts in your application, and reuse data files from the build you previously executed. Before you can use this setting, you must build your whole Project once. The Scripts Only Build option significantly improves iteration times if you only changed the code in your application. This setting is only available if you enable Development Build. |
- (3) 如果只读取该包的debug信息呢,要如何写adb命令?
adb logcat -s Unity ActivityManager PackageManager xinnengyuan DEBUG
- (4) 翻屏后,debug信息被清除了,如何把这些信息保存到指定的文件里,比如存到D盘根目录下
adb logcat -s Unity ActivityManager PackageManager xinnengyuan DEBUG > d:\myLog2.txt
使用方法:
第一步:输入以上的命令,开启adb监听
第二步:在VR一体机上操作app,直到黑屏、花屏,甚至冒烟炸机…
第三步:用【Ctrl + C】结束adb监听
第四步:到D盘下,查看你的myLog2.txt文档,你将会在D盘发现这个胖嘟嘟的可爱的日志文件:)
第五步:分析日志文档
寻找到的报错信息(节选);