Following [our initial dive into Fastlane for Android]({{< ref “fastlane-android-1” >}}), we now focus on leveraging Fastlane for building specific flavors of your Android app and executing unit tests.

Fastlane configuration for Flavors

Fastlane excels in managing multiple product flavors. To configure Fastlane for different flavors, you’ll edit your Fastfile to define lanes for each flavor:

lane :build_flavor1 do
  gradle(task: "assembleFlavor1Release")
end
 
lane :build_flavor2 do
  gradle(task: "assembleFlavor2Release")
end

These configurations enable Fastlane to target specific build tasks associated with your app’s flavors, streamlining the build process for each.

To build a specific flavor of your app, execute the Fastlane lane designed for that flavor:

fastlane build_flavor1

This command initiates the build process for flavor1, generating the necessary build artifacts for that specific flavor.

Executing Unit Tests

lane :test_flavor1 do
  gradle(task: "testFlavor1Debug")
end

By running fastlane test_flavor1, Fastlane executes the unit tests for flavor1.

Wrapping Up

By integrating Fastlane into your development workflow for Android apps, you can efficiently manage the build and test processes for different flavors. This guide has outlined the key steps and configurations to leverage Fastlane’s full potential, paving the way for a more streamlined development process.

References