Skip to content

ADFA-3604: Fix 2 more R8 shrink bugs (Gson templates, JDI debugger) - #1610

Open
davidschachterADFA wants to merge 2 commits into
stagefrom
fix/ADFA-3604-gson-jdi-r8-shrink
Open

ADFA-3604: Fix 2 more R8 shrink bugs (Gson templates, JDI debugger)#1610
davidschachterADFA wants to merge 2 commits into
stagefrom
fix/ADFA-3604-gson-jdi-r8-shrink

Conversation

@davidschachterADFA

Copy link
Copy Markdown
Collaborator

Follow-up to #1609 — two more R8 shrink bugs found after that PR merged

#1609 (fixes 1–5 of the R8 shrink/optimize bugs found while verifying ADFA-3604 on-device) was merged to stage while this session was still actively testing. This PR carries the two additional fixes found afterward, cherry-picked cleanly onto current stage.

What this PR fixes

  1. Gson model classes reported as "abstract" — classes only ever constructed via gson.fromJson(..., X::class.java) reflection have no traceable new call site, so R8 strips their constructor and Gson's runtime then reports them as abstract (Failed to load template archive ... Abstract classes can't be instantiated! on TemplatesIndex, surfaced as a user-facing error dialog). Found and fixed for every gson.fromJson call site in the repo, including two more instances with no prior keep rule at all (OpenedFilesCache/OpenedFile, breakpoint persistence models).
  2. JDI debugger connector strippedcom.sun.tools.jdi's SocketAttachingConnector/SocketListeningConnector are loaded via ServiceLoader, which R8 can't trace; stripping their constructors broke the debugger with Error: no Connectors loaded, which the app then surfaced to the user as a misleading "Network access error" (the debug-connect failure handler always appends a network-access suggestion regardless of actual cause). This exact fix was already anticipated and left commented out in this file since before shrinking was ever genuinely enabled — just needed uncommenting.

Verification

Built and installed on a physical ARM device (Samsung Galaxy Note20 Ultra):

  • Templates load cleanly (all 9 built-in templates listed with no error)
  • Debugger's JDWP listener starts successfully (Starting JDWP listener, startListening), no dialog
  • Zero FATAL EXCEPTION in logcat

Recommendation

A broader smoke test (Java LSP, XML LSP, actually building/running a project) is still recommended before considering ADFA-3604 fully closed — everything verified so far has been found via targeted manual exploration, not exhaustive coverage of the app's core workflows.

🤖 Generated with Claude Code

davidschachterADFA and others added 2 commits July 31, 2026 17:34
Found via a "Failed to load template archive ... Abstract classes can't
be instantiated!" error on-device. Same root cause as the other shrink
bugs fixed in this branch: Gson deserializes these classes only via
reflection (gson.fromJson(..., X::class.java)), never a direct `new`
R8 can trace, so it strips the constructor and Gson's runtime then
reports the class as abstract.

Fixes templates-impl's TemplatesIndex/TemplateJson/etc., and two more
instances found by auditing every gson.fromJson call site in the repo:
OpenedFilesCache/OpenedFile (no prior rule at all) and the breakpoint
persistence models.

Verified on-device: templates load cleanly, zero FATAL EXCEPTION in
logcat, Kotlin project init still succeeds.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Found via a "Network access error" dialog on-device -- misleading, since
the app's debug-connect failure handler always appends a network-access
suggestion regardless of actual cause. The real error was buried in
logcat: "java.lang.Error: no Connectors loaded" from
com.sun.tools.jdi.VirtualMachineManagerImpl, caused by a
ServiceConfigurationError failing to instantiate
SocketAttachingConnector/SocketListeningConnector. Same root cause as
the other shrink bugs: JDI loads these via ServiceLoader, which R8
can't trace, so it stripped their no-arg constructors.

This exact fix was already anticipated and left commented out in this
file ("Initial rules to enable when R8 is shrinking to address
exceptions") from before shrinking was ever genuinely enabled -- just
needed uncommenting now that it is.

Verified on-device: JDWP listener starts successfully, no dialog, zero
FATAL EXCEPTION in logcat.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough
  • Added R8 keep rules for Gson model classes that are loaded through reflection.
  • Preserved template models, OpenedFilesCache, OpenedFile, and breakpoint persistence models.
  • Re-enabled keep rules for JDI connector classes loaded through ServiceLoader.
  • Prevented template loading failures and no Connectors loaded errors caused by stripped constructors or connector implementations.
  • On-device verification succeeded on a Samsung Galaxy Note20 Ultra. Broader smoke testing remains recommended for other workflows.
  • Risk: Package-wide keep rules can increase APK size and reduce shrinker effectiveness.

Walkthrough

The ProGuard configuration now keeps Gson-deserialized model packages and template ZIP models. It also enables retention for JDI connector classes and constructors loaded through ServiceLoader.

Changes

Shrinker retention rules

Layer / File(s) Summary
Gson model retention
app/proguard-rules.pro
Package-wide rules retain Android IDE, debug, and template ZIP model classes used by Gson.
JDI connector retention
app/proguard-rules.pro
Enabled rules retain com.sun.tools.jdi and com.sun.jdi classes and constructors for ServiceLoader loading.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: hal-eisen-adfa

Poem

A rabbit checks the shrinker’s trace,
Keeps Gson models in their place.
JDI connectors stay in sight,
ServiceLoader hops just right.
The build now trims with care.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the two R8 shrink bugs fixed: Gson template handling and JDI debugger connectors.
Description check ✅ Passed The description directly explains the Gson reflection fixes, JDI connector fixes, affected errors, and verification results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ADFA-3604-gson-jdi-r8-shrink

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/proguard-rules.pro`:
- Around line 117-118: Correct the positional reference in the comment
describing templates.impl.zip near the OpenedFilesCache/OpenedFile rules: change
“above” to “below” to reflect the template rule’s location, or remove the
positional wording entirely.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d45ea7d7-01a5-4824-b9f3-3f25873e5b37

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7f32b and 74e2752.

📒 Files selected for processing (1)
  • app/proguard-rules.pro

Comment thread app/proguard-rules.pro
Comment on lines +117 to +118
# templates.impl.zip above. Covers OpenedFilesCache/OpenedFile (no prior
# rule) as well as the APK metadata classes already listed individually.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the relative rule reference.

The template rule is at Line 174, below this block. Change above to below, or remove the positional reference.

Proposed fix
-# templates.impl.zip above. Covers OpenedFilesCache/OpenedFile (no prior
+# templates.impl.zip below. Covers OpenedFilesCache/OpenedFile (no prior
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# templates.impl.zip above. Covers OpenedFilesCache/OpenedFile (no prior
# rule) as well as the APK metadata classes already listed individually.
# templates.impl.zip below. Covers OpenedFilesCache/OpenedFile (no prior
# rule) as well as the APK metadata classes already listed individually.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/proguard-rules.pro` around lines 117 - 118, Correct the positional
reference in the comment describing templates.impl.zip near the
OpenedFilesCache/OpenedFile rules: change “above” to “below” to reflect the
template rule’s location, or remove the positional wording entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant