Automating and Optimizing Android Jetpack Compose App Builds with Bitrise and GitHub
type
Post
status
Published
date
Apr 13, 2023
slug
automating-android-jetpack-compose-builds-bitrise-github
summary
In this blog, we explored how to create a simple Android Jetpack Compose app, push it to GitHub, and configure Bitrise for automatic builds.
tags
CI/CD
Bitrise
GitHub
Automate
category
Android
icon
password
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.

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 https://app.bitrise.io/getting-started. Click on "Add new app" to start the process.

Step 4: Configure the App on Bitrise
- In the Project Access section, select "Only Workspace members" for private projects and click "Next."

- In the Select Repository section, choose GitHub as your provider and click "Select" to choose the Android repository you pushed in step 2.

- In the Setup Repository Access section, click on "No, auto-add SSH key" and proceed by clicking "Next."

- In the Choose Branch section, choose your preferred branch (we have selected "main" here). Select "Yes, auto-detect configuration" and proceed by clicking "Next."

- Bitrise will configure your app, which may take a few minutes.

- Specify the module name (we have selected "app") and variant (we have chosen "debug" as the variant).



- Review the project build configuration and confirm or edit as needed.

- Optionally, you can add an app icon.

- Click on "Register webhook for me" on Bitrise to enable automatic builds upon code pushes.

Step 5: Monitor Your First Build
Click on "We've kicked off your first test build for you!" to see your first build running.

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.

Explore the tabs like
Code Signing & Files, Secrets, Env Vars, Triggers, Stacks & Machines, and bitrise.yml
.
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"

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."

Conclusion
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.