Flutter Continuous Integration and Delivery on Bitrise
Intro to Bitrise:
Bitrise is a powerful CI/CD platform that supports Flutter, a popular framework for building cross-platform mobile apps.
Bitrise is a top mobile CI/CD platform, streamlining build, test, and deployment for mobile apps. It offers a user-friendly interface, robust integrations, and scalable infrastructure to simplify development and ensure efficient delivery of high-quality apps.
Key Features
1. Automated Builds: Bitrise offers out-of-the-box support for Flutter apps, allowing you to build for both iOS and Android.
2. Testing and Analysis: You can run unit, widget, and integration tests using the Flutter Test Step. Analyze results with the Test Reports add-on.
3. Customizable Workflows: Create workflows that fit your needs, specifying the exact version of the Flutter SDK and adding any necessary build parameters.
4. Integration: Bitrise integrates with over 350 mobile tools, making it easy to manage dependencies, run tests, and deploy your app
Let’s get started how to add Flutter App to Bitrise:-
Step-by-Step Setup
1. Create a Bitrise Account and App
- Sign up at bitrise.io and create a new app.
- Connect your repository (GitHub, GitLab, Bitbucket, etc.).
- Select Flutter as the project type during the setup wizard.
2. Configure the Workflow
- Navigate to the Workflows tab in your Bitrise project.
- Add steps to your workflow:
- Flutter Install: Ensures the Flutter SDK is available.
- Flutter Analyze: Runs static code analysis to catch issues early.
- Flutter Test: Executes unit and widget tests.
- Flutter Build: Builds APKs (Android) or IPA files (iOS).
- Optional steps: Integrate tools like Slack for notifications or Firebase for deployment.
3. Set Up Environment Variables
- Add required secrets, such as API keys or credentials, in the Secrets section.
- Configure variables like
FLUTTER_BUILD_MODE
(e.g., debug, release) to customize builds.
4. Trigger Builds
- Push changes to your repository to trigger the pipeline automatically.
- Use webhooks for additional automation.
5. Monitor and Debug
- View logs in the Bitrise dashboard for insights into build performance.
- Fix any issues highlighted during the build process.
Here is the complete workflow yml file:
format_version: '8'
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: flutter
workflows:
deploy:
steps:
- activate-ssh-key@4:
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
- git-clone@4: {}
- script@1:
title: Do anything with Script step
- certificate-and-profile-installer@1: {}
- flutter-installer@0:
inputs:
- version: 1.22.4
- is_update: 'false'
- flutter@0:
inputs:
- version: 1.22.4
- commands: packages get | packages pub run build_runner build
- flutter-analyze@0:
inputs:
- project_location: "$BITRISE_FLUTTER_PROJECT_LOCATION"
- set-xcode-build-number@1:
inputs:
- build_version_offset: '1'
- build_short_version_string: 1.0.0
- build_version: CFBundleVersion
- plist_path: "$BITRISE_SOURCE_DIR/ios/Runner/Info.plist"
- flutter-build@0:
inputs:
- project_location: "."
- is_debug_mode: 'true'
- ios_additional_params: "--release -t lib/main_dev.dart -v"
- platform: ios
- xcode-archive@3:
inputs:
- export_method: app-store
- deploy-to-itunesconnect-application-loader@1.1:
inputs:
- itunescon_user: "$APPLE_ID"
- password: "$APPLE_ID_PASSWORD"
- app_password: "$APP_SPECIFIC_PASSWORD"
- connection: apple_id
- appcenter-deploy-android@2:
inputs:
- owner_name: Your_Owner_Name
- app_name: Your_App_Name
- app_path: "/Users/vagrant/deploy/app-release.apk"
- distribution_group: Your_Group_Name
- mandatory: 'yes'
- debug: 'yes'
- api_token: "$appCenterKey"
- deploy-to-bitrise-io@1: {}
- cache-push@2: {}
app:
envs:
- opts:
is_expand: false
BITRISE_FLUTTER_PROJECT_LOCATION: "."
- opts:
is_expand: false
BITRISE_PROJECT_PATH: ios/Runner.xcworkspace
- opts:
is_expand: false
BITRISE_SCHEME: Runner
- opts:
is_expand: false
BITRISE_EXPORT_METHOD: development
- opts:
is_expand: false
appCenterKey: your_appCenterKey
trigger_map:
- pull_request_source_branch: develop
pull_request_target_branch: master
workflow: primary
- pull_request_target_branch: develop
workflow: primary
Using above workflow bitrise will build your project and it will show the result on the dashboard, if it fails anywhere due to the lint then you have to fix it first.
Conclusion
Bitrise makes setting up CI/CD pipelines for Flutter apps straightforward and efficient.By leveraging Bitrise, you save significant time in the deployment process, allowing your team to focus on enhancing the app’s user experience and adding valuable features.