You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Patrol 3.6.1执行app:connectedDebugAndroidTest任务失败求助

问题描述

复现步骤

  • 克隆测试项目
  • 启动Pixel_3a_API_33模拟器
  • 执行Patrol测试命令:patrol test -t integration_test/example_test.dart --verbose

实际结果

错误截图

初始化Patrol项目时遇到错误,提示app:connectedDebugAndroidTest,且错误详情为空。

已尝试的排查步骤

  • 按照官方入门指南初始化Patrol项目,错误依旧
  • 创建全新Flutter项目模板测试,错误输出完全一致,具体错误日志如下:
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:connectedDebugAndroidTest'.
See the report at: file:///D:/Project/latihan/test%20patrol/test_patrol/build/app/reports/androidTests/connected/index.html    

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 12s
: > Task :app:connectedDebugAndroidTest FAILED
: 85 actionable tasks: 5 executed, 80 up-to-date
✗ Failed to execute tests of apk with entrypoint test_bundle.dart on emulator-5554 
(Gradle test execution failed with code 1) (12.9s)
Exception: Gradle test execution failed with code 1
#0      AndroidTestBackend.execute.<anonymous closure> 
(package:patrol_cli/src/android/android_test_backend.dart:140:9)
#1      DisposeScope.run (package:dispose_scope/src/dispose_scope.dart:46:7)
<asynchronous suspension>
#2      AndroidTestBackend.execute 
(package:patrol_cli/src/android/android_test_backend.dart:106:5)
<asynchronous suspension>
#3      TestCommand._execute (package:patrol_cli/src/commands/test.dart:323:7)
<asynchronous suspension>
#4      TestCommand.run (package:patrol_cli/src/commands/test.dart:215:23)
<asynchronous suspension>
#5      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#6      PatrolCommandRunner.runCommand 
(package:patrol_cli/src/runner/patrol_command_runner.dart:347:18)
<asynchronous suspension>
#7      PatrolCommandRunner.run 
(package:patrol_cli/src/runner/patrol_command_runner.dart:291:18)
<asynchronous suspension>
#8      patrolCommandRunner 
(package:patrol_cli/src/runner/patrol_command_runner.dart:70:20)
<asynchronous suspension>
#9      main 
(file:///C:/Users/myUser/AppData/Local/Pub/Cache/hosted/pub.dev/patrol_cli- 
2.7.0/bin/main.dart:6:20)
<asynchronous suspension>

See the logs above to learn what happened. Also consider running with --verbose. If 
the logs still aren't useful, then it's a bug - please report it.
Uninstalling com.example.myapp from sdk gphone64 x86 64
Uninstalling com.example.myapp.test from sdk gphone64 x86 64

环境信息

  • Patrol版本:patrol: ^3.6.1
  • Patrol Doctor输出:
Patrol doctor:
Patrol CLI version: 2.7.0
Flutter command: flutter 
  Flutter 3.19.6 • channel stable
Android:
• Program adb found in C:\Users\XPERTSPEDIA\Downloads\scrcpy-win64-v1.24\adb.exe
• Env var $ANDROID_HOME set to C:\Users\XPERTSPEDIA\AppData\Local\Android\Sdk
  • Flutter Doctor输出(使用VS Code运行Flutter应用):
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [Version 10.0.19045.4291], locale en-ID)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[!] Android Studio (version 2021.2)
    X Unable to determine bundled Java version.
[√] Android Studio (version 2022.3)
[√] VS Code (version 1.88.1)
[√] Connected device (4 available)
[√] Network resources

解决方案尝试

1. 查看详细测试报告

打开错误提示中的测试报告路径:file:///D:/Project/latihan/test%20patrol/test_patrol/build/app/reports/androidTests/connected/index.html,浏览器中会展示具体失败原因,比如测试类加载异常、设备权限问题或连接故障。

2. 修复Java环境

Flutter Doctor提示旧版Android Studio无法识别捆绑Java版本,建议:

  • 卸载2021.2版本Android Studio,仅保留2022.3版本
  • 确认JAVA_HOME环境变量指向Android Studio自带JDK路径(可在Android Studio的File > Project Structure > SDK Location查看)

3. 调整ADB路径

将Android SDK自带的ADB路径(C:\Users\XPERTSPEDIA\AppData\Local\Android\Sdk\platform-tools\adb.exe)移到系统环境变量PATH最前端,避免第三方ADB版本冲突。

4. 清理重建项目

执行以下命令清理缓存后重新测试:

flutter clean
flutter pub get
patrol test -t integration_test/example_test.dart --verbose --stacktrace

添加--stacktrace参数可获取Gradle执行的详细栈信息,定位具体失败点。

5. 检查模拟器状态

  • 重启Pixel_3a_API_33模拟器,确保完全启动无卡顿
  • 执行adb devices确认模拟器正常连接
  • 尝试创建API 34版本的新模拟器测试,排除旧模拟器兼容性问题

6. 降级Patrol版本

当前Patrol 3.6.1与Flutter 3.19.6可能存在兼容性问题,修改pubspec.yaml依赖为:

patrol: ^3.5.0

执行flutter pub get后重新测试。


内容的提问来源于stack exchange,提问作者Alifa Al Farizi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 17:44:57