{"id":9060,"date":"2026-11-25T23:12:18","date_gmt":"2026-11-25T23:12:18","guid":{"rendered":"https:\/\/lockitsoft.com\/?p=9060"},"modified":"2026-11-25T23:12:18","modified_gmt":"2026-11-25T23:12:18","slug":"google-play-enforces-new-dex-code-optimization-thresholds-and-urges-library-developers-to-refine-r8-keep-rules-for-peak-android-app-performance","status":"publish","type":"post","link":"https:\/\/lockitsoft.com\/?p=9060","title":{"rendered":"Google Play Enforces New DEX Code Optimization Thresholds and Urges Library Developers to Refine R8 Keep Rules for Peak Android App Performance"},"content":{"rendered":"<p>As the Android ecosystem continues to mature, application and library developers face a shared imperative: delivering performant apps that guarantee a seamless, responsive user experience. At the center of this technical optimization effort lies R8, Android\u2019s native app optimizer, which improves runtime performance by stripping away unused code while concurrently optimizing and obfuscating the remainder. Google recently introduced stricter DEX code optimization thresholds for apps and games distributed through Google Play. Designed to accelerate startup times, trim memory footprints, and safeguard the user experience against memory-heavy applications, these thresholds place new performance demands on the entire development pipeline. Because R8 can only optimize software within the boundaries of its assigned parameters\u2014which explicitly include the keep rules bundled by third-party libraries\u2014meeting these rigorous benchmarks has become a collective responsibility across the entire developer ecosystem.<\/p>\n<p>To assist developers in auditing these metrics, tools such as the R8 Configuration Analyzer provide deep visibility into shrinking, obfuscation, and overall optimization percentages. Beyond tracking these performance figures, the tool surfaces inefficient keep rules originating not just from the main application binary, but also from the consumer keep rules embedded within upstream dependencies. As developers race to comply with Google Play\u2019s technical mandates, optimizing library-level configurations has transformed from a routine maintenance task into a critical engineering priority.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/lockitsoft.com\/?p=9060\/#Understanding_Consumer_Keep_Rules_and_Their_Ecosystem_Impact\" >Understanding Consumer Keep Rules and Their Ecosystem Impact<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/lockitsoft.com\/?p=9060\/#Balancing_Software_Stability_with_Aggressive_Performance\" >Balancing Software Stability with Aggressive Performance<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/lockitsoft.com\/?p=9060\/#1_Transitioning_from_Reflection_to_Code_Generation\" >1. Transitioning from Reflection to Code Generation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/lockitsoft.com\/?p=9060\/#2_Scoping_Keep_Rules_Narrowly_Across_All_Scenarios\" >2. Scoping Keep Rules Narrowly Across All Scenarios<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/lockitsoft.com\/?p=9060\/#3_Distributing_Rules_via_Artifacts_Rather_Than_Documentation\" >3. Distributing Rules via Artifacts Rather Than Documentation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/lockitsoft.com\/?p=9060\/#4_Managing_Stack_Traces_Without_Sacrificing_Optimization\" >4. Managing Stack Traces Without Sacrificing Optimization<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/lockitsoft.com\/?p=9060\/#Implications_and_the_Path_Forward\" >Implications and the Path Forward<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Understanding_Consumer_Keep_Rules_and_Their_Ecosystem_Impact\"><\/span>Understanding Consumer Keep Rules and Their Ecosystem Impact<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Consumer keep rules are internal instructions bundled directly within Android or Java Archive (JAR) libraries. They inform the R8 compiler which segments of a library\u2019s codebase must remain untouched during the whole-app compilation and minification phase. Unlike standard app-level configuration rules written for specific artifacts, consumer keep rules operate invisibly from within dependencies. They dictate how a library shrinks when merged into a larger application, ensuring that internal reflection targets and native interfaces remain intact without forcing app developers to manually trace and identify them.<\/p>\n<p>When properly scoped, intentional, and narrowly defined consumer keep rules benefit both the library vendor and the downstream consumer. However, overly broad keep rules\u2014such as package-wide exemptions\u2014inadvertently preserve swathes of dead code. This unnecessary code bloat directly impedes R8\u2019s ability to perform whole-program optimization, resulting in degraded runtime performance, sluggish application launches, and inflated binary sizes. With the integration of DEX code optimization insights directly into the Google Play Console, the metrics visible to app publishers now reflect the combined, cumulative footprint of code rules from both the host application and every integrated library.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Balancing_Software_Stability_with_Aggressive_Performance\"><\/span>Balancing Software Stability with Aggressive Performance<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Library authors often ship broad consumer keep rules with good intentions, aiming to shield their software development kits (SDKs) from runtime crashes caused by the accidental removal of classes accessed via reflection. Nevertheless, package-wide directives are a poor long-term solution for crash prevention. By blanketing entire packages, these broad rules neuter R8\u2019s optimization potential. <\/p>\n<p>Industry data and performance audits indicate that bloated SDKs directly contribute to higher application-not-responding (ANR) rates, increased memory consumption, and extended cold-start latencies. Furthermore, performance-conscious application developers frequently resort to writing custom override rules to neutralize poorly optimized library configurations, a friction point that often discourages them from adopting subsequent library updates due to regression risks.<\/p>\n<p>To reconcile the competing demands of runtime stability and elite performance, library maintainers are encouraged to adopt a series of targeted engineering strategies.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"1_Transitioning_from_Reflection_to_Code_Generation\"><\/span>1. Transitioning from Reflection to Code Generation<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>The most effective method for preventing reflection-related crashes without sacrificing optimization is to replace runtime reflection with code generation (codegen) wherever feasible. Runtime reflection obscures code execution paths from R8 during the build phase, necessitating broad keep rules to prevent runtime failures. Conversely, code generation executes during compilation, granting R8 complete visibility into the code graph and enabling safe, aggressive optimization with minimal keep rules. Common implementation areas for codegen include object serialization and deserialization, as well as modern dependency injection frameworks such as Hilt.<\/p>\n<p>While reflection remains occasionally necessary\u2014particularly when managing optional dependencies\u2014it should be paired with strictly narrow keep rules that protect only the precise entry points required for integration.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"2_Scoping_Keep_Rules_Narrowly_Across_All_Scenarios\"><\/span>2. Scoping Keep Rules Narrowly Across All Scenarios<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Even when reflection cannot be avoided, library providers must ensure that consumer keep rules specify only the exact classes or methods accessed dynamically. When a library invokes a class via reflection, specifying the single entry point is sufficient; R8 autonomously constructs a reference graph and prunes all unreferenced ancillary code. <\/p>\n<p>This principle holds true even for pre-optimized or obfuscated library builds. Because consumer keep rules execute during the app-level compilation step, R8 retains the ability to further trim and optimize the library based on the subset of features actually utilized by the downstream application. The Android CLI analyze command serves as a valuable utility here, proactively identifying unused package-wide rules that obstruct optimization.<\/p>\n<p>Third-party dependencies must be handled with equal care. Broad rules such as <code>-keep public class com.google.android.gms.**  *; <\/code> frequently override narrower configurations established by other parts of an application, leading to severe code bloat. Developers integrating external libraries should design rules that isolate only the accessed components, respecting the pre-existing, finely tuned consumer rules bundled by foundational libraries like Google Play Services.<\/p>\n<p>For ad mediation adapters and similar modular architectures, conditional keep rules offer a pragmatic alternative. By utilizing conditional instructions, libraries can preserve specific features or formats only when the host application includes the corresponding adapter, allowing R8 to shrink unused modules. Alternatively, emerging tools like Jetpack Keep annotations\u2014currently available in alpha\u2014allow developers to annotate reflection usage directly within source code, automating the generation of precise conditional consumer keep rules at build time.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"3_Distributing_Rules_via_Artifacts_Rather_Than_Documentation\"><\/span>3. Distributing Rules via Artifacts Rather Than Documentation<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>A persistent anti-pattern in SDK maintenance involves relegating keep rules to online documentation rather than bundling them within the library artifact. Relying on documentation introduces manual integration friction and long-term maintenance overhead. Every time a library undergoes refactoring, class renaming, or architectural updates, developers must remember to update external guides, while consuming apps must actively track and apply these modifications. Over time, apps integrating multiple library versions accumulate legacy keep rules that no longer serve a purpose, steadily compounding application bloat. Shipping consumer rules directly inside Android Archives (AARs) and JARs ensures out-of-the-box compatibility and maximum optimization without manual intervention.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"4_Managing_Stack_Traces_Without_Sacrificing_Optimization\"><\/span>4. Managing Stack Traces Without Sacrificing Optimization<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>When debugging production issues, developers frequently encounter unreadable stack traces resulting from code obfuscation. To bypass this obstacle, teams are sometimes tempted to utilize the <code>keepnames<\/code> directive. While <code>keepnames<\/code> permits code shrinking, it explicitly prevents subsequent optimizations like identifier renaming within the consuming application\u2014sacrificing the exact performance gains needed in production builds.<\/p>\n<p>Fortunately, modern development environments eliminate the need to compromise optimization for debugging clarity. Platforms including Firebase Crashlytics, the Google Play Console, and Android Studio\u2019s Logcat automatically deobfuscate release stack traces for developers. Furthermore, uploading mapping files to the dedicated SDK Console enables maintainers to inspect fully deobfuscated trace logs without weakening their library\u2019s obfuscation parameters.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Implications_and_the_Path_Forward\"><\/span>Implications and the Path Forward<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The enforcement of stricter DEX code optimization thresholds by Google Play marks a philosophical shift in Android development, moving away from permissive compilation defaults toward rigorous resource management. For library vendors, the era of shipping broad, package-wide keep rules is drawing to a close. <\/p>\n<p>By embracing precise codegen, adopting narrow keep rules, leveraging Jetpack annotations, and distributing configurations directly through library artifacts, maintainers can eliminate the guesswork from application optimization. As the ecosystem adapts to these higher performance standards, proactive auditing of consumer keep rules will remain essential for ensuring that dependent applications achieve peak speed, minimal memory usage, and enduring stability on millions of devices worldwide.<\/p>\n<!-- RatingBintangAjaib -->","protected":false},"excerpt":{"rendered":"<p>As the Android ecosystem continues to mature, application and library developers face a shared imperative: delivering performant apps that guarantee a seamless, responsive user experience. At the center of this technical optimization effort lies R8, Android\u2019s native app optimizer, which improves runtime performance by stripping away unused code while concurrently optimizing and obfuscating the remainder. &hellip;<\/p>\n","protected":false},"author":9,"featured_media":9059,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[21,4,669,290,5,5569,285,5572,623,3,81,3979,282,813,5571,2499,5570,629],"class_list":["post-9060","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mobile-application-development","tag-android","tag-apps","tag-code","tag-developers","tag-development","tag-enforces","tag-google","tag-keep","tag-library","tag-mobile","tag-optimization","tag-peak","tag-performance","tag-play","tag-refine","tag-rules","tag-thresholds","tag-urges"],"_links":{"self":[{"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/posts\/9060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9060"}],"version-history":[{"count":0,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/posts\/9060\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=\/wp\/v2\/media\/9059"}],"wp:attachment":[{"href":"https:\/\/lockitsoft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lockitsoft.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}