In the ongoing quest to deliver fast, highly performant applications that ensure a seamless user experience, Android developers have long relied on R8, the platform’s native app optimizer. R8 operates by stripping away unused code while expertly optimizing and obfuscating the remainder. Now, Google Play is intensifying these performance efforts by introducing strict new DEX code optimization thresholds for apps and games alike. These thresholds are designed to drastically improve startup times, minimize memory footprints, and align with Android’s overarching commitment to shielding the user experience from applications that consume excessive system memory. While these stringent performance thresholds apply directly to end-user applications and games, meeting them is fundamentally a shared responsibility across the entire Android development ecosystem. Because R8 can only optimize an application within the exact parameters it is given, the performance outcome is heavily influenced by the keep rules bundled inside the various libraries that apps depend on. To help developers navigate these tighter requirements, the R8 Configuration Analyzer has emerged as an essential tool for assessing app optimization, shrinking, and obfuscation percentages—metrics that now sit at the heart of Google Play’s core technical requirements. Beyond simply tracking these percentages, the R8 Configuration Analyzer actively surfaces inefficient keep rules originating not just from the main application code, but also from the consumer keep rules bundled deep within third-party libraries. Addressing these challenges is vital for library providers aiming to ship narrow, high-performance rules that help downstream customers successfully clear Google Play’s updated technical hurdles. Read Also: Google Expands Play Age Signals API Globally to Enhance Family Safety and Developer Flexibility Android Dev Summit Makes a Triumphant Return After Four-Year Hiatus in Mountain View and London What are consumer keep rules? Consumer keep rules are specialized instructions embedded directly within Android or JAR libraries that inform R8 which specific portions of the library code must be left untouched during the app-level compilation and minification process. Unlike standard keep rules written by an app developer to manage their own custom artifacts, consumer keep rules travel inside the library itself. They dictate how that library is miniaturized during whole-app optimization, ensuring that critical internal reflection targets and native interfaces remain fully functional without requiring the app developer to manually identify and protect them. Intentionally designed, narrowly scoped consumer keep rules represent a vital industry best practice that benefits both the library author and the developers who consume the SDK. Conversely, overly broad consumer keep rules inadvertently preserve large swaths of unused code, severely undercutting an application’s optimization potential and dragging down overall performance. With new DEX code optimization insights officially integrated into the Google Play Console, the performance metrics visible to developers now reflect the combined, cumulative impact of rules originating from both the application itself and every integrated library. Balancing stability and performance Library providers are almost always well-intentioned when they ship broad consumer keep rules. Naturally, no developer wants their software development kit to trigger catastrophic runtime crashes due to unexpected class removal caused by reflection. However, package-wide or otherwise overly broad keep rules are ultimately unsustainable as a long-term solution for crash prevention, because they place a hard ceiling on R8’s whole-program app optimization capabilities. Shipping a library packed with broad or package-wide keep rules does more than merely impact the SDK in isolation; it forces downstream developers to accept substantial code bloat. This unnecessary bloat actively slows down app startup times, expands download sizes, drives up memory usage, and contributes to higher rates of Application Not Responding errors. Furthermore, performance-minded application teams frequently resort to writing custom rules to override and filter out the bloated rules bundled with poorly optimized libraries, a friction point that often discourages these teams from adopting future library updates due to the inherent risk of breakage. For SDKs that target native code—such as those commonly utilized in games or heavy photo and video editing applications—it is crucial to provide precise rules for all classes that leverage the Java Native Interface. Because the vast majority of modern mobile games operate on top of robust game engines like Unity or Unreal, which compile down to native code, the game engine and external plugins must communicate smoothly with the broader Android framework via JNI calls. Utilizing modern approaches, such as Jetpack Keep annotations, can significantly reduce the maintenance burden traditionally associated with reflection by allowing developers to annotate reflection usage directly, which in turn generates precise keep rules automatically at build time. Navigating code generation and reflection To completely avoid crashes stemming from runtime reflection, the industry consensus strongly favors adopting code generation where possible. Runtime reflection fundamentally hides code execution paths from R8 during the compilation phase, forcing developers to rely on protective keep rules to prevent runtime crashes. When applications utilize code generation instead, the code is fully processed and optimized during the build process itself, giving R8 the comprehensive visibility required to safely optimize the codebase with minimal keep rules. Common scenarios where code generation shines include complex serialization and deserialization tasks, as well as dependency injection frameworks like Hilt. Despite its clear advantages, code generation is not a universal fix for every architectural pattern. For certain flexible patterns, such as optional dependencies, runtime reflection remains entirely necessary. In these instances, the industry recommends pairing necessary reflection with narrowly scoped keep rules that protect only the absolute required entry points, rather than blanketing entire packages. Even when pre-optimizing or obfuscating a library build—which remains an excellent practice for delivering a lightweight and performant SDK—maintaining narrow scopes is critical. Because consumer rules are applied directly during the consuming application’s compilation step, R8 retains the ability to further optimize the library based strictly on the classes and methods that are actively utilized by the downstream app. The Android CLI analyze command serves as a powerful utility for proactively uncovering both used and unused package-wide keep rules that are actively blocking optimization across the ecosystem. Another common pitfall involves interacting with external third-party dependencies. Developers frequently write broad keep rules targeting entire packages of foundational services, such as Google Mobile Services. If an application integrating an SDK also utilizes another service library and includes its own rules to limit code retention, a broad rule from a dependent library will supersede it, reintroducing unnecessary app bloat. When invoking external libraries, keep rules must be designed to strictly preserve only the specific elements accessed through reflection. Additionally, many foundational libraries already ship their own robust consumer keep rules, meaning the introduction of a package-wide keep rule can inadvertently swallow and nullify carefully crafted, narrow rules provided by downstream dependencies. For ad mediation adapters, where ad libraries are loaded dynamically, narrow keep rules remain entirely achievable through the use of conditional keep rules. These specialized rules ensure that specific features or formats are preserved only if the application includes the corresponding ad adapter, allowing R8 to successfully shrink features that the app leaves unused. Alternatively, developers can utilize Jetpack Keep annotations to mark reflective calls directly in the source code, automating the generation of conditional consumer keep rules for optional add-on modules without requiring hand-written configurations. Ultimately, shipping consumer rules directly alongside the library ensures that applications with R8-enabled builds can utilize the software out of the box and unlock maximum performance optimization. Relying on documentation to specify manual configuration steps adds unnecessary friction and creates ongoing maintenance overhead, as updating the library requires remembering to update documentation while forcing apps to continuously check for new requirements. Over time, as applications upgrade through successive versions of a library, they risk accumulating legacy keep rules that are no longer required, leading to persistent app bloat. Reading release stack traces and looking forward Debugging obfuscated code can occasionally present hurdles when stack traces become unreadable in production releases. While some developers might be tempted to utilize settings that allow shrinking while preventing renaming transformations in the consuming app—thereby preserving readable stack traces—this approach sacrifices valuable optimization potential. Fortunately, modern debugging environments such as Firebase Crashlytics, the Google Play Console, and Logcat within Android Studio are fully equipped to automatically deobfuscate stack traces for developers, eliminating the need to compromise app performance for the sake of readability. By uploading mapping files to the SDK Console, teams can easily view fully deobfuscated stack traces without sacrificing optimization depth. Taking the guesswork out of app optimization is essential for the continued health of the Android ecosystem. By maintaining disciplined consumer keep rules, library providers ensure that downstream applications are never blocked from achieving peak optimization. When libraries ship with precise, high-performance rules, entire applications become smaller, faster, and far more reliable for users worldwide. Post navigation Google Announces Linux Terminal Preview for Googlebook to Empower Modern AI Workflows and Agentic Development