Mobile Development 13 min read

Cut Android Build Times by Up to 90% Using Componentized Gradle and Remote Compilation

Facing sluggish Gradle builds for a large Android news app, the team applied componentized compilation, Artifactory caching, minimal compile mode, parameter tuning, and remote compilation via SSH, achieving up to 90% faster non‑incremental builds and 75% faster incremental builds while maintaining stability across the CI pipeline.

NetEase Media Technology Team
NetEase Media Technology Team
NetEase Media Technology Team
Cut Android Build Times by Up to 90% Using Componentized Gradle and Remote Compilation

Background and Motivation

NetEase News, a large Android application, suffered from increasingly heavy code and slow Gradle build times, prompting the team to explore a series of build‑speed optimizations.

1. Componentized Compilation

The team first leveraged componentization to clarify module boundaries and enable "independent component compilation". By splitting the project into two phases and defining clear dependencies, each component could be compiled separately, reducing overall build time.

2. Artifactory Dependency Management

Network constraints caused long delays when fetching third‑party dependencies. To mitigate this, the team set up a JFrog Artifactory repository to cache dependencies. Subsequent builds retrieve artifacts from the local Artifactory cache, eliminating repeated remote fetches and clarifying repository boundaries.

3. Build Scan Analysis

Gradle Enterprise’s Build Scan was used to identify tasks exceeding one second. The analysis revealed that Transform and Compile tasks dominated the build time, mainly due to the large codebase.

4. Minimal Compile Mode

4.1 Analysis Tools

Build Scan reports were used to pinpoint slow tasks, and ClassyShark was employed to analyze APK class size distribution, identifying non‑essential classes (e.g., SDKs for push notifications) that could be excluded.

4.2 SDK/Source Isolation

A flag MiniDependencies was added to gradle.properties. Build scripts read this flag to conditionally include or exclude SDKs and source sets. The design supports a global switch or per‑SDK sub‑switches.

When the flag is disabled, SDKs are enabled and linked via sourceSets.main and dependencies. When enabled, those links are removed, preventing the SDKs from being compiled.

Ignored SDKs are accessed through proxy classes and an SDKManager that loads implementations via reflection only when the mode is off.

Implementation classes reside in an Optional area, compiled only when minimal mode is off.

Interface definitions stay in a Host area, always compiled.

4.3 Ignored Types

Vendor push SDKs

Non‑core analytics

Optional features such as patches

5. Benefits

Build Scan tests (10 runs) showed a 20% speed increase for a cold build and about 25% after a clean when minimal compile mode was enabled. Overall, after all optimizations, build performance improved roughly 50%.

6. Parameter Tuning

Common Gradle tuning parameters (Daemon, Build Cache, etc.) were unified across the team via a Hook task that injects settings into gradle.properties. Additional tweaks disabled Lint in Debug builds and adjusted settings for Release builds.

7. Remote Compilation

7.1 Design

Using SSH, the project files are synchronized to a remote machine, Gradle commands are executed there, and the resulting APK is synced back to the local machine.

7.2 File Synchronization

The "Quick Check" algorithm identifies incremental file changes, syncing only those while ignoring the large and frequently changing .git directory. Only the final APK is transferred to reduce bandwidth.

7.3 Android Studio Integration

Android Studio’s Configuration component was extended to provide a one‑click remote compile button and to store configuration in version control for team collaboration.

7.4 Workflow

The remote compilation workflow consists of three stages: SSH configuration, remote execution, and local post‑processing. SSH keys and configs are distributed automatically to team members.

7.5 Performance Impact

Testing on two machines showed an 82% increase in non‑incremental and 57% in incremental compile performance on the faster remote host. Remote compilation adds a one‑time file sync overhead, but incremental sync time is negligible.

8. Overall Project Gains

Non‑incremental builds up to 90% faster.

Incremental builds up to 75% faster.

When the remote machine meets the required performance threshold, build speed feels "lightning fast".

9. Conclusion

The combination of componentized Gradle builds, Artifactory caching, minimal compile mode, systematic parameter tuning, and remote compilation delivers substantial reductions in build time while preserving build stability, offering a practical blueprint for large Android projects.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

AndroidBuild OptimizationGradleComponentizationArtifactoryRemote Compilation
NetEase Media Technology Team
Written by

NetEase Media Technology Team

NetEase Media Technology Team

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.