[@capacitor/splash-screen] Android 8–11: failed Android 12 API attempt leaves a pre-draw hold, so nothing is drawn for launchShowDuration
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
找到 Android 启动画面插件的代码,其中 showOnLaunch() 会调用 showWithAndroid12API(),并回退到旧版 show() 路径。Issue 提供了一个补丁,根据 SDK 版本对 Android 12 API 调用进行保护。将该改动与现有行为进行比较,并验证 Android 8–11 使用旧版启动画面,而 Android 12+ 保持当前路径。
由索引模型根据 Issue 内容生成。
描述
🤖 Automated review by Claude — posted via @ibrahimkhatib365's account; not written by them personally.
Bug Report
Plugin(s)
@capacitor/splash-screen 8.0.2. The same code is in every version from 4.x through 8.0.3 nightly, 9.0.0-alpha.2 and the current 9.0 dev builds.
Capacitor Version
Latest Dependencies:
@capacitor/cli: 8.6.0
@capacitor/core: 8.6.0
@capacitor/android: 8.6.0
@capacitor/ios: 8.6.0
Installed Dependencies:
@capacitor/cli: 8.5.2
@capacitor/core: 8.5.2
@capacitor/android: 8.5.2
@capacitor/ios: 8.5.2
[success] Android looking great! 👌
Platform(s)
Android 8–11 (API 26–30). Android 12+ is not affected.
Current Behavior
On Android 8–11, showOnLaunch() calls showWithAndroid12API() first. On those versions the attempt does the following:
installSplashScreen()succeeds. The compat library supports API 23+.setKeepOnScreenCondition(() -> isVisible || isHiding)succeeds. Below API 31, the compatSplashScreen.Impladds anOnPreDrawListenertoandroid.R.id.contentright away.- With the default
launchFadeOutDuration(200),setOnExitAnimationListener()then throws, because building the compatSplashScreenViewProviderneedsTheme.SplashScreenattributes that a normal launch theme doesn't have.
The catch logs Android 12 Splash API failed... using previous method. and falls back to show(..., true). However, the compat pre-draw listener from step 2 is still registered, and the legacy path then sets isVisible = true. As a result, the activity's content is held back from drawing for the entire launchShowDuration. The legacy splash window shares the activity's window token, so it doesn't appear while the activity hasn't drawn either.
The visible result depends on timing:
- On a cold launch, the first draw usually happens before
isVisibleflips, so the splash shows normally. - When the activity is recreated in an existing process (for example, after closing it with Back and reopening it from the launcher), the hold wins. Nothing of the app is drawn for
launchShowDuration, and then the app appears at once.
On an Android 9 emulator with launchShowDuration: 3000, the reopen after Back logs Displayed .MainActivity: +3s426ms, and the next line in the log is SplashScreen was automatically hidden after the launch timeout. With a translucent launch theme, the launcher stays on screen for the whole 3.4 s. With an opaque launch theme, the window background shows instead of the plugin's splash.
The 9.x change to the default launchFadeOutDuration (0, #2526) makes this worse below Android 12. Step 3 no longer throws, so the plugin never reaches the legacy path. It only holds the first frame for launchShowDuration behind the theme's window. With launchFadeOutDuration: 0 on 8.0.2, Android 9 showed no splash at all on either a cold launch (+4.4 s) or a reopen (+3.2 s), only the launcher until the app appeared.
Expected Behavior
On Android 8–11, the legacy splash shows right away and the activity isn't held. That is what happens on a cold launch today.
Code Reproduction
No sample repository yet. The steps on a new app:
npm init @capacitor/app, add@capacitor/splash-screen, and setSplashScreen.launchShowDurationto3000incapacitor.config. Keep the other defaults.- Optional, to make the symptom obvious: add
<item name="android:windowIsTranslucent">true</item>toAppTheme.NoActionBarLaunch. - Run on an API 26–30 emulator, for example Android 9.
- Launch the app and wait for it to finish loading, press Back, then tap the launcher icon again.
- The app (and the splash) are not drawn for about 3 s.
adb logcatshowsAndroid 12 Splash API failed...and anActivityManager: Displayedtime of aboutlaunchShowDuration.
Other Technical Details
androidx.core:core-splashscreen1.2.0 (the plugin default)- Reproduced on an Android 9 (API 28) emulator
minSdkVersion26
Additional Context
A guard that only uses the Android 12 API where it applies fixes this, and we now ship it as a patch:
try {
- showWithAndroid12API(activity, settings);
- return;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ showWithAndroid12API(activity, settings);
+ return;
+ }
} catch (Exception e) {
With this guard on Android 9, the reopen after Back shows the legacy splash immediately (Displayed +182ms). The cold launch is unchanged, and Android 12+ runs the same code as before.
Another approach is to remove the pre-draw listener in the catch. However, the compat library doesn't expose it, so skipping the attempt below API 31 seems simpler. This is related to, but separate from, #2627 and #2548, which are about how hide() removes the plugin's own pre-draw listener.
- 主要语言
- Java
- 星标
- 688
- 派生
- 691
- 平均合并
- 1 天 5 小时
- 30 天内合并 PR
- 5
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ionic-team/capacitor-plugins 的其他 Issue
-
triage
难度 2/5 1-3 小时 新手友好度 80/100
ionic-team/capacitor-plugins#2627 ·
维护者通常 1 天内回复
-
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 天内回复
-
platform: android
难度 3/5 1-2 天 新手友好度 74/100
ionic-team/capacitor-plugins#2636 ·
维护者通常 1 天内回复
-
triage
难度 3/5 1-2 天 新手友好度 72/100
ionic-team/capacitor-plugins#2634 ·
维护者通常 1 天内回复
查看 ionic-team/capacitor-plugins 的全部 Issue
相似的 Issue
-
Test: Verify vault unlock max failed attempts and PIN brute-force protection可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 66/100
wultra/powerauth-tests#980 ·
-
account bug communication lecture
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
line/centraldogma#1397 ·
维护者通常 2 天内回复
-
[Bug]: Fixed/recurring deposit accounts are treated as savings in ownership and listings可能已有人在做 @Aana123 今天认领。 未关闭bug Triage
难度 2/5 1-3 小时 新手友好度 76/100
apache/fineract-consumer-facing#252 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 76/100
ShaftHQ/SHAFT_ENGINE#7946 ·
维护者通常 1 天内回复