NativeAutomatorClientException: markPatrolAppServiceReady() failed with Invalid response: 501 - update
I am reopening this issue, since github bot closed the issue while I was on vacation. Anyway, I am reopening this issue, since I spent time on debugging and finally resolved the issue. Original issue: https://github.com/leancodepl/patrol/issues/2737
The issue was version of ktor, wince Patrol uses 2.* and we used ktor 3.* due to some reasons because of home screen widget. There is also this PR https://github.com/leancodepl/patrol/pull/2645 which also updates ktor to 3 for patrol.
For several weeks/months our Patrol does not work and we cannot figure why. We are not sure what changed. We investigated logs and found out that it fails on markPatrolAppServiceReady().
Steps to reproduce
- run patrol in terminal fvm exec patrol test -t integration_test/login/login_and_delete_test.dart --verbose --flavor dev
- emulator is stuck in "test starting..." state
Actual results
Server seems to start, but then it fails on NativeAutomatorClientException: markPatrolAppServiceReady() failed with Invalid response: 501.
Logs
...
: > Task :app:mergeProjectDexDevDebugAndroidTest UP-TO-DATE
: > Task :app:mergeDevDebugAndroidTestJniLibFolders UP-TO-DATE
: > Task :app:mergeDevDebugAndroidTestNativeLibs NO-SOURCE
: > Task :app:stripDevDebugAndroidTestDebugSymbols NO-SOURCE
: > Task :app:validateSigningDevDebugAndroidTest UP-TO-DATE
: > Task :app:writeDevDebugAndroidTestSigningConfigVersions UP-TO-DATE
: > Task :app:mergeLibDexDevDebugAndroidTest UP-TO-DATE
: > Task :app:packageDevDebugAndroidTest UP-TO-DATE
: > Task :app:createDevDebugAndroidTestApkListingFileRedirect UP-TO-DATE
: > Task :app:connectedDevDebugAndroidTest
09-18 10:24:28.755 32018 32018 I MonitoringInstr: Instrumentation started!
09-18 10:24:28.764 32018 32018 I PatrolServer: --------------------------------
09-18 10:24:28.764 32018 32018 I PatrolServer: PatrolJUnitRunner.onCreate() (initial run)
09-18 10:24:28.806 32018 32065 I PatrolServer: PatrolJUnitRunner.setUp(): activityClass = com.myapp.dummy
09-18 10:24:28.809 32018 32065 I PatrolServer: Starting server...
09-18 10:24:28.940 32018 32065 I PatrolServer: Created and started PatrolServer, port: 8081
09-18 10:24:28.985 32018 32065 I PatrolServer: Created PatrolAppServiceClient: http://localhost:8082/
09-18 10:24:28.986 32018 32065 I PatrolServer: PatrolJUnitRunner.setUp(): Waiting for PatrolAppService to report its readiness...
09-18 10:24:30.932 32018 32018 I flutter : Patrol (native): NativeAutomatorClient created, port: 8081
09-18 10:24:30.933 32018 32018 I flutter : Patrol (native): initialize() started
09-18 10:24:31.176 32018 32047 I PatrolServer: POST /initialize started
09-18 10:24:31.251 32018 32047 I PatrolServer: POST /initialize took 60 ms
09-18 10:24:31.747 32018 32018 I flutter : Patrol (native): initialize() succeeded
09-18 10:24:31.781 32018 32018 I flutter : PatrolBinding: Register Patrol service extensions
09-18 10:24:31.790 32018 32018 I flutter : Patrol (native): NativeAutomatorClient created, port: 8081
09-18 10:24:31.791 32018 32018 I flutter : Patrol (native): NativeAutomatorClient created, port: 8081
09-18 10:24:31.801 32018 32018 I flutter : PATROL_LOG {"timestamp":"2025-09-18T10:24:31.790321","type":"config","config":{"printLogs":true}}
09-18 10:24:31.808 32018 32018 I flutter : 00:00 +0: patrol_test_explorer
09-18 10:24:31.815 32018 32018 I flutter : patrol_test_explorer: obtained Dart-side test hierarchy:
09-18 10:24:31.830 32018 32018 I flutter : PatrolAppService started, address: 0.0.0.0, host: 0.0.0.0, port: 8082
09-18 10:24:31.830 32018 32018 I flutter : Patrol (native): markPatrolAppServiceReady() started
09-18 10:24:31.873 32018 32018 I flutter : Patrol (native): markPatrolAppServiceReady() failed
09-18 10:24:31.876 32018 32018 E flutter : [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Patrol action failed: NativeAutomatorClientException: markPatrolAppServiceReady() failed with Invalid response: 501
09-18 10:24:31.876 32018 32018 E flutter : #0 NativeAutomator._wrapRequest (package:patrol/src/native/native_automator.dart:253:7)
09-18 10:24:31.876 32018 32018 E flutter : #1 NativeAutomator.markPatrolAppServiceReady (package:patrol/src/native/native_automator.dart:1072:5)
09-18 10:24:32.014 32018 32018 I flutter : PatrolAppService: registered "login.login_and_delete_test User can login and then delete the profile"
Patrol version
patrol_cli: 3.10.0 patrol: 3.19.0
Patrol Doctor output
Patrol Doctor output
Patrol doctor:
Patrol CLI version: 3.10.0
Flutter command: flutter
Flutter 3.35.2 • channel stable
Android:
• Program adb found in /Users/tenhobi/Library/Android/sdk/platform-tools/adb
• Env var $ANDROID_HOME set to /Users/tenhobi/Library/Android/sdk
iOS / macOS:
• Program xcodebuild found in /usr/bin/xcodebuild
• Program ideviceinstaller found in /opt/homebrew/bin/ideviceinstaller
Flutter Doctor output
Flutter Doctor output
fvm flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.35.2, on macOS 15.6.1 24G90 darwin-arm64, locale en-CZ)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 26.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.103.2)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!
Since issues with ktor version are not mentioned, and probably in the future there will be update to ktor 3 even for this package -- see i.e. https://github.com/leancodepl/patrol/pull/2645. So people having old ktor after this update might also see this issue, so some note maybe somewhere might help?
Not sure whether right now we can make Patrol work if we use ktor 3?
I am mentioning people from previous task: @zoskar, @piotruela
And for anyone wondering, we fixed the version mismatch for out ktor client for home widget and patrol using this
configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == "io.ktor") {
details.useVersion "3.0.3"
details.because "Force unify Ktor versions (fix ByteChannel$default error)"
}
}
}
And in the end we are using 3.0.3 to make it work.