简体   繁体   English

无法在 android 设备上调试 Unity 应用程序/调试和分析器无法正确连接到手机

[英]No abbility to debug Unity app on the android device / Debug and profiler cannot connect to the phone correctly

My problems is:我的问题是:

  • Profiler shows nothing; Profiler 什么也没显示;
  • Console shows nothing;控制台什么都不显示;
  • Debugging isn't possible;调试是不可能的;

And in the same time:同时:

  • debugging works well on "Run" in editor调试在编辑器中的“运行”上运行良好
  • I'm able to install app from Unity ("Debug and run")我可以从 Unity 安装应用程序(“调试并运行”)

What I have done:我做了什么:

  • On the phone I have enabled Debugging(checked checkboxes: "stay awake", "USB debugging", "Install via USB", "USB Debugging(Security settings)")在手机上,我启用了调试(选中复选框:“保持唤醒”、“USB 调试”、“通过 USB 安装”、“USB 调试(安全设置)”)
  • ADB usb driver is installed ADB USB 驱动已安装
  • "Revoke USB Debugging Access" also tried to press. “撤销USB调试访问”也试图按下。
  • Computer and phone restarted few times.电脑和手机重启了几次。
  • Unity build settings is: Development build; Autoconnect profiling; scripts debugging; Unity构建设置为: Development build; Autoconnect profiling; scripts debugging; Development build; Autoconnect profiling; scripts debugging; is enabled已启用
  • USB configured to PTP connection on the phone. USB 配置为手机上的 PTP 连接。 [But MTP I have also tried] 【但是MTP我也试过】
  • ADB can see the phone without any issues: ADB 可以毫无问题地看到电话:

    C:\\Users\\UKS2\\AppData\\Local\\Android\\Sdk\\platform-tools> adb devices List of devices attached a616d3d10204 device


Additional information:附加信息:

  • Result of "adb logcat -s Unity" from cmd shows full log from the phone in realtime;来自cmd的“adb logcat -s Unity”的结果实时显示手机的完整日志;
  • Visual Studio: Debug-> Attach Unity Debugger - shows only local PC, but not the phone Visual Studio: Debug-> Attach Unity Debugger - 只显示本地 PC,而不显示手机
  • In case of connetion via WiFi (but not USB cable) and manually configured IP adress如果通过 WiFi(但不是 USB 电缆)和手动配置的 IP 地址连接在此处输入图片说明 there is possible to look at device console log and to see profiler results.可以查看设备控制台日志并查看分析器结果。 BUT it's not possible to debug from the phone.但是无法通过手机进行调试。

What did I miss?我错过了什么?

I think that Unity for some reason trying to connect to the phone by some incorrect way/adress/port after app install.我认为 Unity 出于某种原因试图在应用程序安装后通过某种不正确的方式/地址/端口连接到手机。 But how to fix this?但是如何解决这个问题? And why it's have no problems in install app process in this case?为什么在这种情况下安装应用程序过程没有问题?

It's sounds like a joke.这听起来像个笑话。 Problem was in Firewall.问题出在防火墙上。

Few days with this problem I have think that Firewall is disabled on my computer.几天出现这个问题,我认为我的计算机上禁用了防火墙。

But it wasn't.但事实并非如此。

This works for iPhone too!这也适用于 iPhone!

Would like to add to the answer by Andrew, because it I couldn't realise the proper way to disable it entirely .想补充安德鲁的答案,因为我无法意识到完全禁用它的正确方法。 Disable the firewall like this:像这样禁用防火墙:

On Windows 10: Windows Defender Firewall with Advanced Security --> Overview --> Windows Defender Firewall Properties:在 Windows 10 上:具有高级安全性的 Windows Defender 防火墙 --> 概述 --> Windows Defender 防火墙属性:

在此处输入图片说明

In there I had to set Firewall State to 'off' for both Domain Profile, Private Profile and Public Profile tabs.在那里,我必须将域配置文件、私有配置文件和公共配置文件选项卡的防火墙状态设置为“关闭”。 (perhaps not all were needed, but was short on time, so didn't experiment). (也许不是所有都需要,但时间不够,所以没有试验)。 Disabling all can expose your pc, making it vulnerable.全部禁用可能会暴露您的电脑,使其容易受到攻击。

Also, double check that the wifi is enabled on the actual device (phone) and that you are connected to the same router as your computer.此外,请仔细检查实际设备(手机)上是否启用了 wifi,并且您是否连接到与计算机相同的路由器。 The USB wire between to PC wasn't enough!到 PC 之间的 USB 线是不够的!

Perhaps might be worth to launch your console in Administrator mode (I always do by default)也许值得以管理员模式启动您的控制台(默认情况下我总是这样做)

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

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