Aurimas Liutikas from the AndroidX team talks about performance tuning Gradle builds, remote caching, and tracking API compatibility with Metalava. They also discuss code optimization in Gradle, cross-sharing knowledge, understanding Gradle in Android development, and versioning and stability of AndroidX libraries and APIs.
AndroidX uses Gradle configuration caching, local caching, and remote caching to optimize build processes and improve build speed.
AndroidX prioritizes API compatibility through the use of Metalava and API lint, ensuring consistent and compatible APIs.
Optimizing Gradle and choosing efficient control flow techniques can significantly improve build configuration time and overall performance.
Deep dives
Optimizing AndroidX Build with Gradle and Configuration Caching
The AndroidX build system uses Gradle and configuration caching to optimize its build process. With approximately 800 Gradle modules, the majority being Android, Kotlin, and Kotlin Multi-platform Java, AndroidX leverages AGP, Kotlin Gradle plugin, and other tools to streamline its workflow. By adopting configuration cache early on and enabling it in Gradle ADOT1, AndroidX significantly improved its configuration phase, allowing faster builds. Additionally, AndroidX utilizes local caching for faster rebuilds and remote caching for sharing build results across the team through cloud storage. The use of remote caching enhanced their pre-submit times and iteration speed, while the decision to mark certain packaging tasks, like zip and non-compressed jar tasks, as not cacheable improved their overall performance.
Tracking API Compatibility with Meta-Lava for AndroidX
AndroidX prioritizes API compatibility by tracking and enforcing binary and source compatibility through the use of Meta-Lava. Meta-Lava is a tool developed by Tor Norby, now passed on to a new team, that analyzes the API surface and generates signature files for each version of AndroidX. This allows AndroidX to ensure that APIs are not modified in an incompatible way, and provides fine-grained control over the evolving APIs. Meta-Lava also supports Kotlin, capturing the Java view of Kotlin for compatibility checks. Additionally, AndroidX utilizes API lint for further API design checks, helping ensure consistent patterns in API naming and structure.
Ensuring API Stability with Signature File Checks
AndroidX employs signature file checks as part of the build process to validate API stability. Developers must update signature files when modifying public signatures to avoid breaking tests and ensure compatibility. API reviews are also conducted for any changes to the API surface, allowing experienced team members to review and provide oversight. The use of signature file checks and API reviews helps prevent inadvertent breaks in binary compatibility, ensuring that developers can easily upgrade AndroidX without issues.
Optimizing Gradle and the danger of using exceptions for control flow
One of the main ideas discussed in this podcast episode is the importance of optimizing Gradle and the potential pitfalls of using exceptions for control flow. The guest speaker shares an example where Gradle was using exceptions for control flow, resulting in a significant number of exceptions being thrown and caught during the build process. This led to performance issues and a long configuration time. However, when Gradle moved away from using exceptions, there were drastic improvements in configuration time, shaving off about 10 seconds. This highlights the importance of optimizing build processes and choosing efficient control flow techniques.
Collaboration between AndroidX, Gradle, and Kotlin Gradle plugin
Another key point of this podcast episode is the collaboration between AndroidX, Gradle, and the Kotlin Gradle plugin. The speakers discuss how their teams work together to improve the development workflow and optimize the build system. By collaborating and sharing knowledge, they are able to address performance issues, identify areas of improvement, and solve complex problems. They also mention the benefits of open-source projects, such as being able to see and learn from what other companies like Slack are doing. This collaboration and knowledge sharing help create a better ecosystem for developers and lead to more efficient build processes.
In this episode, Tor and Romain chat with Aurimas Liutikas from the AndroidX team. Topics include performance tuning the AndroidX Gradle builds using configuration caching, local caching and remote caching, as well as tracking API compatibility using the Metalava tool.