Sonic开源的云真机测试平台搭建三:Mac上部署Agent端
前提场景:
本地机器为Mac系统,官方提示仅Ubuntu系统可以使用Docker方式部署,所以本机使用jar方式进行部署
该方式将在Mac系统上以本地jar包部署Sonic的Agent端和Appium等环境
步骤:
0、很多JDK出现不兼容的问题,Sonic官方推荐使用JDK15,可以前往 https://docs.aws.amazon.com/corretto/latest/corretto-15-ug/downloads-list.html 下载JDK15版本
1、从部署好的前端界面【设备中心】的【Agent中心】新增Agent,记录Agent的Key
2、将安卓SDK设置到系统环境变量,命名为ANDROID_HOME。打开SDKManager,下载 platform-tools。确保platform-tools目录存在,adb指令可用
3、将ANDROID_HOME、ANDROID_HOME/platform-tools添加到系统PATH中
4、选择Mac系统对应的平台zip,下载并解压到Sonic工作目录
5、赋予Sonic工作目录所有权限,然后确保解压后的mini、config、plugins文件夹与jar同级
6、修改config文件夹中 application-sonic-agent.yml 的配置信息,保存
1) application-sonic-agent.yml文件的初始信息:
2) 修改之后的信息
sonic: agent: # 替换为部署Agent机器的ipv4 host: XXX.XXX.XXX.XXX # 替换为Agent服务的端口,可以自行更改 port: 7777 # 替换为前端新增Agent生成的key key: 5aa13292-b9a8-408c-a091-d784d1f37472 server: # 改成server的SONIC_SERVER_HOST host: XXX.XXX.XXX.XXX # 改成server的SONIC_SERVER_PORT port: 3000 modules: android: # 是否开启安卓模块 enable: true # 是否开启sonic-android-supply远程adb调试功能 use-sas: true ios: # 如果不需要连接iOS设备,请将true改为false。开启的windows用户请确保本机已安装iTunes enable: false # 替换为你自己使用的wda的bundleId,如果没有.xctrunner后缀会自动补全,建议使用公司的开发者证书 wda-bundle-id: com.sonic.WebDriverAgentRunner sgm: # 是否开启sonic-go-mitmproxy网络抓包功能 enable: true
7、在Sonic工作目录下执行以下命令
java -Dfile.encoding=utf-8 -jar sonic-agent-macosx-x86_64.jar
一直在报错!!!!
报错一:
1、当jdk1.8时,报错如下:
XXX-MacBook-Pro:sonic-agent-v2.1.2-macosx_x86_64 chunyanzhang$ java -Dfile.encoding=utf-8 -jar sonic-agent-macosx-x86_64.jar Exception in thread "main" java.lang.UnsupportedClassVersionError: org/cloud/sonic/agent/AgentApplication has been compiled by a more recent version
of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:756) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:468) at java.net.URLClassLoader.access$100(URLClassLoader.java:74) at java.net.URLClassLoader$1.run(URLClassLoader.java:369) at java.net.URLClassLoader$1.run(URLClassLoader.java:363) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:362) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46) at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) XXX-MacBook-Pro:sonic-agent-v2.1.2-macosx_x86_64 chunyanzhang$ java -version java version "1.8.0_271" Java(TM) SE Runtime Environment (build 1.8.0_271-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
2、当jdk11时,报错如下
XXX-MacBook-Pro:sonic-agent-v2.1.2-macosx_x86_64 chunyanzhang$ java -version java version "11.0.2" 2019-01-15 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode) XXX-MacBook-Pro:sonic-agent-v2.1.2-macosx_x86_64 chunyanzhang$ java -Dfile.encoding=utf-8 -jar sonic-agent-macosx-x86_64.jar Exception in thread "main" java.lang.UnsupportedClassVersionError: org/cloud/sonic/agent/AgentApplication has been compiled by a more recent version
of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 55.0 at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016) at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174) at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:550) at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458) at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588) at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:398) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46) at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
当前看来,是和jdk版本有直接关系,明天从官网推荐地址下载JDK15版本再次尝试
3、当切换成官网推荐的JDK15后(amazon-corretto-15.0.2.7.1-macosx-x64.pkg),执行成功,啊啊啊啊啊开心
XXX-MacBook-Pro:sonic-agent-v2.1.2-macosx_x86_64 chunyanzhang$ ls -l total 217552 drwxr-xr-x@ 3 chunyanzhang wheel 96 12 18 01:05 config drwxr-xr-x@ 7 chunyanzhang wheel 224 12 17 22:50 mini drwxr-xr-x@ 9 chunyanzhang wheel 288 12 17 22:50 plugins -rw-r--r--@ 1 chunyanzhang wheel 111383102 12 17 22:50 sonic-agent-macosx-x86_64.jar XXX-MacBook-Pro:sonic-agent-v2.1.2-macosx_x86_64 chunyanzhang$ java -Dfile.encoding=utf-8 -jar sonic-agent-macosx-x86_64.jar ▄▄▄▄ ▄▄▄▄ ▄▄▄ ▄▄ ▄▄▄▄▄▄ ▄▄▄▄ ▄█▀▀▀▀█ ██▀▀██ ███ ██ ▀▀██▀▀ ██▀▀▀▀█ ██▄ ██ ██ ██▀█ ██ ██ ██▀ ▀████▄ ██ ██ ██ ██ ██ ██ ██ ▀██ ██ ██ ██ █▄██ ██ ██▄ █▄▄▄▄▄█▀ ██▄▄██ ██ ███ ▄▄██▄▄ ██▄▄▄▄█ ▀▀▀▀▀ ▀▀▀▀ ▀▀ ▀▀▀ ▀▀▀▀▀▀ ▀▀▀▀ Author: SonicCloudOrg https://github.com/SonicCloudOrg 2022-12-18 13:24:39.621 - INFO 67905 --- [main] org.cloud.sonic.agent.AgentApplication : Starting AgentApplication v2.1.2 using Java 15.0.2 on XXX-MacBook-Pro.local with
PID 67905 (/usr/local/sonic/sonic-agent-v2.1.2-macosx_x86_64/sonic-agent-macosx-x86_64.jar started by chunyanzhang in /usr/local/sonic/sonic-agent-v2.1.2-macosx_x86_64) 2022-12-18 13:24:39.627 - INFO 67905 --- [main] org.cloud.sonic.agent.AgentApplication : The following profiles are active: sonic-agent WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (jar:file:/usr/local/sonic/sonic-agent-v2.1.2-macosx_x86_64/sonic-agent-macosx-x86_64.jar!/BOOT-INF/lib/groovy-2.5.15.jar!/)
to method java.lang.Object.finalize() WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release 2022-12-18 13:24:46.241 - INFO 67905 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 7777 (http) 2022-12-18 13:24:46.287 - INFO 67905 --- [main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-12-18 13:24:46.288 - INFO 67905 --- [main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.53] 2022-12-18 13:24:46.634 - INFO 67905 --- [main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-12-18 13:24:46.635 - INFO 67905 --- [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5408 ms ===================== Checking the Environment ===================== 👉 Check ANDROID_HOME Path Pass ✔ 👉 Check ADB env Pass ✔ 👉 Check local resource Pass ✔ =========================== Check results =========================== ANDROID_HOME: /Users/chunyanzhang/Library/Android/sdk ADB path: /Users/chunyanzhang/Library/Android/sdk/platform-tools/adb ADB version: Android Debug Bridge version 1.0.41 Version 33.0.3-8952118 Installed as /Users/chunyanzhang/Library/Android/sdk/platform-tools/adb System: mac os x ========================== Check Completed ========================== 2022-12-18 13:24:49.954 - INFO 67905 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 7777 (http) with context path '' 2022-12-18 13:24:50.207 - INFO 67905 --- [main] o.c.s.a.b.a.AndroidDeviceBridgeTool : Android devices listening... 2022-12-18 13:24:50.254 - INFO 67905 --- [Device List Monitor] o.c.s.a.b.a.AndroidDeviceStatusListener : Android device: PJNFXKLBWS4XGUSG ONLINE! 2022-12-18 13:24:51.226 - INFO 67905 --- [main] o.c.s.a.b.a.AndroidDeviceBridgeTool : Enable Android Module 2022-12-18 13:24:51.267 - INFO 67905 --- [main] o.c.s.agent.tests.handlers.StepHandlers : Registered 5 condition handler(s) 2022-12-18 13:24:51.297 - INFO 67905 --- [main] org.cloud.sonic.agent.AgentApplication : Started AgentApplication in 18.624 seconds (JVM running for 20.151) 2022-12-18 13:24:51.760 - INFO 67905 --- [Thread-1] org.cloud.sonic.agent.tools.LaunchTool : Generating ca file... 2022-12-18 13:24:56.784 - INFO 67905 --- [Thread-1] org.cloud.sonic.agent.tools.LaunchTool : init sonic-go-mitmproxy-ca Successful! 2022-12-18 13:26:16.395 - INFO 67905 --- [WebSocketConnectReadThread-36] o.c.s.agent.transport.TransportClient : Operation timed out 2022-12-18 13:26:16.400 - INFO 67905 --- [WebSocketConnectReadThread-36] o.c.s.agent.transport.TransportClient : Server disconnected. Retry in 10s... 2022-12-18 13:26:26.330 - INFO 67905 --- [WebSocketConnectReadThread-38] o.c.s.agent.transport.TransportClient : Operation timed out 2022-12-18 13:26:26.346 - INFO 67905 --- [WebSocketConnectReadThread-38] o.c.s.agent.transport.TransportClient : Server disconnected. Retry in 10s... 2022-12-18 13:26:36.324 - INFO 67905 --- [WebSocketConnectReadThread-41] o.c.s.agent.transport.TransportClient : Operation timed out 2022-12-18 13:26:36.328 - INFO 67905 --- [WebSocketConnectReadThread-41] o.c.s.agent.transport.TransportClient : Server disconnected. Retry in 10s... 2022-12-18 13:26:46.330 - INFO 67905 --- [WebSocketConnectReadThread-43] o.c.s.agent.transport.TransportClient : Operation timed out 2022-12-18 13:26:46.333 - INFO 67905 --- [WebSocketConnectReadThread-43] o.c.s.agent.transport.TransportClient : Server disconnected. Retry in 10s... 2022-12-18 13:26:56.327 - INFO 67905 --- [WebSocketConnectReadThread-45] o.c.s.agent.transport.TransportClient : Operation timed out 2022-12-18 13:26:56.330 - INFO 67905 --- [WebSocketConnectReadThread-45] o.c.s.agent.transport.TransportClient : Server disconnected. Retry in 10s... ^C2022-12-18 13:26:58.997 - INFO 67905 --- [SpringContextShutdownHook] org.cloud.sonic.agent.tools.LaunchTool : Release done! XXX-MacBook-Pro:sonic-agent-v2.1.2-macosx_x86_64 chunyanzhang$
还在报错,但是JDK问题确实解决了,开心
当前服务器连接失败是因为Server当前使用http://42.192.225.230:3000/没有办法正常访问,所以服务器连接失败,而且还有相关组件还没有安装成功,得继续努力,,继续排查问题,加油