By NHI Mgmt Group Editorial TeamBased on Guardsquare: “From Keep Rules to Guided Configuration” (April 7, 2026)

TL;DR: Android optimizers such as ProGuard and R8 can break apps when reflection-dependent classes are renamed or removed, and that debugging keep rules often requires iterative crash analysis, according to Guardsquare. Its guided workflow claims to collect the needed keep rules during instrumentation so teams can configure protection with less trial and error.


At a glance

What this is: This article explains why Android optimisation tools can break reflection-heavy apps and how a guided workflow can collect keep rules during profiling to reduce crash-driven iteration.

Why it matters: It matters to mobile security and engineering teams because brittle obfuscation settings can create availability failures, while overly broad keep rules can weaken protection and hide misconfiguration in release pipelines.


Context

Android code shrinking and obfuscation change class names, method names, and sometimes code paths to reduce app size and expose less implementation detail. That creates a governance problem for teams that depend on reflection, because runtime lookups expect symbols that the optimiser may rename or remove.

The article’s real issue is not optimisation itself but the control boundary around it. Mobile teams need a way to preserve intended runtime behaviour without giving up the security and packaging benefits of obfuscation, especially when libraries perform reflective access behind the application’s own code.

For Android app teams, this is a common failure mode rather than an edge case. Any app using reflection-heavy libraries can encounter the same tension between protection strength and functional safety when keep rules are incomplete.


Key questions

Q: What should teams do when an Android app crashes after enabling R8 or ProGuard?

A: Start by tracing the failing class or method back through the retraced stack trace and mapping file, then identify whether reflection or another dynamic lookup depends on names that optimisation changed. Add the smallest keep rule that restores the behaviour, test again, and avoid broad preservation unless the crash proves the scope is still too narrow.

Q: Why do reflection-heavy Android apps need more careful keep rule governance?

A: Because reflection depends on runtime names that obfuscation and shrinking are designed to change. If a serializer, injector, or loader expects a class or field name that no longer exists, the app can fail only after packaging. Governance has to preserve the runtime contract without disabling optimisation across unrelated code.

Q: What do security teams get wrong about broad keep rules?

A: They treat broad preserve rules as a safe fallback, but those rules can weaken shrinking and obfuscation across far more code than necessary. That creates long-term security debt because the app remains functional while the protection posture becomes less precise and easier to reverse engineer.

Q: When is guided profiling better than manual keep rule debugging?

A: It is better when an app has multiple reflective paths, mixed libraries, or a large codebase where crash-led iteration would take several build-test cycles. Guided profiling captures runtime behaviour directly, so teams can gather the needed rules in one controlled run instead of inferring them from repeated failures.


Technical breakdown

Why reflection breaks after shrinking and obfuscation

ProGuard, R8, and similar tools rewrite application structure by renaming identifiers, removing unused code, and merging or relocating classes and methods. Reflection depends on stable runtime names, so a class that is present in source can become unreachable if its symbol changes during optimisation. Library code makes this harder because the application may not call reflection directly, yet still depend on it through a dependency such as a JSON serializer. The result is a runtime failure that only appears after packaging, not during ordinary compilation or static analysis.

Practical implication: Treat reflection as a compatibility dependency and identify every code path where runtime lookup depends on stable names before enabling aggressive shrinking.

Why broad keep rules solve crashes but weaken optimisation

A keep rule tells the optimiser to preserve selected classes, methods, or fields from transformation. That prevents crashes, but broad rules can also preserve more than necessary, reducing obfuscation and shrinking benefits across the app. The article shows why this matters: a rule that protects one library type may still leave its fields vulnerable, while a rule that keeps too much can neutralise the purpose of the optimiser. The technical challenge is precision, not simply preservation. Teams need enough scope to keep runtime behaviour intact, but not so much that they flatten the protection model.

Practical implication: Use the narrowest keep rule that restores behaviour, then tighten it further so the protection layer still removes unused or sensitive implementation detail.

How guided profiling changes keep rule collection

The guided workflow shifts discovery from post-crash debugging to runtime profiling. During instrumentation, the app is exercised while the tooling observes reflection usage and records the keep rules needed to preserve behaviour. Those collected rules are then folded into the protection phase, which reduces the need to infer missing symbols from stack traces. This is a control-plane change as much as a tooling change: the rule set is derived from observed execution rather than repeated failure analysis. For teams supporting large or heavily modular apps, that reduces the gap between intended behaviour and protected builds.

Practical implication: Profile representative user flows before release so keep rules are based on observed runtime paths rather than guesswork after a crash.


NHI Mgmt Group analysis

Keep-rule precision is an application governance problem, not just a build task. The article shows that reflection-heavy Android apps can fail when optimisation changes the runtime contract between code and libraries. That means release engineering has to govern what must remain stable, not only what can be stripped away. Practitioners should treat keep rules as part of security and reliability policy, not a one-off fix.

