PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchIf deserialization works in a debug build but fails in a minified Android release, the likely cause is that the release build changed or removed something the serializer discovers at runtime. With R8 and Gson, common failure points include missing classes or members, renamed fields used as JSON keys, stripped generic type metadata, and constructors that reflection expects. The fix is to identify which runtime contract broke, preserve only what it needs, and test the transformed build.
Why reflection can fail after shrinking or obfuscation
R8 can make several distinct changes. Shrinking removes code it considers unused; obfuscation renames classes and members. Optimizations can also affect assumptions made by code that constructs or inspects objects reflectively.
Ordinary code contains references a shrinker can analyze. Reflection may instead look up a class by a string, inspect a field at runtime, or invoke a constructor without a visible call site. Android explains that R8 may not recognize a class loaded by name and can remove it as unused. The relevant keep-rule guidance is in Android’s keep rules overview.
That means a release failure is not simply “obfuscation broke reflection.” The class might be gone, a member might be gone or renamed, a required constructor or generic signature might be missing, or a data-format name might no longer match. Find the first broken assumption before adding rules.
How R8 and Gson break the JSON contract
Field names change while JSON names stay fixed
If Gson derives a JSON key from a Java field name, renaming the field can make the key differ from the one in existing input or expected output. Use Gson’s @SerializedName annotation to define a stable JSON name independently of the source identifier, and ensure the annotated field remains available to Gson. Android’s Gson optimization guidance describes the interaction with R8.
Members or classes disappear
Reflection does not necessarily create a static reference that tells R8 a model class, field, or constructor is needed. A class loaded by name, or a constructor invoked only reflectively, may therefore be removed unless the configuration preserves it.
Rank #2
Generic metadata or constructors are missing
Gson can depend on generic type signatures and default constructors in particular use cases. Android’s R8 guidance notes that full mode can strip metadata or constructors unless the application configuration preserves what its usage requires. The right rule depends on the model, Gson version, reflection pattern, and optimization mode; a rule that fixes one app is not automatically appropriate for another.
Inherited fields collide after renaming
R8’s compatibility FAQ documents a Gson failure in which private fields in a class hierarchy can be renamed to the same name, producing java.lang.IllegalArgumentException: class <class name> declares multiple JSON fields named <name>. The FAQ’s remedies for this case include giving serialized fields distinct @SerializedName values and applying the corresponding member keep rule. See the R8 compatibility FAQ; do not generalize this particular collision into a rule for every serialization error.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Choose a narrow fix for the runtime contract
Start with the actual runtime lookup: which class is loaded, which constructor is called, which fields are inspected, and whether generic type information is required. Android’s keep-rule syntax can preserve selected classes or members while permitting shrinking or obfuscation where those transformations do not violate the contract. Conditional rules can scope preservation to matching classes. Avoid rules that keep every class or member indiscriminately: they can block useful optimization. The Android keep-rule overview explains the distinctions and modifiers.
For Gson, check the library version and its consumer rules before copying a rule. Android notes that Gson 2.11.0 and later bundle rules for TypeToken and fields annotated with @SerializedName; this does not mean every application model or open-ended reflective use is automatically protected. Gson’s troubleshooting guide likewise recommends testing minified builds and describes strategies such as constraining reflected model classes and using explicit adapters.
Rank #4
Stable names and preservation solve different problems: @SerializedName specifies the JSON key, while keep rules address whether the runtime can still access the relevant program elements. An annotation alone does not establish that every required class, constructor, or field survives optimization.
Verify the release build, not just debug
- Reproduce the failure in the release variant with minification enabled. Record the R8/Android Gradle Plugin and Gson versions and the exact exception or unexpected JSON.
- Locate the first missing or changed element. Check the reflective lookup, model hierarchy, and generated mapping or shrinker reports where available. Determine whether the issue is removal, renaming, metadata, construction, or a name collision.
- Make the smallest relevant change. Add a targeted keep rule, use stable
@SerializedNamevalues, or replace reflection for the affected type with an explicit adapter or another supported approach. - Test the transformed build again. Exercise serialization and deserialization for the nested, generic, inherited, and other model shapes the app actually uses.
- Check the external JSON contract and optimization effect. Confirm that keys and values remain compatible with the expected format, and review whether the rule protects unrelated code unnecessarily.
Gson’s documentation explicitly calls for testing after minification. This workflow applies that advice to the failure modes documented by Android and R8; it is not a guarantee that one rule works across all project configurations.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
When to keep Gson reflection—and when to avoid it
Gson’s project documentation warns that its open-ended runtime reflection can conflict with Android release shrinking and obfuscation. It says minified use is possible, but needs careful testing. Options include limiting reflected model classes and defining their serialized names, or using explicit TypeAdapter/TypeAdapterFactory implementations and Gson’s JSON tree or stream APIs. These approaches change how the application handles data; they are not automatic drop-in fixes. Read the project’s Gson guidance before choosing.
Also account for language features. Gson’s guidance says Kotlin-specific features such as non-null types and default constructor arguments are not supported, and advises users of non-Java JVM languages to consider libraries with explicit support. A keep rule cannot make unsupported language semantics supported.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




