Skip to content

fix(android): keep span constructors that are looked up by reflection - #840

Open
Junveloper wants to merge 1 commit into
software-mansion:mainfrom
Junveloper:fix/android-keep-span-constructors
Open

Junveloper wants to merge 1 commit into
software-mansion:mainfrom
Junveloper:fix/android-keep-span-constructors

Conversation

@Junveloper

Copy link
Copy Markdown

Summary

Fixes #839.

InlineStyles and ParagraphStyles create spans with type.getDeclaredConstructor(HtmlStyle::class.java). R8 can't see that reflective use, so in a minified release build it can inline a span's (HtmlStyle) constructor into its only direct caller (rebuildWithStyle) and remove it. Typing with that style active then crashes with NoSuchMethodException: <span>.<init> [class <HtmlStyle>]. In the example app this hits Bold, Italic, Underline and Strikethrough.

This adds android/consumer-rules.pro, which keeps the (HtmlStyle) constructor of every class in com.swmansion.enriched.textinput.spans, and exports it with consumerProguardFiles. Apps that enable R8 pick it up automatically. The rule only keeps constructors, so span class names are still obfuscated, and a class R8 removes as unused is still removed.

android/ is already in the package's files, so the new file is published.

Test Plan

R8 isn't enabled in the example app, so turn it on for the test without committing it:

  1. In apps/example/android/app/build.gradle, set enableProguardInReleaseBuilds = true.
  2. On main, build and install a release build: cd apps/example/android && ./gradlew :app:assembleRelease -PreactNativeArchitectures=arm64-v8a, then adb install -r app/build/outputs/apk/release/app-release.apk.
  3. Type a few characters, tap B, type one more. The app crashes with NoSuchMethodException in InlineStyles.setSpan. The same happens for I, U and S.
  4. Repeat steps 2 and 3 on this branch. Typing and backspace work with each of the four styles active, and nothing crashes.

On this branch, R8's merged configuration (app/build/outputs/mapping/release/configuration.txt) includes the rule from the library's exported consumer ProGuard file. The mapping keeps <init>(HtmlStyle) on all 14 span classes that have one, against 10 on main.

Checked on an Android 16 emulator (API 36, arm64). The same rule, added at app level, also fixes the crash in our production Expo app on 1.1.1.

Screenshots / Videos

On main with R8 on, the app crashes at the first styled character. The trace is in #839. On this branch, the input shows the text typed with Bold, Italic, Underline and Strikethrough each active in turn, each styled correctly, and the app keeps running.

Compatibility

OS Implemented
iOS ❌
Android ✅
Web ❌

iOS and web don't use R8 or this reflection.

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

The Maestro suite installs the example app with yarn example android, a debug build with R8 off, so it can't cover this. I didn't run it.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 10:58

Copilot AI 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.

🟢 Approval recommended

The narrow rule matches the reflective constructor signature and is correctly exported, with no blocking issues identified.

No open issues 🎉

What changed in this PR

Fixes #839 by preserving Android span constructors used through reflection, preventing NoSuchMethodException crashes in R8-minified builds.

Changes:

  • Adds a targeted consumer rule that preserves (HtmlStyle) constructors without keeping otherwise unused span classes.
  • Exports the rule so consuming Android apps receive it automatically.
File Description
android/​consumer-rules.pro Preserves span constructors used by reflective style creation.
android/​build.gradle Registers the consumer rules for consuming apps.

Review effort: Balanced

@exploIF exploIF self-assigned this Oct 23, 2026

This branch has not been deployed

No deployments
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.

Android: typing with Bold, Italic, Underline or Strikethrough active crashes R8 release builds (NoSuchMethodException on span constructor)

3 participants