Automating and Optimizing Android Jetpack Compose App Builds with Bitrise and GitHub

Android|Apr 13, 2023|Last edited: May 4, 2023
  • CI/CD
  • Bitrise
  • GitHub
  • Automate
  • Automating and Optimizing Android Jetpack Compose App Builds with Bitrise and GitHub
    Apr 13, 2023
    In this blog, we explored how to create a simple Android Jetpack Compose app, push it to GitHub, and configure Bitrise for automatic builds.

    How to Automate Your Android App Development Workflow with Bitrise and GitHub

    In this blog post, we will walk you through setting up a simple Android Jetpack Compose app, pushing it to GitHub, and configuring Bitrise to automatically build the app. We will also discuss some important Bitrise features such as webhooks, environment variables, and workflows. By the end of this tutorial, you should have a basic understanding of how to integrate your Android project with Bitrise and GitHub.

    Step 1: Create a Basic Android Jetpack Compose App

    First, you need to create a simple Android Jetpack Compose app. You can follow Android's official documentation to get started with Jetpack Compose or create a new project using Android Studio's built-in Jetpack Compose templates.
    notion image

    Step 2: Push the App to GitHub

    Once you have created your app, push it to a GitHub repository. Make sure that the repository is accessible by the Bitrise account you will be using.

    Step 3: Log in to Bitrise and Add a New App

    Login to your Bitrise account and navigate to the Getting Started page at Click on "Add new app" to start the process.
    notion image

    Step 4: Configure the App on Bitrise

    • In the Project Access section, select "Only Workspace members" for private projects and click "Next."
      • notion image
    • In the Select Repository section, choose GitHub as your provider and click "Select" to choose the Android repository you pushed in step 2.
        notion image
    • In the Setup Repository Access section, click on "No, auto-add SSH key" and proceed by clicking "Next."
    notion image
    • In the Choose Branch section, choose your preferred branch (we have selected "main" here). Select "Yes, auto-detect configuration" and proceed by clicking "Next."
    notion image
    • Bitrise will configure your app, which may take a few minutes.
    notion image
    • Specify the module name (we have selected "app") and variant (we have chosen "debug" as the variant).
      • notion image
    notion image
    notion image
    • Review the project build configuration and confirm or edit as needed.
        notion image
    • Optionally, you can add an app icon.
    notion image
    • Click on "Register webhook for me" on Bitrise to enable automatic builds upon code pushes.
        notion image

    Step 5: Monitor Your First Build

    Click on "We've kicked off your first test build for you!" to see your first build running.
    notion image

    Step 6: Customize the Bitrise Workflow

    Click on the "Edit workflow" button at the top. Review the steps in the "Primary" workflow, which Bitrise has selected by default.
    notion image
    Explore the tabs like Code Signing & Files, Secrets, Env Vars, Triggers, Stacks & Machines, and bitrise.yml.
    notion image
    In the Env Vars section, add or edit variables as needed. We have added two variables in this example:
    _JAVA_OPTIONS: Xms1024m -Xmx2048m GRADLE_OPTS: Dorg.gradle.jvmargs="-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError"
    notion image
    These environment variables were added to improve the performance and stability of the build process on Bitrise:
    _JAVA_OPTIONS: Xms1024m -Xmx2048m This variable sets the initial and maximum heap size for the Java Virtual Machine (JVM) running the build. By specifying the minimum (Xms) and maximum (Xmx) heap sizes, you can allocate more memory to the JVM, which can help prevent out-of-memory errors and improve the build performance. In this case, the minimum heap size is set to 1024 MB (1 GB), and the maximum heap size is set to 2048 MB (2 GB).
    GRADLE_OPTS: Dorg.gradle.jvmargs="-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError" This variable sets custom JVM arguments for the Gradle build process. In this example, two arguments are specified:
    • -Xmx4096m: This sets the maximum heap size for the JVM running the Gradle build to 4096 MB (4 GB). By allocating more memory to the JVM, you can improve the build performance and prevent out-of-memory errors.
    • -XX:+HeapDumpOnOutOfMemoryError: This option instructs the JVM to generate a heap dump if an out-of-memory error occurs. Heap dumps are useful for diagnosing memory-related issues and can help you identify memory leaks or excessive memory consumption in your app.
    By adding these environment variables, you can optimize the build process on Bitrise, ensuring faster builds and reducing the chances of encountering memory-related issues during the build process.

    Trigger Bitrise Workflow on Push to Git

    In the Triggers section, click on "Add Trigger" and select the "main" branch to trigger Bitrise builds on every push to the main branch.
    Choose the desired workflow to be triggered, such as "deploy" or "primary."
    notion image


    Your basic setup is now ready! You have successfully integrated your Android Jetpack Compose app with Bitrise and GitHub. In future tutorials, we will cover more advanced topics like customizing workflows, adding UI tests to Bitrise, and integrating Google Play signing.
    Mastering Location-Based App Testing with Maestro UI Testing Framework's Travel CommandEfficiently Running Maestro UI Tests in Bitrise for Your Android App