AirtestProject / Poco-SDK

https://github.com/AirtestProject/Poco
Apache License 2.0
283 stars 170 forks source link

UGUI项目打出的apk无法获取ui渲染树 #42

Open CodyGit opened 5 years ago

CodyGit commented 5 years ago

按照文档完成了pocosdk的接入

CodyGit commented 5 years ago

跪求大神解决,卡了很多天了。。。

yimelia commented 5 years ago

可以看一下命令行有没有报错信息的显示(IDE启动时附带的黑色的命令行窗口里)

CodyGit commented 5 years ago

我的都快绝望了,救世主来了,大佬请看下面的日志

[10:53:24][DEBUG]<airtest.core.android.minicap> update_rotation: 90
[10:53:24][DEBUG]<airtest.core.android.minicap> do update rotation
[10:53:24][DEBUG]<airtest.core.android.minicap> minicap stream ends
[10:53:24][DEBUG]<airtest.core.android.adb> D:\Software\AirtestIDE_2019-01-15_py3_win64\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s 3f863bf forward --remove tcp:18728
[10:53:24][DEBUG]<airtest.core.android.adb> D:\Software\AirtestIDE_2019-01-15_py3_win64\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s 3f863bf forward --no-rebind tcp:16292 localabstract:minicap_16292
[10:53:24][DEBUG]<airtest.core.android.adb> D:\Software\AirtestIDE_2019-01-15_py3_win64\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s 3f863bf shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -i
[10:53:24][DEBUG]<airtest.core.android.adb> D:\Software\AirtestIDE_2019-01-15_py3_win64\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s 3f863bf shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -n 'minicap_16292' -P 1920x1200@800x500/0 -l 2>&1
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'PID: 13155'
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: Using projection 1920x1200@800x500/0'
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_27.cpp:241) Creating SurfaceComposerClient'
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_27.cpp:244) Performing SurfaceComposerClient init check'
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_27.cpp:255) Creating virtual display'
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_27.cpp:261) Creating buffer queue'
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_27.cpp:264) Setting buffer options'
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_27.cpp:268) Creating CPU consumer'
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_27.cpp:272) Creating frame waiter'
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_27.cpp:276) Publishing virtual display'
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (jni/minicap/JpgEncoder.cpp:64) Allocating 6914052 bytes for JPG encoder'
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (/home/lxn3032/minicap_for_ide/jni/minicap/minicap.cpp:473) Server start'
[10:53:24][DEBUG]<airtest.core.android.minicap> (1, 24, 13155, 1920, 1200, 800, 500, 0, 2)
[10:53:24][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (/home/lxn3032/minicap_for_ide/jni/minicap/minicap.cpp:475) New client connection'
[10:53:47][DEBUG]<airtest.core.android.adb> D:\Software\AirtestIDE_2019-01-15_py3_win64\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s 3f863bf forward --no-rebind tcp:13357 tcp:5001
initializing Unity poco.
[rpc]connected
<poco.utils.simplerpc.simplerpc.Callback object at 0x00000231EE925A58> (rid=9bd4dbae-8348-4a37-a003-6328dc832cc2) (connection="tcp://127.0.0.1:13357")
CodyGit commented 5 years ago

@yimelia 大佬求看

yimelia commented 5 years ago

这个log看起来是连上了poco service的,但是看不到UI树吗?它应该会不断去连,后面有没有什么报错呢

TreHack commented 5 years ago

请问你们是通过unity打包的apk吗?打包apk的时候有没有什么特殊的操作?比如经过IL2CPP编译什么的?

CodyGit commented 5 years ago

@yimelia @TreHack 心里说不出的激动,两位大佬早,windows的的log就这些了,但是很奇怪的是我直接用unity的ide去跑,然后抓windows的窗口去获取ui树就可以。 我们是用unity直接出的apk,没有什么太骚的操作,使用了IL2CPP

TreHack commented 5 years ago

@CodyGit 你可以用adb logcat抓一下你们app运行时的log吗?https://juejin.im/post/5a17b4c16fb9a04528462b4c

TreHack commented 5 years ago

因为我们这边用untiy 打的apk出来都是正常的。看你上面贴的log也是正常的。

CodyGit commented 5 years ago

@TreHack T神 log在此,请查收 log.txt

TreHack commented 5 years ago
03-22 10:43:27.987 15606 15658 I Unity   : start server
03-22 10:43:27.987 15606 15658 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
03-22 10:43:27.987 15606 15658 I Unity   : UnityEngine.Logger:Log(LogType, Object)
03-22 10:43:27.987 15606 15658 I Unity   : TcpServer.AsyncTcpServer:Start()
03-22 10:43:27.987 15606 15658 I Unity   : PocoManager:Awake()
03-22 10:43:27.987 15606 15658 I Unity   :  
03-22 10:43:27.987 15606 15658 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/Android/runtime/DebugBindings.gen.cpp Line: 51)
03-22 10:43:27.987 15606 15658 I Unity   : 
03-22 10:43:27.989 15606 15658 I Unity   : Tcp server started and listening at 5001
03-22 10:43:27.989 15606 15658 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
03-22 10:43:27.989 15606 15658 I Unity   : UnityEngine.Logger:Log(LogType, Object)
03-22 10:43:27.989 15606 15658 I Unity   : PocoManager:Awake()
03-22 10:43:27.989 15606 15658 I Unity   :  
03-22 10:43:27.989 15606 15658 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/Android/runtime/DebugBindings.gen.cpp Line: 51)
03-22 10:43:27.989 15606 15658 I Unity   : 
03-22 10:43:27.991 15606 15658 I Unity   : start server
03-22 10:43:27.991 15606 15658 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
03-22 10:43:27.991 15606 15658 I Unity   : UnityEngine.Logger:Log(LogType, Object)
03-22 10:43:27.991 15606 15658 I Unity   : TcpServer.AsyncTcpServer:Start()
03-22 10:43:27.991 15606 15658 I Unity   : PocoManager:Awake()
03-22 10:43:27.991 15606 15658 I Unity   :  
03-22 10:43:27.991 15606 15658 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/Android/runtime/DebugBindings.gen.cpp Line: 51)
03-22 10:43:27.991 15606 15658 I Unity   : 
03-22 10:43:27.993 15606 15658 I Unity   : start server
03-22 10:43:27.993 15606 15658 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
03-22 10:43:27.993 15606 15658 I Unity   : UnityEngine.Logger:Log(LogType, Object)
03-22 10:43:27.993 15606 15658 I Unity   : TcpServer.AsyncTcpServer:Start()
03-22 10:43:27.993 15606 15658 I Unity   : PocoManager:Awake()
03-22 10:43:27.993 15606 15658 I Unity   :  
03-22 10:43:27.993 15606 15658 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/Android/runtime/DebugBindings.gen.cpp Line: 51)
03-22 10:43:27.993 15606 15658 I Unity   : 
03-22 10:43:27.995 15606 15658 I Unity   : Tcp server started and listening at 5002
03-22 10:43:27.995 15606 15658 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
03-22 10:43:27.995 15606 15658 I Unity   : UnityEngine.Logger:Log(LogType, Object)
03-22 10:43:27.995 15606 15658 I Unity   : PocoManager:Awake()
03-22 10:43:27.995 15606 15658 I Unity   :  
03-22 10:43:27.995 15606 15658 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/Android/runtime/DebugBindings.gen.cpp Line: 51)

