[@capacitor/splash-screen] Android: hide() removes the launch pre-draw listener off the UI thread, crashing cold start
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 80/100
調査の方向性
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時間
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 が 3 日前に担当しました。 オープン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 が 3 日前に担当しました。 オープン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
-
Document and enforce pull request review guidelines対応中かも @dashorst が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
`Time.at(t, in: nil)` returns UTC instead of the local time (or the time zone of `t`), unlike CRubyオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
hermes-queue
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
chrisalunlloyd2-sudo/mindpalace#349 ·
メンテナーはふだん 1 日以内に返信
-
Retry-After parser accepts invalid delay-seconds values対応中かも @Dhruvraj-Rana が今日担当しました。 オープンBug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
open-telemetry/opentelemetry-java#9018 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dropwizard/dropwizard#11410 ·
メンテナーはふだん 1 日以内に返信