Using Profiler in Unity for Android remote debugging

Using Profiler in Unity for Android remote debugging

In the past two days, I have studied the Profiler to remotely debug Android, check the memory and CPU usage, etc. I have actually studied it, but I forgot it after a long time, so write an article to record it, so as to avoid repeated mining next time.

Some articles on the Internet are written more clearly, such as this one . Basically, it is not a big problem to follow suit. My article is mainly to make a record, and I also add some conclusions of my own. At the same time, I am also afraid that other people’s articles will disappear, and Anyway, it's good to go through it yourself.

Implementation principle analysis

The principle is actually very simple. If some students have used AndroidStudio at ordinary times, they should be familiar with the adb command. The whole debugging process is actually based on adb, and then monitors the fixed port.

adb is equivalent to a debugging server, which receives and analyzes the processing process of the app. For details, please refer to Google's official documentation .

Unity's Profiler is just a message distributed on a fixed port after adb receives and analyzes it.

Personally, I think it is more important to understand this principle. If you just follow the articles on the Internet or the official Unity documents, there are some inexplicable problems that cannot be solved independently in practice, especially problems such as port occupation.

practice process

For the detailed process, please refer to the above article, I just make a simple record here.

Just create a project and enter BuildingSetting, then switch to the Android platform, and then check it according to the icon.

insert image description here

There are a few points to explain:

  • It is necessary to set up paths such as SDK and JDK in Unity Preference in advance
  • Set the Package Name in PlayerSetting, which will be used later
  • What I didn’t check here is Export Project instead of the officially recommended Build And Run, because direct construction is prone to problems, especially after the domestic network is blocked, it will cause various problems in Gradle, so it is recommended to use it alone after exporting the project AndroidStudio to build
  • The Autoconnect Profiler is not checked here, because it is easy to cause problems if it is connected by itself, but if the adb channel does not appear in the Profiler later, you can check it first, and the impact will not be great

After exporting, you can run it directly on the emulator (such as the thunderbolt simulator) through AndroidStudio. You don’t need to run it on the real machine. Of course, it’s okay if you want to run it on the real machine.

As long as you open the Profiler after the export is complete, it will appear AndroidPlayer([email protected]:34999), run the game (on the emulator), and you can see the running status after selecting here. As shown below:

insert image description here

Finally, you can happily debug the game according to the usual way of using the Profiler under the Editor to debug the game.

Of course, the above process is recommended by the official website. In most cases, you can’t really receive debugging information by following this process. Generally, you will only see that it does not move, but you are stunned.

So we still need some small operations, open the command line (or powershell), and execute the following commands:

adb kill-server # 关闭adb调试服务器
adb start-server # 开启adb调试服务器
# * daemon not running; starting now at tcp:5037
# * daemon started successfully
# 看到上面的打印代表调试服务器启动成功了
adb forward tcp:34999 localabstract:Unity-com.ilclpj.remote # 监听adb的34999端口, 并把app绑定到该端口, 前面都是固定的, 这里com.ilclpj.remote是你的Package Name, 就是PlayerSetting里面设置的那个
# 这条命令只要没报错, 就代表监听成功了, 一般在上面直接重启了服务器, 这里应该不会报错
# 如果真的报错了, 那么就参考上面那篇文章, 主体思路就是解开adb调试服务器的端口占用, 然后重启服务器而已
# 我原先按照上面文章去做的, 后面发现直接重启服务器就行了, 如果各位同学出现其它问题, 就按照这个思路去探索吧

Then restart Unity, then open Profiler, and select AndroidPlayer to see the information. Some Unity versions do not need to be restarted. Here I am using 2017, which is relatively old, so it needs to be restarted. You can open Profiler to have a look, and restart if there is no information also.

Finally, I would like to mention that the 34999 port here (Unity5.x is 54998 or the like) seems to be fixed. I have tried to change to other ports, but it has not been successful. I hope that knowledgeable students can give me advice.

Well, that's all for today, I hope it will be helpful to everyone.

Guess you like

Origin blog.csdn.net/woodengm/article/details/122862020