# Getting started with Android projects

In this guide, we’ll walk you through how to add an Android app to Bitrise, what the default Workflows can do, and finally how to test and deploy your app to [bitrise.io](https://www.bitrise.io/) and to Google Play Store.

:::note[Do you have a Bitrise account?]

Make sure you have signed up to [bitrise.io](https://www.bitrise.io) and can access your Bitrise account. There are multiple ways of registering an account:

- [Signing up with email](/bitrise-platform/getting-started/signing-up-for-bitrise#signing-up-with-email)
- [Signing up with a Git provider](/bitrise-platform/getting-started/signing-up-for-bitrise#signing-up-with-a-git-provider)

:::

## Adding an Android project to Bitrise

Add your project the same way as any other: see [Adding a new project](/bitrise-ci/getting-started/adding-a-new-project) for the full walkthrough of the wizard. This section covers what's specific to Android.

### How the scanner detects an Android project

The project scanner looks for a Gradle wrapper script (`gradlew`) in your repository, then checks the Gradle build scripts next to it for the `com.android.application` plugin. If it finds this plugin in at least one `build.gradle` or `build.gradle.kts` file, it registers your project as Android.

The scanner skips common non-source directories, such as `.git`, `.gradle`, `.idea`, `build`, and `node_modules`. It also steps aside if your repository is already detected as Flutter, React Native, Cordova, Ionic, or Kotlin Multiplatform, since those scanners handle their own Android configuration.

### What you can configure

During the **CI configuration** stage, the wizard shows:

- **Project location**: the directory that contains your `gradlew` file. If the scanner finds more than one, you can pick which one to use.
- **Module**: the Gradle module to build, for example `app`.
- **Variant**: the build variant to use, for example `Debug`. You can leave this blank and add variants later.

## Managing dependencies for Android projects

The Gradle build system allows you include external binaries or other library modules as dependencies. Bitrise can install these dependencies for your project during the build process.

:::tip[Adding build dependencies]

You can read more about adding dependencies to your Android project: [https://developer.android.com/studio/build/dependencies](https://developer.android.com/studio/build/dependencies)

:::

1. Make sure your project's `build.gradle` file lists all your dependencies.
1. 1. Log in to Bitrise and select **Bitrise CI** on the left, then select your project.
1. Click the **Workflows** button on the main page.
1. Make sure your Workflow includes the **Android Build** Step.

   If the project scanner generated a Workflow called **build_apk** when first adding your app, that Workflow includes the Step. It installs all dependencies listed in the `build.gradle` file without any additional configuration.
1. Make sure your Workflow includes the **Install missing Android SDK components** Step.

   The Step must be BEFORE the **Android Build** Step in the Workflow. It will install all Android SDK tool that your project might need.

## Testing your Android app

We have several Steps dedicated to assisting you in testing your Android app during the CI process.

- The **[Android Lint](https://www.bitrise.io/integrations/steps/android-lint)** Step runs Lint on your Android project source files and detects potential syntax errors to keep your code error free.
- The **[Android Unit Test](https://www.bitrise.io/integrations/steps/android-unit-test)** Step runs your project's unit tests. You can run it for all your different modules and flavors. [Android unit tests](/bitrise-ci/testing/testing-android-apps/android-unit-tests)
- The [**Virtual Device Testing for Android**](https://www.bitrise.io/integrations/steps/virtual-device-testing-for-android) uses Firebase TestLab to run Android tests on virtual devices. [Device testing for Android](/bitrise-ci/testing/device-testing-with-firebase/device-testing-for-android)

The **[Android Unit Test](https://www.bitrise.io/integrations/steps/android-unit-test)** Step and the [**Virtual Device Testing for Android**](https://www.bitrise.io/integrations/steps/virtual-device-testing-for-android) Step can both export their results to [test reports](/bitrise-ci/testing/test-reports/deploying-test-results). To do so, simply make sure that your Workflow includes the **Deploy to Bitrise.io** Step at the very end of the Workflow.

## Signing your Android app

In order to publish an Android app to Google Play, you need to digitally sign the app. Bitrise can also do this for you: you'll just need to upload a keystore file, and provide the necessary authentication.

:::note[Other code signing options]

In this section, we'll go through how to sign an Android app with the Android Sign Step. There are other ways to sign your app - check out the other options in our relevant guides: [Android code signing](/bitrise-ci/code-signing/android-code-signing/android-code-signing-using-the-android-sign-step).

:::

1. [Generate a keystore file](https://developer.android.com/studio/publish/app-signing#generate-key)[Generate a keystore file](https://reactnative.dev/docs/signed-apk-android#generating-an-upload-key).

   1. 1. Open your project on Bitrise with a user that has the **Admin** [role on the project](/bitrise-platform/projects/roles-and-permissions-for-bitrise-ci), or a [custom role](/bitrise-platform/workspaces/collaboration-and-permissions-in-workspaces/custom-roles/custom-roles-overview) with the **Edit workflows** permission.
1. On the main page of the project, click on the **Project settings** button.
1. On the left, select **Code signing** from the menu.
1. Drag-and-drop your keystore file to the **ANDROID KEYSTORE FILE** field.
1. Fill out the **Keystore password**, **Keystore alias**, and **Private key password** fields and click **Save metadata**.

   ![keystore-alias.png](/img/_paligo/uuid-0b79fc48-3861-0744-0f53-53a6c65ffc2c.png)
1. Open the Workflow Editor.
1. Add the **Android Sign** Step to your Workflow.

And that's it. The next time you'll run a build, the **Android Sign** Step will sign the generated binary.

## Deploying an Android app to bitrise.io

In this section, we'll go through how to deploy your Android project to [bitrise.io](https://www.bitrise.io/).

Deploying to [bitrise.io](https://www.bitrise.io) means that the build artifacts generated during the build will be available for download once the build is finished. You can use this to test your Android app on your own test devices, for example.

To deploy your app to [bitrise.io](https://www.bitrise.io/):

**Workflow Editor**

1. Make sure your Workflow contains the **[Android Build](https://www.bitrise.io/integrations/steps/android-build)** Step to build your app.

   Optionally, you can build your app with the **[Gradle Runner](https://www.bitrise.io/integrations/steps/gradle-runner)** Step. This requires a bit more configuration from you but allows for more extensive customization.
1. Add the **[Deploy to Bitrise.io](https://www.bitrise.io/integrations/steps/deploy-to-bitrise-io)** Step to your Workflow.

   :::tip[Notifying other users]

   You can use the **Notify: User Roles** and the **Notify: Emails** inputs of the Step to set up notifications about your deploy. Click the input names to reveal more information about how to configure them.

   :::
1. Optionally, set the **Enable public app install page** input of the Step to **true** so the Step [enables the public install page](/bitrise-ci/deploying/bitrise-ota-app-deployment#the-public-install-page) for your app.
1. Run a build.

**Configuration YAML**

1. Open the `bitrise.yml` file of your app.
1. Make sure your Workflow contains the `android-build` Step to build your app.

   ```yaml
   workflows:
     example-workflow:
       steps:
       - android-build@1:
   ```

   Optionally, you can build your app with the `gradle-runner` Step. This requires a bit more configuration from you but allows for more extensive customization.
1. Set the `module` and/or `variant` input to tell the Step what to build.

   In this example, we're building a debug variant of the Android project.

   ```yaml
   workflows:
     example-workflow:
       steps:
       - android-build@1:
           inputs:
           - variant: debug
       - deploy-to-bitrise-io: {}
   ```
1. Add the `deploy-to-bitrise-io` Step to your Workflow.

   ```yaml
   workflows:
     example-workflow:
       steps:
       - android-build@1:
           inputs:
           - variant: debug
       - deploy-to-bitrise-io: {}
   ```

   :::tip[Notifying other users]

   You can use the `notify_user_groups` and the `notify_email_list` inputs of the Step to set up notifications about your deploy:

   - The `notify_user_groups` input allows you to send notifications based on the [access roles](/bitrise-platform/projects/roles-and-permissions-for-bitrise-ci) granted to users. For example, you can set the input to notify everyone with an **Admin** and a **Developer** role. Set multiple roles separated by a comma: `- notify_user_groups: admins, testers`.
   - The `notify_email_list` input only accepts Secrets, and the Secret should contain comma-separated lists of email addresses.

   :::
1. Optionally, set the **Enable public app install page** input of the Step to **true** so the Step [enables the public install page](/bitrise-ci/deploying/bitrise-ota-app-deployment#the-public-install-page) for your app.
1. Run a build.

The **Deploy to Bitrise.io** Step will deploy the app. You can share the generated binary with your team members using the build’s URL.

**A bitrise.yml for deploying an Android app to Bitrise**

In this example, we're building the `debug` variant of an Android app, and deploy it to bitrise.io, as.

## Setting up Google Play deployment for the first time

Deploying to Google play publishes your app to Google's online store. When you do it for the first time, this requires a bit more work than simply deploying to [bitrise.io](https://www.bitrise.io/). Once the necessary configurations are in place, it becomes very simple.

When configuring Google Play deployment for the first time, you need to link your Google Play Developer account to an API project, set up API access, and upload the service account JSON key to Bitrise.

1. Upload the first AAB or APK manually to Google Play [using the Google Play Console](https://support.google.com/googleplay/android-developer/answer/113469?hl=en).
1. [Link](https://developers.google.com/android-publisher/getting_started) your Google Play Developer Console to an API project.
1. [Set up API Access Clients using a service account](https://developers.google.com/android-publisher/getting_started): Please note when you create your service account on the Google Developer Console, you have to choose `json` as **Key Type**.
1. Grant the necessary rights to the service account with your [Google Play Console](https://play.google.com/apps/publish). Go to **Settings**, then **Users & permissions**, then **Invite new user**. Due to the way the Google Play Publisher API works, you have to grant at least the following permissions to the service account:

   - Access level: View app information.
   - Release management: Manage production releases, manage testing track releases.
   - Store presence: Edit store listing, pricing & distribution.
1. As an optional step, you can add translations to your Store Listing: [Translate & localize your app](https://support.google.com/googleplay/android-developer/answer/3125566?hl=en).
1. [Connect your Google service account to Bitrise](/bitrise-platform/integrations/connecting-a-google-service-account-to-bitrise).

## Deploying to Google Play

Deploying to Google Play requires [a signed APK or AAB file](/bitrise-ci/code-signing/android-code-signing/android-code-signing-using-the-android-sign-step) and the **[Google Play Deploy](https://www.bitrise.io/integrations/steps/google-play-deploy)** Step.

**Workflow Editor**

1. [Upload your service account JSON key to the **Files** section](/bitrise-ci/run-and-analyze-builds/managing-build-files/uploading-files-for-your-builds).
1. In the **Files** section, copy the **Download URL** of your service account file.

   For example, `BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL`.
1. Open the Workflow Editor and select **Secrets**.
1. Create a Secret with the copied download URL as the value.

   If you uploaded the JSON key file to Bitrise, the download URL is an Environment Variable so check the **Replace variables in inputs** checkbox.

   :::note[Direct link]

   If you use a direct link to your keystore file without uploading it to Bitrise, you don't need to check the **Replace the variables in inputs** option.

   :::
1. Add the **Google Play Deploy** Step to your Workflow.
1. In the **Service Account JSON key file path** input, paste the Secret you created.
1. In the **Package name** input, add the package name of your app.
1. In the **Track** input, add the track where you want to deploy your APK (for example, alpha/beta/rollout/production or any custom track you set).

**Configuration YAML**

1. [Upload your service account JSON key to the **Files** section](/bitrise-ci/run-and-analyze-builds/managing-build-files/uploading-files-for-your-builds).

   :::note[Uploading the service account JSON key file]

   We recommend uploading the service account JSON key to Bitrise but it is not mandatory: you can store it elsewhere and provide a direct link to it.

   :::
1. Open your app's Configuration YAML file and add the `google-play-deploy` Step to it.

   ```yaml
   deploy-workflow:
     steps: 
     - google-play-deploy: 
         inputs:
   ```
1. In the `service_account_json_key_path` input, you need to provide the path to the service account JSON key file.

   [Create a Secret](/bitrise-ci/configure-builds/secrets) to the path and reference that here.

   ```yaml
   deploy-workflow:
     steps: 
     - google-play-deploy: 
         inputs:   
         - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL"
   ```
1. In the `package` input, add [the package name](https://support.google.com/admob/answer/9972781?hl=en#:~:text=The%20package%20name%20of%20an,supported%20third%2Dparty%20Android%20stores.) of your app.

   ```yaml
   deploy-workflow:
     steps: 
     - google-play-deploy: 
         inputs:   
         - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL"
         - package_name: myApp
   ```
1. In the `track` input, add the track where you want to deploy your app binary (for example, alpha/beta/rollout/production or any custom track you set).

   ```yaml
   deploy-workflow:
     steps: 
     - google-play-deploy: 
         inputs:   
         - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL"
         - package_name: myApp
         - track: alpha
   ```

That’s all! Start or schedule a build and share the URL with external testers or distribute your app on an app store of your choice!
