Skip to content

fix(android): keep the by-name androidx members when the app minifies - #2

Merged
DD-Intercom merged 1 commit into
mainfrom
dheepakraj.selvakumar/keep-viewtree-owner-reflection
Dec 4, 2026
Merged

DD-Intercom merged 1 commit into
mainfrom
dheepakraj.selvakumar/keep-viewtree-owner-reflection

Conversation

@DD-Intercom

Copy link
Copy Markdown
Contributor

Why?

When a Unity app turns on minification, the Android bridge can no longer give the Unity activity a lifecycle. It looks up the androidx lifecycle and saved-state helpers by name, R8 renames them, so setup fails with "Could not set view tree owners" and in-app messages cannot render. Apps that don't minify are unaffected, which is why this has gone unnoticed.

How?

The Android build post-processor now adds exact keep rules for those androidx members to the file the generated library already passes to R8. The same rules keep the bridge's own by-name entry points, so the wrapper no longer relies on the native SDK to keep them.

Notes for reviewers

Checked with a minified build shaped like Unity's Gradle export: the bridge, a player stub and Android SDK 18.9.0 in a library module, launched from a plain Activity, release build with proguard-android-optimize and -repackageclasses '', on an API 36 emulator.

  • Without the rules: Could not set view tree owners … Ld1.get [class android.view.View], and all three owners were null on the decor view.
  • With only these rules: all three "set on decor view" logs, and all three owners non-null. Nothing else kept the bridge class.

Not run inside the Unity editor, and no in-app message was rendered.

Generated with Claude Code

IntercomPlugin.initialize() installs the ViewTree lifecycle, saved-state
and ViewModelStore owners on the Unity activity's decor view through
reflection and Proxy dispatch on interface method names. When the app
minifies with R8, the Class.forName strings are rewritten but the methods
are renamed, so the setup throws and logs "Could not set view tree
owners", and in-app messages built with Compose cannot render.

The Android post-processor now appends exact keep rules for those members
to unityLibrary's proguard-unity.txt, which the generated build already
lists in consumerProguardFiles. The block also keeps IntercomPlugin's
public static entry points and HeaderInterceptor.setUnityVersion, both
reached only by name, so the wrapper no longer depends on the native SDK
shipping keep rules for them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DD-Intercom
DD-Intercom merged commit 9065ebd into main Dec 4, 2026
3 checks passed
@DD-Intercom
DD-Intercom deleted the dheepakraj.selvakumar/keep-viewtree-owner-reflection branch December 4, 2026 15:55
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.

2 participants