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

使用patrol develop无法启动并连接Flutter(Android)应用求助

Patrol Develop热重载失败:应用未启动且提示“not attached to the app yet”

问题描述

使用patrol develop命令尝试实现热重载时,APK构建成功但应用从未在模拟器启动,控制台持续提示[WARN] Hot Restart: not attached to the app yet。无论是否添加--flavor=dev参数,问题都存在,且已按官方文档完成Android环境配置、Flavor设置,并参考官方示例配置了common.dart。

执行命令及输出:

❯ patrol develop -t integration_test/initial_test.dart  --device=emulator-5554 --flavor=dev

• Building apk with entrypoint test_bundle.dart...
✓ Completed building apk with entrypoint test_bundle.dart (50.1s)
• Executing tests of apk with entrypoint test_bundle.dart on emulator-5554...
Hot Restart: logs connected
[WARN] Hot Restart: not attached to the app yet

测试代码:

import 'common.dart';

void main() {
  patrolSetUp(() {
    expect(2 + 2, equals(4));
  });

  patrol('Initial test', ($) async {
    await createApp($);

    await $('Continue with English').tap();
    expect($('Get Started'), findsOneWidget);
    await $('Get Started').tap();
  });
}

排查与解决步骤

  • 确认设备连接有效性

    1. 执行adb devices查看模拟器状态,确保emulator-5554处于device状态,而非offline
    2. 若设备状态异常,重启adb服务:adb kill-server → adb start-server,之后重新启动模拟器并运行命令
  • 验证Flavor与Android配置

    1. 检查dev flavor对应的AndroidManifest.xml,确认主Activity的配置正确,且测试相关的入口(如PatrolTestRunner)已注册
    2. 核对build.gradle中的flavor配置,确保dev flavor的applicationId与测试bundle的配置完全匹配
  • 检查Patrol初始化逻辑
    确认common.dart中的createApp函数正确启动了应用入口,比如是否调用了$.app.main(),或者是否正确初始化了应用的根Widget

  • 清理构建缓存

    1. 执行flutter clean清空Flutter缓存
    2. 删除android/build目录
    3. 重新执行patrol develop命令,避免缓存导致的构建异常
  • 验证基础测试功能
    先跳过热重载,执行patrol test -t integration_test/initial_test.dart --device=emulator-5554 --flavor=dev,若该命令也无法启动应用,说明是基础集成问题,需重新检查Patrol的native端集成步骤

  • 切换Patrol版本
    若使用的是最新开发版,尝试降级到稳定版本,修改pubspec.yaml中的patrol依赖版本后执行flutter pub get,再重新测试

内容的提问来源于stack exchange,提问作者Ashwin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 18:02:36