Skip to content
Book Cover of Extending Android Builds

Reader's Guide ​

Extending Android Builds (EAB) goes beyond Gradle configuration. It focuses on Gradle Plugin development that cooperates with Android Gradle Plugin (AGP) and related build tools such as AAPT2, Kotlin Symbol Processing (KSP) and bytecode manipulators. With the help of multiple hands-on demos and case studies, you will learn how to craft Gradle plugins and tasks, how to integrate with the AGP APIs, and best practices for architecting, testing, and debugging Android builds. EAB explains not only "what" and "how", but also "why"β€”the art behind Gradle and AGP designs.

Who should read this book ​

This book mainly targets intermediate-level (and above) Android developers, and all other Gradle users who have a need for Gradle skills sharpening on Android field, such as Java, React Native or Flutter developers.

The majority of the knowledge prerequisites fall into three categories:

  1. Gradle: including a basic understanding of build scripts, CLI commands and flags, Task essentials, and dependency management.
  2. Android Gradle Plugin: including common Android Gradle Plugin extensions and package commands.
  3. Kotlin: including basic syntax and DSL capabilities.

Most of the content in these three categories can be found in the respective official documentation. It is recommended to familiarize yourself with these materials, gain a broad understanding, and then delve deeper into specific cases with this book.

Preparatory learning materials - KOGE ​

KOGE (https://koge.2bab.com) is an open-source handbook for preparatory learning. It stands for Kotlin-oriented Gradle Essentials and organizes the most confusing concepts for beginners in a logical sequence, drawing from existing questions, source code, and sample projects already available on the internet. It's not a collection of projects like "Awesome Gradle," but rather a concise self-learning guide.

The handbook uses Kotlin as the primary language to introduce Gradle scripting and basic tasking skills, with a focus on Android build scenarios.

How this book is organized ​

In total, EAB covers 8 chapters with 39 sections. After reading this book, you will be able to:

  • Utilize the Kotlin language for both Gradle scripts and plugins.
  • Author Gradle plugins/tasks with confidence while effectively interacting with AGP APIs and Gradle raw APIs.
  • Monitor and modify various aspects of the Android build process, including resource files, source code, JVM bytecode, and even their combinations using AAPT2, Kotlin Symbol Processing (KSP), and multiple bytecode modifiers.
  • Ensure that the plugin is both robust and low-cost to maintain, following the simple test pyramid.
  • Adhere to the latest best practices in App architecture that align with many Gradle golden rules and offer extensibility for developers.
  • Reduce the build time of the Android application and enhance the efficiency of their existing CI/CD workflows.

The recommended approach for reading this book is chapter by chapter, as the content is organized with the following three steps:

  1. Chapters 1 to 2: Establishing fundamental understanding of Gradle, Android Gradle Plugin, and relevant Android build tools.
  2. Chapters 3 to 4: Discussing core techniques for extending Android builds, introducing advanced Gradle skills, and the raw APIs for plugin development (instead of DSL APIs used often in scripts).
  3. Chapters 5 to 8: Enhancing comprehension of Android builds through samples and case studies involving resource, source code, and JVM bytecode extensions, alongside appropriate build monitoring and analysis techniques to boost overall performance.

It's clear that the content of most subsequent chapters builds upon the knowledge from preceding ones. Additionally, to summarize each chapter:

  • Chapter 1, Concepts and Little Handmade: Provides insight into Gradle and Android Gradle Plugin basics, alongside manual Android app creation.
  • Chapter 2, Quick Start: Offers hands-on experience in structuring Gradle projects, understanding lifecycle, plugins, tasks, and creating a basic Gradle plugin for Slack notifications.
  • Chapter 3, The Key of Extending Android Builds: Focuses on mastering Android Gradle Plugin's Variant and Artifact APIs for efficient and customizable builds.
  • Chapter 4, Diving into the Gradle Raw APIs: Explores advanced Gradle raw API features like lifecycle hooks, lazy properties, task orchestration, and caching mechanisms.
  • Chapter 5, Extension of Android Resources Build: Covers manipulation of Android resources through AGP Extensions, with insights into AAPT2 internals for optimized builds.
  • Chapter 6, Extension of Source Code Build: Discusses manipulating source code through AGP Extensions and understanding Kotlin Symbol Processing (KSP) for code generation.
  • Chapter 7, Extension of the JVM Bytecode Build: Explores JVM bytecode manipulation using AGP APIs and tools, including Aspect-oriented Programming (AOP) at the bytecode level.
  • Chapter 8, Improving the Build Experience: Focuses on optimizing build experiences through analysis, performance tuning, and conditional plugin application.

For readers who prefer not to start from the beginning:

  1. If you're familiar with AGP configuration but less so with custom Gradle plugins, you can try Chapters 2 and 4 first, then proceed to other chapters.
  2. For those experienced in Gradle and interested in extending Android builds, dive directly into Chapters 3, 5, 6, or 7 based on your interests.
  3. If you seek quick adoption of latest techniques and best practices, feel free to skip deep technical details and historical background, such as Sections 1-3, 3-2, 3-4, 3-5, 7-2, etc.

Conventions ​

This book uses the following typographical conventions:

  • The italic font is used to introduce new terms.
  • Code samples, function names, classes, and other identifiers are denoted using a fixed-width font.
  • The Uppercase is used for titles, technical terms, acronyms, brands, companies. Additionally, the capitalized words "Task" and "Plugin" in this book specifically refer to two concepts within Gradle.

Errata ​

For the latest errata feedback and to submit any errors or feedback on the text or samples, please visit the Playground Github repository (https://github.com/2BAB/Extending-Android-Builds-Playground/blob/main/errata.md). Your contributions are invaluable in ensuring the accuracy of this work.

Additonal Resources ​

Kindly refer to Appendix A for a complete list of references and samples.

Extending Android Builds - Pragmatic Gradle and AGP Skills with Kotlin

Copyright Since 2023.

All rights reserved. This book or any portion thereof may not be reproduced or used in any manner whatsoever without the express written permission of the publisher except for the use of brief quotations in a book review.