Distribute CLI
The Distribute CLI is a command-line tool designed to streamline the process of building and distributing Flutter applications for Android and iOS platforms. It supports integration with Firebase and Fastlane for seamless app distribution.
Features
- Build Android and iOS apps with custom configurations.
- Distribute apps using Firebase App Distribution or Fastlane.
- Automatically generate changelogs based on Git commits.
- Validate and download metadata for Android Play Store.
- Cross-platform support (macOS required for iOS builds).
Prerequisites
Before using the Distribute CLI, ensure the following tools are installed:
For iOS builds, you must use macOS and have Xcode installed.
Installation
Execute the following command to globally activate distribute_cli:
dart pub global activate distribute_cli
Run the following command to initialize the environment:
distribute init
This will create the necessary directories and validate the required tools.
Usage
Build Apps
To build Android and iOS apps, use the build command:
distribute build --android --ios
Options
-p, --[no-]publish: Automatically distribute Android builds.--[no]-android: Build Android (enabled by default).--[no]-ios: Build iOS (enabled by default).--android_binary: Specify the Android binary type (aaborapk).--android_args: Specify additional arguments for Android builds.--ios_args: Specify additional arguments for iOS builds.--custom_args=<macos:macos,windows:windows,ios:ipa,android_apk:apk>: Provide custom arguments in the formatkey:args,key:args. These will be executed asflutter build <args>.
Distribute Apps
To distribute apps, use the publish command:
distribute publish --android --firebase
Options
--[no]-android: Build and distribute Android (enabled by default).--[no]-ios: Build and distribute iOS (enabled by default).--[no]-firebase: Use Firebase for distribution.--[no]-fastlane: Use Fastlane for distribution (enabled by default).--fastlane_track: Specify the Play Store track (e.g.,internal,production).--fastlane_promote_track_to: Specify the track to promote to after distribution.
Example Commands
Build and Distribute Android App
distribute build --no-ios --android --publish --android_binary=aab
Distribute iOS App
distribute publish --ios --no-android
Build with Custom Arguments
distribute build --custom_args="macos:macos,windows:windows"
Configuration
The tool uses a .distribution.env file for configuration. This file is created during initialization and contains the following settings:
ANDROID_BUILD=true
ANDROID_DISTRIBUTE=true
ANDROID_PLAYSTORE_TRACK=internal
ANDROID_PLAYSTORE_TRACK_PROMOTE_TO=production
ANDROID_PACKAGE_NAME=com.example.app
ANDROID_FIREBASE_APP_ID=your-firebase-app-id
ANDROID_FIREBASE_GROUPS=testers
ANDROID_BINARY=appbundle
IOS_BUILD=true
IOS_DISTRIBUTE=true
IOS_DISTRIBUTION_USER=your-apple-id
IOS_DISTRIBUTION_PASSWORD=your-app-specific-password
USE_FASTLANE=true
USE_FIREBASE=false
Populating the .distribution.env File
-
ANDROID_BUILD:
Set totrueto enable Android builds. -
ANDROID_DISTRIBUTE:
Set totrueto enable Android distribution after building. -
ANDROID_PACKAGE_NAME:
Specify your app's package name (e.g.,com.example.app). -
ANDROID_PLAYSTORE_TRACK:
Specify the Play Store track for Android distribution (e.g.,internal,alpha,beta,production). Defaults tointernal. -
ANDROID_PLAYSTORE_TRACK_PROMOTE_TO:
Specify the Play Store track to promote the build to after distribution (e.g.,production). Defaults toproduction. -
ANDROID_BINARY:
Specify the Android binary type for builds (apkorappbundle). Defaults toappbundle. -
ANDROID_FIREBASE_APP_ID:
Provide your Firebase App ID if using Firebase App Distribution. Leave blank otherwise. -
ANDROID_FIREBASE_GROUPS:
List Firebase tester groups (comma-separated) for distribution. Leave blank if not applicable. -
IOS_BUILD:
Set totrueto enable iOS builds. -
IOS_DISTRIBUTE:
Set totrueto enable iOS distribution after building. -
IOS_DISTRIBUTION_USER:
Provide your Apple ID for App Store distribution. -
IOS_DISTRIBUTION_PASSWORD:
Provide your app-specific password for App Store distribution. You can generate it from Apple ID settings. -
USE_FASTLANE:
Set totrueto enable Fastlane for Android distribution. -
USE_FIREBASE:
Set totrueto enable Firebase App Distribution.
Adding the distribution/fastlane.json File
- Visit the Google Cloud Console.
- Navigate to IAM & Admin > Service Accounts.
- Select or create a service account with Editor or Release Manager permissions for your Play Store project.
- Generate a JSON key for the service account and download it.
- Place the JSON key file in the
distributiondirectory and name itfastlane.json.
Ensure your project directory is structured as follows:
your_project_directory
├── lib
├── distribution
├── fastlane.json
Logs
All logs are saved to distribution.log in the root directory. Use this file to debug issues or review the build and distribution process.
Contributing
Contributions are welcome! Feel free to submit issues or pull requests to improve the tool.
License
This project is licensed under the MIT License. See the LICENSE file for details.