How do generate Android APKs by build variants?

Greetings everyone! I am new to Bitrise, so I am gradually learning their service. I have a question regarding generating APKs. How can I setup my builds to generate APKs based on build variants? I have posted my YAML below. And my assumptions on changes. Can anyone help with this? Thanks in advanced

Here is our premise

  1. We have 3 environments i.e. debug, stage, release
  2. We have 2 product flavors i.e. freemium, subscription

format_version: '4’
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: android
trigger_map:

  • pull_request_source_branch: development
    workflow: debug
    pull_request_target_branch: development
  • tag: Test
    workflow: debug
  • tag: Stage
    workflow: stage
  • tag: Production
    workflow: release
    workflows:
    release:
    steps:
    • activate-ssh-key@3.1.1:
      run_if: ‘{{getenv “SSH_RSA_PRIVATE_KEY” | ne “”}}’
    • git-clone@4.0.5: {}
    • cache-pull@2.0.1: {}
    • script@1.1.5:
      title: Do anything with Script step
    • install-missing-android-tools@2.0.6: {}
    • gradle-runner@1.8.0:
      inputs:
      • gradle_file: “$GRADLE_BUILD_FILE_PATH”
      • gradle_task: assembleRelease
      • gradlew_path: "$GRADLEW_PATH"
        inputs: <---- I added this input
      • gradle_file: “$GRADLE_BUILD_FILE_PATH”
      • gradle_task: assembleReleaseFreemium
      • gradlew_path: "$GRADLEW_PATH"
        inputs: <---- I added this input
      • gradle_file: “$GRADLE_BUILD_FILE_PATH”
      • gradle_task: assembleReleaseSubscription
      • gradlew_path: “$GRADLEW_PATH”
    • deploy-to-bitrise-io@1.3.10: {}
    • cache-push@2.0.3: {}
      stage:
      steps:
    • activate-ssh-key@3.1.1:
      run_if: ‘{{getenv “SSH_RSA_PRIVATE_KEY” | ne “”}}’
    • git-clone@4.0.5: {}
    • cache-pull@2.0.1: {}
    • script@1.1.5:
      title: Do anything with Script step
    • install-missing-android-tools@2.0.6: {}
    • gradle-runner@1.8.0:
      inputs:
      • gradle_file: “$GRADLE_BUILD_FILE_PATH”
      • gradle_task: assembleStage
      • gradlew_path: "$GRADLEW_PATH"
        inputs: <---- I added this input
      • gradle_file: “$GRADLE_BUILD_FILE_PATH”
      • gradle_task: assembleStageFreemium
      • gradlew_path: "$GRADLEW_PATH"
        inputs: <---- I added this input
      • gradle_file: “$GRADLE_BUILD_FILE_PATH”
      • gradle_task: assembleStageSubscription
      • gradlew_path: “$GRADLEW_PATH”
    • deploy-to-bitrise-io@1.3.10: {}
    • cache-push@2.0.3: {}
      debug:
      steps:
    • activate-ssh-key@3.1.1:
      run_if: ‘{{getenv “SSH_RSA_PRIVATE_KEY” | ne “”}}’
    • git-clone@4.0.5: {}
    • cache-pull@2.0.1: {}
    • script@1.1.5:
      title: Do anything with Script step
    • install-missing-android-tools@2.0.6: {}
    • gradle-runner@1.8.0:
      inputs:
      • gradle_file: “$GRADLE_BUILD_FILE_PATH”
      • gradle_task: assembleDebug
      • gradlew_path: "$GRADLEW_PATH"
        inputs: <---- I added this input
      • gradle_file: “$GRADLE_BUILD_FILE_PATH”
      • gradle_task: assembleDebugFreemium
      • gradlew_path: "$GRADLEW_PATH"
        inputs: <---- I added this input
      • gradle_file: “$GRADLE_BUILD_FILE_PATH”
      • gradle_task: assembleDebugSubscription
      • gradlew_path: “$GRADLEW_PATH”
    • deploy-to-bitrise-io@1.3.10: {}
    • cache-push@2.0.3: {}
      after_run:
    • stage
    • release
      app:
      envs:
    • opts:
      is_expand: false
      GRADLE_BUILD_FILE_PATH: build.gradle
    • opts:
      is_expand: false
      GRADLEW_PATH: “./gradlew”

Hi @transdev,

Please see this #how-to : How to build different flavors of an Android project

If you’d have any questions just let us know! :wink:

@viktorbenei

I think I may have got this to work. If I understand the tutorial correctly, ALL flavors will build if I do not specify any flavor specifically but instead only define a type. Like this correct?

1 Like

Indeed, that’s correct :slight_smile: