Skip to content

fix(appfunctions): keep AppSearch document-factory constructors under R8 full mode#5829

Merged
jamesarich merged 1 commit into
mainfrom
claude/objective-elgamal-411967
Jun 17, 2026
Merged

fix(appfunctions): keep AppSearch document-factory constructors under R8 full mode#5829
jamesarich merged 1 commit into
mainfrom
claude/objective-elgamal-411967

Conversation

@jamesarich

Copy link
Copy Markdown
Collaborator

Why

Internal/release (minified) builds crash on the first AppFunctions state sync with ExceptionInInitializerError at AppFunctionManager.getInstance(). The root cause is NoSuchMethodException for androidx.appfunctions.metadata.$$__AppSearch__AppFunctionRuntimeMetadata.<init>[].

AppSearch instantiates its generated $$__AppSearch__* document factories reflectively via DocumentClassFactoryRegistry. AppSearch's own consumer rule keeps the factory class with a bare -keep class ** implements DocumentClassFactory {}. Under R8 full mode (the AGP 8+ default, and we're on AGP 9.2.1) a bare keep no longer implicitly retains the default constructor, so the no-arg ctor is tree-shaken and reflective construction fails. Debug builds don't minify, which is why this only surfaces in release. Upstream tracking: Google issue b/440484133 — appfunctions' own rules even carry a "remove once AppSearch updates their rules" TODO.

Changes

🐛 Bug Fixes

  • Add an explicit -keepclassmembers rule in androidApp/proguard-rules.pro restoring the no-arg constructor on androidx.appsearch.app.DocumentClassFactory implementations. -keepclassmembers (rather than -keep) only restores the ctor on factories the upstream rule already retains, keeping the rule minimal. It is package-agnostic, so it covers both the library's internal metadata docs and our own @AppFunctionSerializable models in androidApp/src/google/.../appfunctions/AppFunctionModels.kt.

Testing Performed

  • :androidApp:minifyGoogleReleaseWithR8 — passes with no R8 warnings.
  • Confirmed the fix at the R8 level: build/outputs/mapping/googleRelease/seeds.txt now lists the previously-stripped constructor as kept:
    androidx.appfunctions.metadata.$$__AppSearch__AppFunctionRuntimeMetadata: $$__AppSearch__AppFunctionRuntimeMetadata()
    
    13 generated-factory constructors are retained in total; none of them appear in R8's usage.txt removal list.

Affects release-only R8 behavior in an Android-only feature, so Spotless/detekt and the unit-test baseline are unaffected.

🤖 Generated with Claude Code

… R8 full mode

Release (minified) builds crashed on first AppFunctions sync with
ExceptionInInitializerError at AppFunctionManager.getInstance(), root
cause NoSuchMethodException for
androidx.appfunctions.metadata.$$__AppSearch__AppFunctionRuntimeMetadata.<init>().

AppSearch instantiates its generated $$__AppSearch__* document factories
reflectively via DocumentClassFactoryRegistry. AppSearch's own consumer
rule keeps the factory class with a bare `-keep class ** implements
DocumentClassFactory {}`. Under R8 full mode (AGP 8+ default; we are on
AGP 9) a bare keep no longer implicitly retains the default constructor,
so the no-arg ctor is tree-shaken and reflective construction fails.
Debug builds don't minify, so it only surfaced in the internal release.

Add an explicit -keepclassmembers rule restoring the no-arg constructor
on DocumentClassFactory implementations. Covers both the library's
internal metadata docs and our own @AppFunctionSerializable models.
Upstream tracking: b/440484133.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added the bugfix PR tag label Jun 17, 2026
@jamesarich jamesarich enabled auto-merge June 17, 2026 13:57
@jamesarich jamesarich added this pull request to the merge queue Jun 17, 2026
Merged via the queue into main with commit 5b19a5f Jun 17, 2026
18 checks passed
@jamesarich jamesarich deleted the claude/objective-elgamal-411967 branch June 17, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant