Android: typing with Bold, Italic, Underline or Strikethrough active crashes R8 release builds (NoSuchMethodException on span constructor)
Maintainer thường phản hồi trong vòng 4 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start with InlineStyles.kt and ParagraphStyles to inspect the reflective span construction described in the report, then check the Android release configuration in apps/example/android/app/build.gradle. The report identifies a consumer ProGuard rule as the proposed fix, and linked pull request #840 is already open. Done means the relevant span constructors survive R8 minification and typing with inline styles no longer crashes in a release build.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Before submitting a new issue
- I tested using the latest version of the library, as the bug might be already fixed.
- I tested using a supported version of react native.
- I checked for possible duplicate issues, with possible answers.
Bug summary
In an Android release build with R8 enabled, typing while Bold, Italic, Underline or Strikethrough is active crashes the app. Retraced:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.NoSuchMethodException: xp.<init> [class pz]
at java.lang.Class.getConstructor0(Class.java:3385)
at java.lang.Class.getDeclaredConstructor(Class.java:3067)
at com.swmansion.enriched.textinput.styles.InlineStyles.setSpan(InlineStyles.kt:43)
at com.swmansion.enriched.textinput.styles.InlineStyles.afterTextChanged(InlineStyles.kt:127)
at com.swmansion.enriched.textinput.watchers.EnrichedTextWatcher.applyStyles(EnrichedTextWatcher.kt:77)
at com.swmansion.enriched.textinput.watchers.EnrichedTextWatcher.afterTextChanged(EnrichedTextWatcher.kt:72)
at android.widget.TextView.sendAfterTextChanged(TextView.java:12852)
at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:16566)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:579)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:509)
at android.view.inputmethod.BaseInputConnection.replaceTextInternal(BaseInputConnection.java:1026)
at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:241)
xp is EnrichedInputBoldSpan and pz is HtmlStyle.
InlineStyles and ParagraphStyles create spans with type.getDeclaredConstructor(HtmlStyle::class.java).newInstance(view.htmlStyle). R8 can't see that reflective use. The only direct call to EnrichedInputBoldSpan(HtmlStyle) is in its own rebuildWithStyle, so R8 inlines the constructor there and removes it. The mapping shows <init> folded into rebuildWithStyle (-> c) instead of surviving as <init>:
com.swmansion.enriched.textinput.spans.EnrichedInputBoldSpan -> xp:
...
7:10:void com.swmansion.enriched.common.spans.EnrichedBoldSpan.<init>(com.swmansion.enriched.common.EnrichedStyle):11:11 -> c
7:10:void <init>(com.swmansion.enriched.textinput.styles.HtmlStyle):9 -> c
7:10:com.swmansion.enriched.textinput.spans.EnrichedInputBoldSpan rebuildWithStyle(com.swmansion.enriched.textinput.styles.HtmlStyle):13 -> c
In the example app, 4 of the 14 span classes with an (HtmlStyle) constructor lose it: Bold, Italic, Underline and Strikethrough. Which ones go depends on R8's inlining, so other apps can lose different ones.
The library ships no consumer ProGuard rules, and the example app builds with enableProguardInReleaseBuilds = false, so the library's own builds never run into this. We hit it in production in an Expo app (expo-build-properties with enableMinifyInReleaseBuilds: true): the app crashed while users typed in a chat composer.
Until this is fixed, apps can add the rule themselves, in proguard-rules.pro or expo-build-properties → android.extraProguardRules:
-keepclassmembers class com.swmansion.enriched.textinput.spans.** {
<init>(com.swmansion.enriched.textinput.styles.HtmlStyle);
}
I'll open a PR that ships this as a consumer rule.
Library version
1.1.1. Also reproduced on main at f35eb41.
Environment info
System:
OS: macOS 27.0.1
CPU: (11) arm64 Apple M3 Pro
Binaries:
Node:
version: 24.3.0
Yarn:
version: 4.13.0
SDKs:
Android SDK:
API Levels:
- "35"
- "36"
- "37"
IDEs:
Android Studio: 2024.2 AI-242.23726.103.2422.12816248
Languages:
Java:
version: 17.0.14
npmPackages:
"@react-native-community/cli":
installed: 20.2.0
react:
installed: 19.2.3
react-native:
installed: 0.87.0
Android:
hermesEnabled: true
newArchEnabled: true
Gradle 9.4.1. Device: Android emulator, API 36 (Pixel, arm64).
Steps to reproduce
- In
apps/example/android/app/build.gradle, setenableProguardInReleaseBuilds = true. - Build and install a release build:
cd apps/example/android && ./gradlew :app:assembleRelease, thenadb install -r app/build/outputs/apk/release/app-release.apk. - Tap the input and type a few characters.
- Tap B in the toolbar, then type one more character.
- The app crashes with the
NoSuchMethodExceptionabove. Italic, Underline and Strikethrough crash the same way.
Reproducible example repository
https://github.com/Junveloper/react-native-enriched-html/tree/repro/r8-span-constructors (this repository with step 1 applied)
- Ngôn ngữ chính
- C
- Star
- 1.4k
- Fork
- 76
- Merge trung bình
- 3 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 23
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của software-mansion/react-native-enriched-html
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
software-mansion/react-native-enriched-html#855 · 8 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 4 ngày
-
[Feature request] Vertical spacing (margins) for headings and lists in htmlStyleCó thể đã có người làm @henrikra đã nhận 15 ngày trước. Đang mởenhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
software-mansion/react-native-enriched-html#832 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 4 ngày
-
[iOS] Tags not parsed on iOS below a certain string lengthCó thể đã có người làm @hejsztynx đã nhận 24 ngày trước. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
software-mansion/react-native-enriched-html#811 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 50/100
software-mansion/react-native-enriched-html#810 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Support for `<raw-text-block>`Đang mởenhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
software-mansion/react-native-enriched-html#803 ·
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của software-mansion/react-native-enriched-html
Issue tương tự
-
area: metrics area: tracing contribfest enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
open-telemetry/opentelemetry-ebpf-instrumentation#4188 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[hardware] `fn_pico_blob.h` names the wrong consumer and justifies PC fallbacks nothing usesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
FujiNetWIFI/fujinet-firmware#2328 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
onehumanbeing/esp32-iphone-agent#118 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:http-gateway decision priority:low status:needs-info type:feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
crazy-goat/php-fpm-ng#1093 ·
Maintainer thường phản hồi trong vòng 1 ngày