Overly broad preservation is its own control failure. The article makes clear that the easy response to a crash is to keep more code, but that weakens the very protections obfuscation is meant to provide. This is a familiar pattern in mobile security: teams trade precision for stability and then inherit a larger attack surface. Practitioners should narrow rules to the minimum required behaviour.

Reflection creates a hidden dependency on symbol stability. When libraries perform dynamic lookup under the hood, the app’s operational state depends on names that optimisation tools are free to change. That makes runtime behaviour fragile unless the build process captures those dependencies explicitly. Practitioners should surface reflective dependencies early and govern them as first-class release constraints.

Guided collection is a better failure model than crash-led iteration. The most useful shift in this article is not automation for its own sake, but moving discovery into an instrumented runtime phase. That is how teams avoid repeatedly shipping, crashing, and widening rules by guesswork. Practitioners should prefer observed execution over retrospective inference when configuring protection.

What this signals

Reflection-aware configuration is becoming a release governance issue. Android teams that rely on obfuscation now have to preserve behaviour while still reducing symbol exposure, which means build pipelines need explicit controls for reflective dependencies. The practical shift is toward instrumented profiling and tighter rule scope, not broader exclusions.

Guided collection changes the operational baseline for mobile hardening. When keep rules are derived from observed runtime flows, teams reduce the chance that crash analysis becomes the primary mechanism for discovering missing configuration. That makes protection settings more repeatable and less dependent on individual source-code knowledge.


For practitioners

  • Inventory reflection-dependent code paths Map every library and application path that relies on runtime symbol lookup, including JSON serializers, dependency injection, and plugin-style loading. Treat those paths as configuration-sensitive before enabling aggressive shrinking or obfuscation.
  • Start with narrow keep rules Preserve only the classes, fields, or methods required to keep the observed behaviour working, then tighten any broad rule that protects more of the app than necessary. Avoid defaulting to class-wide preservation unless the failure mode proves it is required.
  • Profile representative user flows before release Exercise the app in an instrumented build across the screens and code paths where reflection occurs so runtime keep-rule needs are collected from actual behaviour rather than inferred after a crash.
  • Review library consumer rules for blast radius Check third-party keep rules to confirm they do not preserve unrelated application classes or methods. A library-level rule that is too broad can silently reduce obfuscation across the whole app.

Key takeaways

  • Android optimisation can break apps when reflection depends on class or field names that shrinking and obfuscation change.
  • Broad keep rules may prevent crashes, but they also reduce the security and size benefits the optimiser is meant to deliver.
  • Instrumented profiling gives teams a more controlled way to collect keep rules from real app behaviour instead of repeated crash analysis.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

MITRE ATT&CK addresses the attack and risk surface, while OWASP ASVS, CIS Controls v8 and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP ASVSV15 — Secure Coding and ArchitectureReflection failures here stem from architecture choices that depend on stable runtime names.
Recommendation — Review dynamic lookup paths under V15 and preserve only the names the app truly needs at runtime.
CIS Controls v8CIS-16 — Application Software SecurityThe article is about securing application behaviour during build-time protection and release.
Recommendation — Apply CIS-16 to test protected builds for runtime failures before release.
NIST CSF 2.0PR.PS-05 — Software, Firmware, and Information IntegrityProtected Android builds need integrity over configuration so behaviour remains stable after processing.
Recommendation — Use PR.PS-05 to verify protected builds still behave correctly after optimisation and obfuscation.
MITRE ATT&CKTA0005 — StealthObfuscation and name changing relate to the broader tactic of concealing code and runtime behaviour.
Recommendation — Map obfuscation-related control decisions to TA0005 when evaluating how much implementation detail stays exposed.

Key terms

  • Keep Rule: A keep rule tells an optimiser or obfuscator which classes, methods, or fields must not be renamed, removed, or merged. It preserves runtime symbols that code depends on, especially when reflection, serialization, or framework lookup uses names rather than explicit references.
  • Reflection: Reflection is a runtime mechanism that lets code inspect or access classes, methods, or fields by name. It is useful for flexible frameworks, but it becomes fragile when obfuscation changes the names or structure that the runtime lookup expects.
  • Code Shrinking: Code shrinking removes unused code from an application to reduce size and sometimes improve performance. In mobile builds, it can also create functional risk if the analyser does not correctly identify code that is only used indirectly at runtime.
  • Prompt Obfuscation: Prompt obfuscation is the practice of hiding malicious instructions so they bypass literal filters but still remain understandable to an LLM. The technique relies on the gap between surface text matching and semantic reconstruction, which allows a model to recover harmful intent from encoded or disguised input.

Deepen your knowledge

NHI Mgmt Group covers identity security, NHI governance, and agentic AI through independent research, practitioner guides, and the NHI Foundation Level course. Explore the NHI Foundation Level course, the industry's only accredited NHI security programme, if your programme needs stronger identity governance discipline.
NHIMG Editorial Note
Published by the NHIMG editorial team on August 18, 2026.
Updated on October 12, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org