fix(appfunctions): keep AppSearch document-factory constructors under R8 full mode#5829
Merged
Merged
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Internal/release (minified) builds crash on the first AppFunctions state sync with
ExceptionInInitializerErroratAppFunctionManager.getInstance(). The root cause isNoSuchMethodExceptionforandroidx.appfunctions.metadata.$$__AppSearch__AppFunctionRuntimeMetadata.<init>[].AppSearch instantiates its generated
$$__AppSearch__*document factories reflectively viaDocumentClassFactoryRegistry. 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
-keepclassmembersrule inandroidApp/proguard-rules.prorestoring the no-arg constructor onandroidx.appsearch.app.DocumentClassFactoryimplementations.-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@AppFunctionSerializablemodels inandroidApp/src/google/.../appfunctions/AppFunctionModels.kt.Testing Performed
:androidApp:minifyGoogleReleaseWithR8— passes with no R8 warnings.build/outputs/mapping/googleRelease/seeds.txtnow lists the previously-stripped constructor as kept:usage.txtremoval 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