[@capacitor/splash-screen] Android: hide() removes the launch pre-draw listener off the UI thread, crashing cold start
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
阅读 android/src/main/java/com/capacitorjs/plugins/splashscreen/SplashScreen.java,重点查看 hide(int, boolean) 中的 isLaunchSplash 分支,以及 hideDialog(...) 中的 Android 12 API 分支。检查这两个调用点如何释放 pre-draw 监听器,并与建议的 releaseLaunchSplash 方案进行比较。完成标准是:两个路径都在 UI 线程上同时更新可见性、移除监听器并清空其字段,且冷启动不再崩溃。
由索引模型根据 Issue 内容生成。
描述
Plugin: @capacitor/splash-screen 8.0.2 (Android)
Describe the bug
SplashScreen.hide() runs on Capacitor's plugin thread. On the Android 12 splash-screen API path it calls
content.getViewTreeObserver().removeOnPreDrawListener(this.onPreDrawListener) directly on that thread, but a
ViewTreeObserver may only be touched from the UI thread.
With launchAutoHide: false the launch listener returns false, so it holds drawing and the UI thread runs
ViewTreeObserver.dispatchOnPreDraw() on every frame until the web layer calls hide(). The off-thread removal
then races that dispatch: removing an entry shifts the array under the dispatch loop and leaves a null slot, and
the app dies with
java.lang.NullPointerException: Attempt to invoke interface method
'boolean android.view.ViewTreeObserver$OnPreDrawListener.onPreDraw()' on a null object reference
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1116)
roughly 10 ms after the hide() call. The same block also sets isVisible = false before the removal, so a
dispatch landing between the two can set it back and leave the splash pinned up.
Both affected call sites are in android/src/main/java/com/capacitorjs/plugins/splashscreen/SplashScreen.java:
the isLaunchSplash early-return inside hide(int, boolean), and the "Hide with Android 12 API" branch of
hideDialog(...).
To Reproduce
- A Capacitor 8 Android app targeting the Android 12 splash API, with
launchAutoHide: falsein
capacitor.config, so the launch splash is held until the web layer hides it. - Call
SplashScreen.hide()from JavaScript as soon as the web app has painted (the usual pattern). - Cold-start the app repeatedly on a device or emulator (Android 12+; seen on Android 14).
It is a race, so it is intermittent — observed twice in one night across an automated relaunch suite that
cold-starts the app many times.
Expected behavior
Hiding the launch splash should never crash the app, and the pre-draw listener should be removed on the UI thread.
Suggested fix
Post the whole release — clear isVisible, remove the listener, clear the field — to the main looper as a single
runnable, from both call sites. Doing all three together on the UI thread also closes the second half of the bug,
since no dispatch can run between clearing the flag and removing the listener:
private void releaseLaunchSplash(final OnPreDrawListener listener) {
new Handler(context.getMainLooper()).post(() -> {
isVisible = false;
if (null != content) {
content.getViewTreeObserver().removeOnPreDrawListener(listener);
}
if (onPreDrawListener == listener) {
onPreDrawListener = null;
}
});
}
We are running exactly this as a pinned patch against 8.0.2 and the cold-start crash has not recurred. Happy to
open a PR if that is useful.
Additional context
- Capacitor: 8.4.2
@capacitor/splash-screen: 8.0.2 (current npmlatestat time of writing)- Platform: Android 12+ (reproduced on Android 14)
- 主要语言
- Java
- 星标
- 688
- 派生
- 691
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ionic-team/capacitor-plugins 的其他 Issue
-
triage
难度 2/5 1-3 小时 新手友好度 72/100
ionic-team/capacitor-plugins#2616 ·
维护者通常 1 天内回复
-
[@capacitor/app] iOS: 'Expression implicitly coerced from String? to Any' warning in getAppLanguage未关闭triage
难度 1/5 1 小时以内 新手友好度 88/100
ionic-team/capacitor-plugins#2604 ·
维护者通常 1 天内回复
-
bug(action-sheet, camera): on iPhone with Liquid Glass, action sheets show as a popover without the Cancel action可能已有人在做 @arblitroshani 于 4 天前认领。 未关闭platform: ios
难度 3/5 1-2 天 新手友好度 20/100
ionic-team/capacitor-plugins#2630 ·
维护者通常 1 天内回复
-
bug(status-bar): iOS WebView moves under the status bar after a full-screen modal is dismissed可能已有人在做 @kidzki 于 5 天前认领。 未关闭platform: ios
难度 3/5 1-2 天 新手友好度 25/100
ionic-team/capacitor-plugins#2625 ·
维护者通常 1 天内回复
-
platform: ios
难度 4/5 3-5 天 新手友好度 35/100
ionic-team/capacitor-plugins#2624 ·
维护者通常 1 天内回复
查看 ionic-team/capacitor-plugins 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 86/100
MetricsHub/metricshub-community#1532 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
asciidoctor/asciidoctor-intellij-plugin#2157 ·
维护者通常 4 天内回复
-
account bug exercise lecture
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复