Skip to main content

Intermittent connection/timeout issues when downloading Android dependencies

Issue:

When Gradle attempts to download dependencies, you get intermittent timeout or connection errors.

Possible solutions:

There are numerous reasons why this can happen, and several potential solutions.

Using the Bitrise Maven Central repository manager

All Bitrise-hosted builds use the Bitrise Maven Central repository manager by default: a proxy cache in each datacenter that serves Gradle dependencies locally, protecting your builds from Maven Central rate limiting (HTTP 429 errors) and speeding up dependency resolution.

Usually no action is needed — but if you see 429 errors, check that your configuration isn't opting out: setting the BITRISE_MAVENCENTRAL_PROXY_ENABLED environment variable to false disables it. For how it works and special cases such as dependency verification, see Maven Central repository manager in the Bitrise docs.

Limiting the Maximum Number of Gradle Workers

Connection issues might increase after upgrading to a more powerful machine. This is because Gradle uses the additional processor threads to download more dependencies simultaneously. This can result in rate limiting errors.

One workaround is to limit the number of threads Gradle can use by specifying the maximum number of workers.

If you are calling a Gradle task from a Script Step, add the following argument:

--max-workers=4

Alternatively, you can add the following to your gradle.properties file:

org.gradle.workers.max=(max # of worker processes)

Retrying Failed Connections

Some dependencies from third parties may be using unstable hosting. In these instances, retrying a failed download can sometimes resolve the issue and keep the build from failing.

To have Maven retry connections, add the following to your gradle.properties file:

maven.wagon.http.retryHandler.count = 5

Committing Dependencies to Source Control

We highly recommend committing dependencies to your repository. Not only does this help with stability, but it dramatically decreases build times as well.

Additional information:

Did this answer your question?