Tests for Android do not run in CodeMagic
Steps to reproduce
I'm trying to run my patrol tests in CodeMagic CI for Android.
Here is part of my configuration and error stack. I can't figure out what the problem is and how I can fix it. Please help. The tests did run once, but I can't figure out why this happened, since I didn't change anything.
- name: Install Patrol CLI
script: |
#!/usr/bin/env bash
dart pub global activate patrol_cli
- name: Launch Android emulator
script: |
#!/usr/bin/env bash
flutter emulators --launch emulator &
adb wait-for-device
echo "Android emulator launched"
- name: Run integration e2e tests android
script: |
#!/usr/bin/env bash
echo "Running Android integration e2e tests"
dart pub upgrade --directory=tools/builder
cd apps/app
patrol test -t integration_test/ --dart-define=BUILD_ENVIRONMENT=staging --dart-define="FLUTTER_TEST=true" --verbose
Actual results
StackTrace
• Building apk with entrypoint test_bundle.dart...
$ ./gradlew :app:assembleDevDebug -Ptarget=/home/builder/clone/apps/travelers/integration_test/test_bundle.dart -Pdart-defines=QlVJTERfRU5WSVJPTk1FTlQ9c3RhZ2luZw==,RkxVVFRFUl9URVNUPXRydWU=,UEFUUk9MX1dBSVQ9MA==,UEFUUk9MX0FQUF9QQUNLQUdFX05BTUU9cnUudHJpcHN0ZXIudHJpcHN0ZXI=,UEFUUk9MX0FQUF9CVU5ETEVfSUQ9cnUudHJpcHN0ZXIuVHJpcHN0ZXI=,UEFUUk9MX0FORFJPSURfQVBQX05BTUU9dHJhdmVsZXJz,UEFUUk9MX0lPU19BUFBfTkFNRT10cmF2ZWxlcnM=,SU5URUdSQVRJT05fVEVTVF9TSE9VTERfUkVQT1JUX1JFU1VMVFNfVE9fTkFUSVZFPWZhbHNl,UEFUUk9MX1RFU1RfTEFCRUxfRU5BQkxFRD10cnVl,UEFUUk9MX1RFU1RfU0VSVkVSX1BPUlQ9ODA4MQ==,UEFUUk9MX0FQUF9TRVJWRVJfUE9SVD04MDgy,Q09WRVJBR0VfRU5BQkxFRD1mYWxzZQ==,RkxVVFRFUl9BUFBfRkxBVk9SPWRldg== -Papp-server-port=8082 -Ptest-server-port=8081
✗ Failed to build apk with entrypoint test_bundle.dart (Gradle build failed with code 127) (11ms)
Exception: Gradle build failed with code 127
#0 AndroidTestBackend.build.<anonymous closure> (package:patrol_cli/src/android/android_test_backend.dart:81:9)
<asynchronous suspension>
#1 DisposeScope.run (package:dispose_scope/src/dispose_scope.dart:46:7)
<asynchronous suspension>
#2 AndroidTestBackend.build (package:patrol_cli/src/android/android_test_backend.dart:51:5)
<asynchronous suspension>
#3 TestCommand._build (package:patrol_cli/src/commands/test.dart:337:7)
<asynchronous suspension>
#4 TestCommand.run (package:patrol_cli/src/commands/test.dart:252:5)
<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:386:18)
<asynchronous suspension>
#7 PatrolCommandRunner.run (package:patrol_cli/src/runner/patrol_command_runner.dart:330:18)
<asynchronous suspension>
#8 patrolCommandRunner (package:patrol_cli/src/runner/patrol_command_runner.dart:76:20)
<asynchronous suspension>
#9 main (file:///home/builder/.pub-cache/hosted/pub.dev/patrol_cli-3.5.1/bin/main.dart:6:20)
<asynchronous suspension>
Logs
Logs
<!-- Replace this line with your logs. Do not remove the backticks! -->
Patrol version
patrol: ^3.14.1
Patrol Doctor output
Patrol doctor: Patrol CLI version: 3.5.1 Flutter command: flutter Flutter 3.27.4 • channel stable Android: • Program adb found in /usr/local/share/android-sdk/platform-tools/adb • Env var $ANDROID_HOME set to /usr/local/share/android-sdk
Flutter Doctor output
flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.27.4, on macOS 15.3.2 24D81 darwin-arm64, locale en-RS) [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 16.2) [✓] Chrome - develop for the web [!] Android Studio (not installed) [✓] IntelliJ IDEA Community Edition (version 2024.3.3) [✓] VS Code (version 1.98.0) [✓] Connected device (6 available) [✓] Network resources
! Doctor found issues in 1 category.
Hi @ielnitskiy Could you provide full log from the workflow?
@zoskar Hello Yes, of course (I changed the name of the app to myapp)
integration-patrol-tests-android:
name: Run integration patrol tests Android
instance_type: linux_x2
environment:
flutter: 3.27.4
groups:
- common
- vpn
- testrail_credentials
vars:
CM_CLONE_DEPTH: 1
cache:
cache_paths:
- $HOME/.pub-cache
- $HOME/.gradle/caches
scripts:
- name: Install and run OpenVPN
script: |
#!/usr/bin/env bash
echo $MYAPP_STAGING_OPENVPN | base64 --decode > myapp.ovpn
sudo apt-get update
sudo apt-get install -y openvpn
sudo openvpn --config myapp.ovpn --daemon
if pgrep openvpn > /dev/null; then
echo "OpenVPN started successfully."
else
echo "Failed to start OpenVPN."
exit 1
fi
- name: Install Patrol CLI
script: |
#!/usr/bin/env bash
dart pub global activate patrol_cli
- name: Launch Android emulator
script: |
#!/usr/bin/env bash
flutter emulators --launch emulator &
adb wait-for-device
echo "Android emulator launched"
- name: Run integration e2e tests android
script: |
#!/usr/bin/env bash
echo "Running Android integration e2e tests"
dart pub upgrade --directory=tools/builder
cd apps/myapp
patrol test -t integration_test/ --dart-define=BUILD_ENVIRONMENT=staging --dart-define="FLUTTER_TEST=true" --verbose
Install Patrol CLI
#!/usr/bin/env bash
dart pub global activate patrol_cli
Package patrol_cli is currently active at version 3.5.1.
Resolving dependencies...
Downloading packages...
The package patrol_cli is already activated at newest available version.
To recompile executables, first run `dart pub global deactivate patrol_cli`.
Installed executable patrol.
Activated patrol_cli 3.5.1.
Launch Android emulator
#!/usr/bin/env bash
flutter emulators --launch emulator &
adb wait-for-device
echo "Android emulator launched"
* daemon not running; starting now at tcp:5037
* daemon started successfully
╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.dev ║
║ ║
║ The Flutter tool uses Google Analytics to anonymously report feature usage ║
║ statistics and basic crash reports. This data is used to help improve ║
║ Flutter tools over time. ║
║ ║
║ Flutter tool analytics are not sent on the very first run. To disable ║
║ reporting, type 'flutter config --no-analytics'. To display the current ║
║ setting, type 'flutter config'. If you opt out of analytics, an opt-out ║
║ event will be sent, and then no further information will be sent by the ║
║ Flutter tool. ║
║ ║
║ By downloading the Flutter SDK, you agree to the Google Terms of Service. ║
║ The Google Privacy Policy describes how data is handled in this service. ║
║ ║
║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and ║
║ crash reports to Google. ║
║ ║
║ Read about data we send with crash reports: ║
║ https://flutter.dev/to/crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://policies.google.com/privacy ║
║ ║
║ To disable animations in this tool, use ║
║ 'flutter config --no-cli-animations'. ║
╚════════════════════════════════════════════════════════════════════════════╝
Android emulator launched
Run integration e2e tests android
14s
#!/usr/bin/env bash
echo "Running Android integration e2e tests"
dart pub upgrade --directory=tools/builder
cd apps/myapp
patrol test -t integration_test/ --dart-define=BUILD_ENVIRONMENT=staging --dart-define="FLUTTER_TEST=true" --verbose
Running Android integration e2e tests
Resolving dependencies in `tools/builder`...
Downloading packages...
ffi 2.1.3 (2.1.4 available)
freezed 2.5.8 (3.0.4 available)
freezed_annotation 2.4.4 (3.0.0 available)
googleapis 13.2.0 (14.0.0 available)
intl 0.19.0 (0.20.2 available)
js 0.7.1 (0.7.2 available)
No dependencies changed in `tools/builder`.
6 packages have newer versions incompatible with dependency constraints.
Try `dart pub outdated` for more information.
Verbose mode enabled. More logs will be printed.
Completion files installed. To enable completion, run the following command in your shell:
source /home/builder/.zshrc
Received 1 test target(s)
Received test target: /home/builder/clone/apps/myapp/integration_test/tests/auth_test.dart
Generated entrypoint /home/builder/clone/apps/myapp/integration_test/test_bundle.dart with 1 bundled test(s)
Received Android flavor: dev
Received iOS flavor: dev
$ flutter --no-version-check --suppress-analytics devices --machine
No device specified, using the first one (emulator-5554)
Received 1 device(s) to run on
Received device: emulator-5554
$ flutter doctor --verbose
$ flutter --suppress-analytics --no-version-check pub deps --style=list
Received 12 --dart-define(s) (2 custom, 10 internal)
Received custom --dart-define: BUILD_ENVIRONMENT
Received custom --dart-define: FLUTTER_TEST
Received internal --dart-define: PATROL_WAIT=0
Received internal --dart-define: PATROL_APP_PACKAGE_NAME=ru.myapp.myapp
Received internal --dart-define: PATROL_APP_BUNDLE_ID=ru.myapp.myapp
Received internal --dart-define: PATROL_ANDROID_APP_NAME=myapp
Received internal --dart-define: PATROL_IOS_APP_NAME=myapp
Received internal --dart-define: INTEGRATION_TEST_SHOULD_REPORT_RESULTS_TO_NATIVE=false
Received internal --dart-define: PATROL_TEST_LABEL_ENABLED=true
Received internal --dart-define: PATROL_TEST_SERVER_PORT=8081
Received internal --dart-define: PATROL_APP_SERVER_PORT=8082
Received internal --dart-define: COVERAGE_ENABLED=false
$ flutter build apk --config-only -t integration_test/test_bundle.dart
$ flutter doctor --verbose
$ ./gradlew :app:dependencies
• Building apk with entrypoint test_bundle.dart...
$ ./gradlew :app:assembleDevDebug -Ptarget=/home/builder/clone/apps/myapp/integration_test/test_bundle.dart -Pdart-defines=QlVJTERfRU5WSVJPTk1FTlQ9c3RhZ2luZw==,RkxVVFRFUl9URVNUPXRydWU=,UEFUUk9MX1dBSVQ9MA==,UEFUUk9MX0FQUF9QQUNLQUdFX05BTUU9cnUudHJpcHN0ZXIudHJpcHN0ZXI=,UEFUUk9MX0FQUF9CVU5ETEVfSUQ9cnUudHJpcHN0ZXIuVHJpcHN0ZXI=,UEFUUk9MX0FORFJPSURfQVBQX05BTUU9dHJhdmVsZXJz,UEFUUk9MX0lPU19BUFBfTkFNRT10cmF2ZWxlcnM=,SU5URUdSQVRJT05fVEVTVF9TSE9VTERfUkVQT1JUX1JFU1VMVFNfVE9fTkFUSVZFPWZhbHNl,UEFUUk9MX1RFU1RfTEFCRUxfRU5BQkxFRD10cnVl,UEFUUk9MX1RFU1RfU0VSVkVSX1BPUlQ9ODA4MQ==,UEFUUk9MX0FQUF9TRVJWRVJfUE9SVD04MDgy,Q09WRVJBR0VfRU5BQkxFRD1mYWxzZQ==,RkxVVFRFUl9BUFBfRkxBVk9SPWRldg== -Papp-server-port=8082 -Ptest-server-port=8081
✗ Failed to build apk with entrypoint test_bundle.dart (Gradle build failed with code 127) (10ms)
Exception: Gradle build failed with code 127
#0 AndroidTestBackend.build.<anonymous closure> (package:patrol_cli/src/android/android_test_backend.dart:81:9)
<asynchronous suspension>
#1 DisposeScope.run (package:dispose_scope/src/dispose_scope.dart:46:7)
<asynchronous suspension>
#2 AndroidTestBackend.build (package:patrol_cli/src/android/android_test_backend.dart:51:5)
<asynchronous suspension>
#3 TestCommand._build (package:patrol_cli/src/commands/test.dart:337:7)
<asynchronous suspension>
#4 TestCommand.run (package:patrol_cli/src/commands/test.dart:252:5)
<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:386:18)
<asynchronous suspension>
#7 PatrolCommandRunner.run (package:patrol_cli/src/runner/patrol_command_runner.dart:330:18)
<asynchronous suspension>
#8 patrolCommandRunner (package:patrol_cli/src/runner/patrol_command_runner.dart:76:20)
<asynchronous suspension>
#9 main (file:///home/builder/.pub-cache/hosted/pub.dev/patrol_cli-3.5.1/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.
Exception: Gradle build failed with code 127
#0 AndroidTestBackend.build.<anonymous closure> (package:patrol_cli/src/android/android_test_backend.dart:81:9)
<asynchronous suspension>
#1 DisposeScope.run (package:dispose_scope/src/dispose_scope.dart:46:7)
<asynchronous suspension>
#2 AndroidTestBackend.build (package:patrol_cli/src/android/android_test_backend.dart:51:5)
<asynchronous suspension>
#3 TestCommand._build (package:patrol_cli/src/commands/test.dart:337:7)
<asynchronous suspension>
#4 TestCommand.run (package:patrol_cli/src/commands/test.dart:252:5)
<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:386:18)
<asynchronous suspension>
#7 PatrolCommandRunner.run (package:patrol_cli/src/runner/patrol_command_runner.dart:330:18)
<asynchronous suspension>
#8 patrolCommandRunner (package:patrol_cli/src/runner/patrol_command_runner.dart:76:20)
<asynchronous suspension>
#9 main (file:///home/builder/.pub-cache/hosted/pub.dev/patrol_cli-3.5.1/bin/main.dart:6:20)
<asynchronous suspension>
Build failed :|
Step 7 script `Run integration e2e tests android` exited with status code 1
[Apps](https://codemagic.io/apps)
[Builds](https://codemagic.io/builds)
[Teams](https://codemagic.io/teams)
[Billing](https://codemagic.io/billing)
Ivan Elnitskiy
[Flutter Mobile Apps](https://codemagic.io/builds)
[email protected]:experience/mobile-flutter-apps.git
Start new build
Build overview
ID:
67dd29f8fb67662e2e97d040
Please provide this ID when you contact our support team
Index:
17
Status:
failed
Workflow:
Run integration patrol tests Android
Started by:
USER
Started:
41 minutes ago
Mar 21st, 2025 at 10:05 CET
Duration:
2m 48s
Machine:
Linux X2
Branch:
ci-myapp-patrol
Commit:
44ec003
Click on the build steps for details.
Preparing build machine
22s
Fetching app sources
12s
Restoring cache
32s
Installing SDKs
40s
Install and run OpenVPN
21s
Install Patrol CLI
1s
Launch Android emulator
22s
Publishing
< 1s
Cleaning up
< 1s
Step 7 script `Run integration e2e tests android` exited with status code 1
Build for Flutter Mobile Apps finished
Click to open build
Hi @ielnitskiy We didn't have a chance to reproduce the issue yet, but we have a few theories why it's not working:
- what android API is this emulator? I read somewhere on Codemagic GH that it's API 30, maybe your app doesn't support it. Try with
emulator-34instead ofemulatorinflutter emulators --launch. ("somewhere": https://github.com/orgs/codemagic-ci-cd/discussions/2832) - Gradle cache might cause some problems, but it's not likely an issue
We'll keep investigating, but it will take a while
Hi @jBorkowska
Unfortunately, this did not help me. I tried disabling the cache. I tried running tests on emulators:
emulator -34
emulator -35
emulator -36
I also tried running the test launch command in the ci terminal, but I still encounter the same error.
Hi @jBorkowska Perhaps you have any other hypotheses on this matter?
Hi @ielnitskiy , we had no idea why it's happening until last week. We had similar issue on Firebase Studio, where we were trying to run patrol test, but it was failing with similar error. We discovered a race condition in the command - sometimes the machine is so slow, that building starts before gradlew is generated, which should be done by flutter build apk --config-only -t integration_test/test_bundle.dart command, invoked inside patrol test. Turns out patrol test is not waiting for this command to finish and starts next one without gradlew generated.
TL;DR:
Try adding flutter build apk --config-only -t integration_test/test_bundle.dart before patrol test.
Let us know if it helped if you're still experiencing this problem
Without additional information, we can't resolve this issue. We're therefore reluctantly going to close it. Feel free to open a new issue with all the required information provided, including a [minimal, reproducible sample]. Make sure to diligently fill out the issue template. Thanks for your contribution. [minimal, reproducible sample]: https://stackoverflow.com/help/minimal-reproducible-example
This issue has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar problem, please file a new issue. Make sure to follow the template and provide all the information necessary to reproduce the issue.