> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trunk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Android

> A guide for generating Trunk-compatible test reports for Android projects

You can automatically [detect and manage flaky tests](../../detection/) in your Android projects by integrating with Trunk. This document explains how to configure Android to output JUnit XML reports that can be uploaded to Trunk for analysis.

## Setup steps

Work through the steps below in order. Once you've finished the last one, you'll be ready to move on to [configure uploads in CI](../ci-providers/).

**1. [Generate a compatible test report](#generating-reports)**

**2. [Configure the report file path or glob](#report-file-path)**

**3. [Test uploads locally](#try-it-locally)**

## Generating reports

Android tests run with Gradle, typically using `./gradlew test` in CI. This will generate JUnit XML output by default, which you can further configure in your `build.gradle.kts` or `build.gradle`.

### Report file path

By default, Android projects will produce a directory with JUnit XML reports under `./app/build/test-results`.

You can customize the report output location in your `build.gradle.kts` or `build.gradle`, for example, writing the reports to `./app/junit-reports`.

```groovy Groovy theme={"system"}
android {
    testOptions {
        unitTests {
            all {
                reports {
                    junitXml {
                        outputLocation = file("./junit-reports")
                    }
                }
            }
        }
    }
}
```

```kotlin Kotlin theme={"system"}
android {
    testOptions {
        unitTests {
            all {
                reports {
                    junitXml.outputLocation.set(file("./junit-reports"))
                }
            }
        }
    }
}
```

When you configure your CI provider to upload reports in later steps, you will be uploading the reports using a glob such as `./junit-reports/*.xml`.

## Try It Locally

### The Validate Command

You can validate your test reports using the [Trunk Analytics CLI](https://docs.trunk.io/flaky-tests/reference/cli-reference.md). If you don't have it installed already, you can install and run the `validate` command like this:

```bash Linux (x64) theme={"system"}
SKU="trunk-analytics-cli-x86_64-unknown-linux.tar.gz"
VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4)
curl -fL --retry 3 \
  "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \
  | tar -xz

chmod +x trunk-analytics-cli
./trunk-analytics-cli validate --junit-paths "./junit-reports/*.xml"
```

```bash Linux (arm64) theme={"system"}
SKU="trunk-analytics-cli-aarch64-unknown-linux.tar.gz"
VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4)
curl -fL --retry 3 \
  "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \
  | tar -xz

chmod +x trunk-analytics-cli
./trunk-analytics-cli validate --junit-paths "./junit-reports/*.xml"
```

```bash macOS (arm64) theme={"system"}
SKU="trunk-analytics-cli-aarch64-apple-darwin.tar.gz"
VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4)
curl -fL --retry 3 \
  "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \
  | tar -xz

chmod +x trunk-analytics-cli
./trunk-analytics-cli validate --junit-paths "./junit-reports/*.xml"
```

```bash macOS (x64) theme={"system"}
SKU="trunk-analytics-cli-x86_64-apple-darwin.tar.gz"
VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4)
curl -fL --retry 3 \
  "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \
  | tar -xz

chmod +x trunk-analytics-cli
./trunk-analytics-cli validate --junit-paths "./junit-reports/*.xml"
```

**This will not upload anything to Trunk**. To improve detection accuracy, you should **address all errors and warnings** before proceeding to the next steps.

### Test Upload

Before modifying your CI jobs to automatically upload test results to Trunk, try uploading a single test run manually.

You make an upload to Trunk using the following command:

```sh theme={"system"}
./trunk-analytics-cli upload --junit-paths "./junit-reports/*.xml" \
    --org-url-slug <TRUNK_ORG_URL_SLUG> \
    --test-collection-id <TRUNK_TEST_COLLECTION_ID> \
    --token <TRUNK_ORG_TOKEN>
```

## Next Steps

Configure your CI to upload test runs to Trunk. Find the guides for your CI framework below:

> [card] [Azure DevOps Pipelines](https://docs.trunk.io/flaky-tests/get-started/ci-providers/azure-devops-pipelines.md)

> [card] [BitBucket Pipelines](https://docs.trunk.io/flaky-tests/get-started/ci-providers/bitbucket-pipelines.md)

> [card] [BuildKite](https://docs.trunk.io/flaky-tests/get-started/ci-providers/buildkite.md)

> [card] [CircleCI](https://docs.trunk.io/flaky-tests/get-started/ci-providers/circleci.md)

> [card] [Drone CI](https://docs.trunk.io/flaky-tests/get-started/ci-providers/droneci.md)

> [card] [GitHub Actions](https://docs.trunk.io/flaky-tests/get-started/ci-providers/github-actions.md)

> [card] [GitLab](https://docs.trunk.io/flaky-tests/get-started/ci-providers/gitlab.md)

> [card] [Jenkins](https://docs.trunk.io/flaky-tests/get-started/ci-providers/jenkins.md)

> [card] [Semaphore](https://docs.trunk.io/flaky-tests/get-started/ci-providers/semaphoreci.md)

> [card] TeamCity

> [card] [Travis CI](https://docs.trunk.io/flaky-tests/get-started/ci-providers/travisci.md)

> [card] [Other CI Providers](https://docs.trunk.io/flaky-tests/get-started/ci-providers/otherci.md)