看log是因为5001端口启动失败,然后又重新启动了5002端口,然而IDE默认是连的5001端口,我估计就是因为这个原因没有拿到树结构。 在本地可以这样来调试一下:1.手机通过adb连到本地电脑,打开你们的app。2,打开python命令行,执行以下几行代码(如果没有安装airtest和poco的话,麻烦按照官网教程安装一下)

from poco.drivers.unity3d.unity3d_poco import UnityPoco
poco1 = UnityPoco(('localhost', 5001), unity_editor=True)
print(poco1.agent.hierarchy.dump())

3.如果第二行代码的5001端口不行,就继续5002,或者5003或者5004或者5005,端口范围是(5001~5005)

IDE后续可能需要支持用户去改端口的功能

CodyGit commented 5 years ago

@TreHack 感谢T神 我先试试,现在对应的技术吃饭去了,一会再反馈给您。您也去吃饭把, 哈哈

CodyGit commented 5 years ago

@TreHack 我从5001~5005都尝试了,还是不行,报错如下 image

TreHack commented 5 years ago

额 搞错了 上面是连untiy的代码 用下面这段

from poco.drivers.unity3d.unity3d_poco import UnityPoco
ip = '你手机的ip地址'
poco1 = UnityPoco((ip, 5001))
print(poco1.agent.hierarchy.dump())

另外建议你先查一下你手机的5001端口有没有被其他程序占用。

CodyGit commented 5 years ago

