Bitrise平台运行Appium测试遇会话创建失败、ADB超时如何解决
Bitrise平台Appium Android测试APK安装超时排查方案
核心报错定位
org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command '/usr/local/share/android-sdk/platform-tools/adb -P 5037 -s emulator-5554 install /Users/vagrant/git/appium/../../deploy/app-release.apk' timed out after 90000ms'. Try to increase the 90000ms adb execution timeout represented by 'androidInstallTimeout' capability
步骤1:排查环境变量配置
你写在.zprofile里的SDK路径配置完全不会在Bitrise构建流程中生效——Bitrise执行构建任务的shell为非登录式shell,不会加载~/.zprofile、~/.bash_profile这类用户登录态的配置文件,所以你自定义的ANDROID_HOME根本没有被加载。
当前报错日志里的adb路径已经是Bitrise默认的/usr/local/share/android-sdk/platform-tools/adb,说明adb本身的解析路径是正常的,不需要刻意修正路径匹配问题,只需要在构建脚本最前面显式声明环境变量,避免后续工具解析路径时出错:
- 在启动Appium测试的脚本开头添加如下配置,确保所有子进程都能读取到正确的SDK路径:
export ANDROID_HOME=/usr/local/share/android-sdk export PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/cmdline-tools/latest/bin:$PATH - 执行
which adb验证返回结果是否为/usr/local/share/android-sdk/platform-tools/adb,确认配置生效。
步骤2:调整超时参数适配CI环境性能
当前配置里的androidInstallTimeout值为90000ms(90秒),这个值是本地开发环境的常用配置,但Bitrise的共享CI机器性能、磁盘IO读写速度普遍低于本地设备,加上未优化压缩的APK体积偏大时,90秒的安装时间很容易达到阈值触发超时。
- 将
androidInstallTimeout和adbExecTimeout的配置值同步提升到300000(5分钟),避免两个超时配置不一致导致的流程中断:caps.setCapability("adbExecTimeout", 300000); caps.setCapability("androidInstallTimeout", 300000); - 报错提示里已经明确给出了超时调整的建议,不需要额外修改其他路径配置。
步骤3:校验APK文件路径有效性
当前代码里通过多层相对路径拼接APK的逻辑,在CI环境下很容易因为工作目录错位导致找不到文件,进而出现adb安装命令挂起超时:
- 在初始化driver前增加调试日志,打印最终拼接的APK绝对路径,确认文件真实存在且有可读权限:
String appURL = System.getProperty("user.dir") + File.separator + ".." + File.separator + ".." + File.separator + "deploy" + File.separator + "app-release.apk"; File apkFile = new File(appURL); System.out.println("APK 绝对路径:" + apkFile.getAbsolutePath()); System.out.println("APK 文件存在性校验:" + apkFile.exists()); - 如果路径校验返回不存在,直接替换为Bitrise构建流程中提前定义的APK输出绝对路径,不要再用多层
../的相对路径拼接。
步骤4:确认模拟器完全就绪后再执行测试
虽然你设置了avdLaunchTimeout为60000ms,但模拟器返回启动完成的信号不代表系统所有服务都就绪,此时直接执行adb安装命令会出现无响应卡死的情况:
- 模拟器启动后,增加系统就绪等待逻辑,直到检测到系统启动完成的标记后再初始化Appium driver:
adb wait-for-device until [ "$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" == "1" ]; do sleep 2 done - 移除
skipServerInstallation=true配置:这个配置会跳过UiAutomator2 Server的安装校验,当环境下Server版本和Appium服务版本不匹配时,会直接导致后续命令执行卡住超时。
内容的提问来源于stack exchange,提问作者Mharvey
相关产品推荐
相关产品推荐

