patrol build command creates optimized test binaries for Android, iOS, and macOS. It’s primarily used for CI/CD pipelines and device farms where you need to build once and run tests later.
Synopsis
<platform> is one of:
android- Build for Android devices and emulatorsios- Build for iOS devices and simulatorsmacos- Build for macOS desktop
Description
patrol build performs all the same build steps as patrol test, but stops before running the tests. This is useful when:
- Running tests on CI/CD platforms like Firebase Test Lab
- Building once and running tests multiple times
- Separating build and test stages in your pipeline
- Testing on device farms that require pre-built binaries
For
patrol build to work, you must complete the native setup.Basic Usage
Build for Android
- App APK:
build/app/outputs/apk/debug/app-debug.apk - Test APK:
build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk
Build for iOS
- App bundle:
build/ios_integ/Build/Products/Debug-iphonesimulator/Runner.app - Test runner:
build/ios_integ/Build/Products/Debug-iphonesimulator/RunnerUITests-Runner.app
Build for macOS
Build Modes
By default, builds are in debug mode. You can specify a different mode:Build in debug mode (default).
Build in profile mode for performance testing.
Build in release mode. Required for physical iOS devices on device farms.
Target Selection
Specify which test file(s) to include in the build.
Exclude specific test files.
patrol_test/ are bundled into a single binary.
Flavors
Build a specific flavor of your app.
Build Versioning
Set the version name (e.g., “1.2.3”).
Set the version code (e.g., “123”).
Dart Defines
Pass environment variables to your app.
Load environment variables from a file.
Tags
Include only tests with specific tags.
Exclude tests with specific tags.
Platform-Specific Options
Android
Override the Android package name.
iOS
Override the iOS bundle identifier.
Enable full isolation between test runs on iOS Simulator.
Advanced Options
Display label overlay on the app during testing.
Port for the test instrumentation server.
Port for the app under test server.
Verify dependency compatibility.
Generate test bundle file.
Disable icon tree shaking during build.
Controls whether to uninstall during subsequent test runs.
Examples
CI/CD Usage
Here’s how to usepatrol build in common CI/CD scenarios:
Firebase Test Lab (Android)
AWS Device Farm (iOS)
GitHub Actions Example
Output Files
Android
After building for Android, you’ll find: Debug mode:build/app/outputs/apk/debug/app-debug.apk(app under test)build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk(test instrumentation)
build/app/outputs/apk/release/app-release.apkbuild/app/outputs/apk/androidTest/release/app-release-androidTest.apk
build/app/outputs/apk/{flavor}/debug/app-{flavor}-debug.apkbuild/app/outputs/apk/androidTest/{flavor}/debug/app-{flavor}-debug-androidTest.apk
iOS
After building for iOS, you’ll find: Simulator:build/ios_integ/Build/Products/Debug-iphonesimulator/Runner.appbuild/ios_integ/Build/Products/Debug-iphonesimulator/RunnerUITests-Runner.app
build/ios_integ/Build/Products/Release-iphoneos/Runner.appbuild/ios_integ/Build/Products/Release-iphoneos/RunnerUITests-Runner.app
Under the Hood
Thepatrol build command uses advanced test bundling:
- Discovers tests - Finds all
*_test.dartfiles inpatrol_test/ - Creates bundle - Generates a single test file that references all tests
- Builds binaries - Compiles app and test instrumentation into single binaries
- Enables sharding - Each test runs as a separate process for better isolation
- Single build for all tests (much faster)
- Better isolation between test runs
- Sharding support for parallel execution
- Native integration with platform test runners
Troubleshooting
Build fails with “Native setup incomplete”
Ensure you’ve completed the native setup guide.APKs not found after build
Check the exact output path. It varies based on:- Build mode (debug/release)
- Flavor (if specified)
iOS build fails on CI
Ensure:- You’re running on macOS
- Xcode is properly installed
- Code signing is configured for release builds
Version conflicts
Run compatibility check:Related Commands
- patrol test - Build and run tests
- patrol develop - Develop tests with Hot Restart
- patrol doctor - Verify environment setup