@TreHack T神请看。

端口没有被占用

image

修改了端口,但是报链接超时 端口改成 5001~5003

image

改成5004时,又报了另一个错

image

TreHack commented 5 years ago

app启动了吗?

CodyGit commented 5 years ago

启动了

CodyGit commented 5 years ago

有什么日志可以看一下app里对应的poco的socket是可用的么?

TreHack commented 5 years ago

方便的话可以发个apk包给我们看看?

CodyGit commented 5 years ago

@TreHack 不太方便,是研发期的游戏。好尴尬。。

yimelia commented 5 years ago

如果用这个工具试试呢?在这里下载

TreHack commented 5 years ago

你这个问题应该就是端口的问题,ide支持下用户修改端口应该就可以了。 目前可以这样调试一下吧,在PocoManager.cs的72行https://github.com/AirtestProject/Poco-SDK/blob/ebb9e623faedebff1de712c4d0a563e9ac8fb329/Unity3D/PocoManager.cs#L72 加一个Debug语句Debug.Log (string.Format("Tcp server started failed {0}", e)); 重新打个apk包, 然后再取一下新包的adb logcat,看看为啥5001端口为启动失败!

CodyGit commented 5 years ago

@TreHack 求看


03-23 19:36:33.467  6829  6880 I Unity   : Tcp server started failed System.Net.Sockets.SocketException: Address already in use
03-23 19:36:33.467  6829  6880 I Unity   :   at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in <filename unknown>:0 
03-23 19:36:33.467  6829  6880 I Unity   :   at System.Net.Sockets.TcpListener.Start (Int32 backlog) [0x00000] in <filename unknown>:0 
03-23 19:36:33.467  6829  6880 I Unity   :   at TcpServer.AsyncTcpServer.Start (Int32 backlog) [0x00000] in <filename unknown>:0 
03-23 19:36:33.467  6829  6880 I Unity   :   at PocoManager.Awake () [0x00000] in <filename unknown>:0 
03-23 19:36:33.467  6829  6880 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
03-23 19:36:33.467  6829  6880 I Unity   : UnityEngine.Logger:Log(LogType, Object)
03-23 19:36:33.467  6829  6880 I Unity   : PocoManager:Awake()
03-23 19:36:33.467  6829  6880 I Unity   : 
TreHack commented 5 years ago

Tcp server started failed System.Net.Sockets.SocketException: Address already in use 看这句报错说明你手机里的5001端口被占了。查下你手机里什么程序占用了5001端口。

yushuang1206 commented 5 years ago

@TreHack 我们更换了端口,会报错,大神求看~~~ app日志如下~ 04-11 16:49:33.611 1211 1250 I Unity : PocoManager:Awake() 04-11 16:49:33.611 1211 1250 I Unity : 04-11 16:49:33.611 1211 1250 I Unity : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/Android/runtime/DebugBindings.gen.cpp Line: 51) 04-11 16:49:33.611 1211 1250 I Unity : 04-11 16:49:33.612 1211 1250 D Unity : Tcp server started and listening at 5002: 0 at /Users/builduser/buildslave/unity/build/artifacts/generated/Android/runtime/DebugBindings.gen.cpp:51 (17408, 0, 0) 04-11 16:49:33.613 1211 1250 I Unity : Tcp server started and listening at 5002 04-11 16:49:33.613 1211 1250 I Unity : UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object) 04-11 16:49:33.613 1211 1250 I Unity : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[]) 04-11 16:49:33.613 1211 1250 I Unity : UnityEngine.Logger:Log(LogType, Object) 04-11 16:49:33.613 1211 1250 I Unity : UnityEngine.Debug:Log(Object) 04-11 16:49:33.613 1211 1250 I Unity : PocoManager:Awake()

程序报错截图 image

CodyGit commented 5 years ago

@TreHack 抱歉T神,之前因为研发进度,所以这块就落下了。现在我们尝试在PocoManager中更换了端口到5002,脚本也对应的调整了。看了一下adb的日志 PocoManager 正常的启动了5002端口,但是这边还是导不出ui树。

brantxiong commented 4 years ago

@CodyGit 有空试下在PocoManager.cs 的 public class PocoManager : MonoBehaviour 中添加如下方法看看:

    void OnDestroy()
    {
        // stop listening thread
        stopListening();
    }

有可能是你那边挂载的GameObject一段时间后会被销毁,PocoManager 的 Server 没有释放之前的端口,继续尝试新的端口,导致端口一直在更换。