Unity 安卓真机DEBUG

本文介绍了如何在Unity中进行安卓真机调试,包括开启USB调试、使用ADB命令进行网络连接以及通过Monodevelop进行远程调试。同时,文章讲解了ADB命令的使用,特别是logcat命令在抓取和过滤日志中的应用,以及如何将日志保存到SD卡。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.首先在手机上开启USB调试功能,并安装驱动(这一步很多手机助手都可以完成)。

  2.用USB电缆连接手机和电脑。

  3.确保手机和电脑在一个局域网内,简单的说就是电脑和手机共用一个路由器,网段一样。

  4.打开电脑上CMD窗口,输入以下命令:

  adb tcpip 5555(该命令打开手机adb网络调试功能)

  正常情况下输入命令后控制台会出现回显

  restarting in TCP mode port: 5555

  打开手机查看手机的IP地址(不会请百度)假设手机的地址是192.168.1.x输入命令

  adb connect 192.168.1.x

  如果一切正常控制台会回显以下内容

  connected to 192.168.1.x:5555

  如果你想查看是否连接成功请输入以下内容

  adb devices

  控制台会回显连接的设备

  5.如果一切连接成功,请拔掉USB电缆,选择File->Build&Run,在编译之前要勾选上Development Build 和Script Debugging这两项(在build setting里面勾选不要忘记否则是不能调试的)电脑会自动编译文件并将APK推送至手机,在手机上同意并安装。

  6.当程序运行后再Monodevelop里面打开Run->Attach to process 会发现你手机的选项,选择手机,在脚本里面添加断点,你发现可以调试了,那叫一个爽!出现问题再也不用去瞎猜,或者添加Debuglog了。


开发过程中,解决各种问题bug,不管是性能问题还是ANR问题,还是各种严重崩溃问题,经常需要抓取log,从log中分析找到问题源头,并进行修改。

但是,统一时间点下,可能会有很多log打印出来,分属于各个不同的进程。因此,我们需要的部分可能已经被淹没了。因此,使用工具或者命令抓取需要的log部分,并尽可能少的减少遗漏,是非常有必要的。

通常情况下,可以使用工具。

因此,使用命令抓取变得很重要,这里就自己总结下adb相关的命令。

比如eclipse 的logcat可以直接查看log输出,但是有个问题就是在手机设备没有连接的情况下,是很恼火的。比如我需要开机log,可以直接使用adb抓取到txt文件中就OK了。google的同时自己整理了一下。不喜勿喷。


adb logcat 命令使用帮助说明;

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
logcat: option requires an argument -- v
Unrecognized Option
Usage: logcat [options] [filterspecs]
options include:
   -s              Set default filter to silent.
                   Like specifying filterspec '*:s'
   -f <filename>   Log to file. Default to stdout
   -r [<kbytes>]   Rotate log every kbytes. ( 16 if unspecified). Requires -f
   -n <count>      Sets max number of rotated logs to <count>, default 4
   -v <format>     Sets the log print format, where <format> is one of:
 
                   brief process tag thread raw time threadtime long
 
   -c              clear (flush) the entire log and exit
   -d              dump the log and then exit (don't block)
   -t <count>      print only the most recent <count> lines (implies -d)
   -g              get the size of the log's ring buffer and exit
   -b <buffer>     Request alternate ring buffer, 'main' , 'system' , 'radio'
                   or 'events' . Multiple -b parameters are allowed and the
                   results are interleaved. The default is -b main -b system.
   -B              output the log in binary
filterspecs are a series of
   <tag>[:priority]
 
where <tag> is a log component tag (or * for all) and priority is:
   V    Verbose
   D    Debug
   I    Info
   W    Warn
   E    Error
   F    Fatal
   S    Silent (supress all output)
 
'*' means '*:d' and <tag> by itself means <tag>:v
 
If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.
If no filterspec is found, filter defaults to '*:I'
 
If not specified with -v, format is set from ANDROID_PRINTF_LOG
or defaults to "brief"
</tag></tag></tag></tag></buffer></count></count></format></format></count></count></kbytes></filename>


抓取log之前先清除缓存的log信息。

?
1
2
appledeMacBook-Pro:~ apple$ adb logcat -c
appledeMacBook-Pro:~ apple$

或者你可以这样写

?
1
2
3
4
5
appledeMacBook-Pro:~ apple$ adb logcat -c && adb logcat
--------- beginning of /dev/log/main
E/cynicok ( 16917 ): receive a heartbeat msg: H!
I/Wisdom_ConnectSdk( 16917 ): request long connection success and the state = 200
I/Wisdom_ConnectSdk( 16917 ): receive the heart message H


这样查看晕死。。。。
?
1
2
3
4
5
6
7
8
9
10
11
12
13
appledeMacBook-Pro:~ apple$ adb logcat
--------- beginning of /dev/log/main
D/AppOps  ( 1989 ): startOperation: allowing code 40 uid 1000 package android
D/NtpTrustedTime( 1989 ): currentTimeMillis() cache hit
--------- beginning of /dev/log/system
D/PowerManagerService( 1989 ): newScreenState = 0
D/PowerManagerService( 1989 ): updateDisplayPowerStateLocked:  mBootCompleted = true , mScreenBrightnessSettingDefault = 165
D/PowerManagerService( 1989 ): updateDisplayPowerStateLocked:  xxxx = 187
D/PowerManagerService( 1989 ): Package Lib: shouldUseProximitySensorLocked mLidMode = false
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值