Unity 安卓真机DEBUG

1.首先在手机上开启USB调试功能,并安装驱动(这一步很多手机助手都可以完成)。  2.用USB电缆连接手机和电脑。  3.确保手机和电脑在一个局域网内,简单的说就是电脑和手机共用一个路由器,网段一样。  4.打开电脑上CMD窗口,输入以下命令:  adb tcpip 5555(该命令打开手机adb网络调试功能)  正常情况下输入命令后控制台会出现回显  restartin
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unity中进行安卓真机调试的步骤如下: 1. 首先,确保你已经安装了UnityAndroid SDK,并且已经将Android设备连接到电脑上。 2. 打开Unity项目,并在菜单栏中选择“Edit”(编辑)>“Preferences”(首选项)>“External Tools”(外部工具)。 3. 在“External Tools”(外部工具)面板中,找到“Android”部分,并确保已经正确设置了Android SDK的路径。 4. 在Unity中,选择“File”(文件)>“Build Settings”(构建设置)。 5. 在“Build Settings”(构建设置)面板中,选择“Android”作为目标平台,并点击“Switch Platform”(切换平台)按钮。 6. 点击“Player Settings”(播放器设置)按钮,打开“Player Settings”(播放器设置)面板。 7. 在“Player Settings”(播放器设置)面板中,展开“Other Settings”(其他设置)部分,并找到“Scripting Backend”(脚本后端)选项。 8. 将“Scripting Backend”(脚本后端)选项设置为“Mono”(单线程)。 9. 点击“Build and Run”(构建和运行)按钮,将Unity项目构建为安卓应用程序。 10. 将生成的安卓应用程序文件(.apk)传输到Android设备上。 11. 在Android设备上,打开“设置”应用程序,并找到“开发者选项”。 12. 在“开发者选项”中,启用“USB调试”选项。 13. 将Android设备连接到电脑上,并确保已经安装了正确的设备驱动程序。 14. 在Unity中,点击“Play”(播放)按钮,开始在安卓设备上进行调试。 请注意,以上步骤仅适用于使用MonoDevelop作为脚本编辑器的情况。如果你使用其他脚本编辑器,例如Visual Studio,你需要按照相应的文档进行设置和调试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值