簡體   English   中英

為什么在 Ionic 4 啟動畫面后白屏卡住?

[英]Why white screen stuck after splash screen in Ionic 4?

我為我的 Ionic Cordova 項目運行ionic cordova run android 此時,我的手機通過 USB 連接到 PC。 因此,當我運行該命令時,它會在我的真實設備 Android Redmi Note 6 PRO 上安裝該應用程序。

但真正發生的是當應用程序打開時,只出現白屏,什么也沒有。 首先它顯示閃屏,然后永遠是白屏。 為什么會發生這種行為? 我在某處讀到有人因為 Ionic 4 而遇到這個問題。

以下是我單擊應用程序在 Android 模擬器上打開后的 logcat 日志(它也在 Android 模擬器上顯示白屏)。

2019-02-11 00:01:24.131 5945-5945/? I/zygote: Not late-enabling -Xcheck:jni (already on)
2019-02-11 00:01:24.148 5945-5945/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
2019-02-11 00:01:24.312 5945-5945/io.ionic.starter I/CordovaLog: Changing log level to DEBUG(3)
2019-02-11 00:01:24.312 5945-5945/io.ionic.starter I/CordovaActivity: Apache Cordova native platform version 7.1.4 is starting
2019-02-11 00:01:24.312 5945-5945/io.ionic.starter D/CordovaActivity: CordovaActivity.onCreate()
2019-02-11 00:01:24.342 5945-5945/io.ionic.starter I/WebViewFactory: Loading com.android.chrome version 61.0.3163.98 (code 316409812)
2019-02-11 00:01:24.350 5945-5945/io.ionic.starter I/zygote: The ClassLoaderContext is a special shared library.
2019-02-11 00:01:24.392 5945-5945/io.ionic.starter I/cr_LibraryLoader: Time to load native libraries: 8 ms (timestamps 2894-2902)
2019-02-11 00:01:24.421 5945-5945/io.ionic.starter I/chromium: [INFO:library_loader_hooks.cc(136)] Chromium logging enabled: level = 0, default verbosity = 0
2019-02-11 00:01:24.422 5945-5945/io.ionic.starter I/cr_LibraryLoader: Expected native library version number "61.0.3163.98", actual native library version number "61.0.3163.98"
2019-02-11 00:01:24.436 5945-5963/io.ionic.starter W/cr_ChildProcLH: Create a new ChildConnectionAllocator with package name = com.android.chrome, sandboxed = true
2019-02-11 00:01:24.464 5945-5945/io.ionic.starter I/cr_BrowserStartup: Initializing chromium process, singleProcess=false
2019-02-11 00:01:24.513 5945-5945/io.ionic.starter W/o.ionic.starter: type=1400 audit(0.0:48): avc: denied { read } for name="vmstat" dev="proc" ino=4026532039 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:proc:s0 tclass=file permissive=0
2019-02-11 00:01:24.544 5945-5945/io.ionic.starter I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-02-11 00:01:24.553 5945-5945/io.ionic.starter D/EGL_emulation: eglCreateContext: 0xa4516160: maj 3 min 0 rcv 3
2019-02-11 00:01:24.555 5945-5945/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0xa4516160: ver 3 0 (tinfo 0x94123730)
2019-02-11 00:01:24.635 5945-5945/io.ionic.starter D/IonicWebViewEngine: Ionic Web View Engine Starting Right Up 1...
2019-02-11 00:01:24.659 5945-5945/io.ionic.starter D/SystemWebViewEngine: CordovaWebView is running on device made by: Google
2019-02-11 00:01:24.675 5945-5945/io.ionic.starter D/PluginManager: init()
2019-02-11 00:01:24.718 5945-5999/io.ionic.starter D/OpenGLRenderer: HWUI GL Pipeline
2019-02-11 00:01:24.787 5945-5945/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(file:///android_asset/www/index.html)
2019-02-11 00:01:24.793 5945-5963/io.ionic.starter I/cr_LibraryLoader: Using linker: org.chromium.base.library_loader.ModernLinker
2019-02-11 00:01:24.795 5945-5992/io.ionic.starter W/cr_media: Requires BLUETOOTH permission
2019-02-11 00:01:24.800 5945-5945/io.ionic.starter D/CordovaActivity: Started the activity.
2019-02-11 00:01:24.805 5945-5945/io.ionic.starter D/CordovaActivity: Resumed the activity.
2019-02-11 00:01:24.834 5945-5999/io.ionic.starter I/OpenGLRenderer: Initialized EGL, version 1.4
2019-02-11 00:01:24.834 5945-5999/io.ionic.starter D/OpenGLRenderer: Swap behavior 1
2019-02-11 00:01:24.836 5945-5999/io.ionic.starter W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-02-11 00:01:24.836 5945-5999/io.ionic.starter D/OpenGLRenderer: Swap behavior 0
2019-02-11 00:01:24.856 5945-5999/io.ionic.starter D/EGL_emulation: eglCreateContext: 0xa48062c0: maj 3 min 0 rcv 3
2019-02-11 00:01:24.871 5945-5999/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0xa48062c0: ver 3 0 (tinfo 0xa48038d0)
2019-02-11 00:01:25.188 5945-5999/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0xa48062c0: ver 3 0 (tinfo 0xa48038d0)
2019-02-11 00:01:25.209 5945-6010/io.ionic.starter D/EGL_emulation: eglCreateContext: 0x94170560: maj 3 min 0 rcv 3
2019-02-11 00:01:25.212 5945-6010/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0x94170560: ver 3 0 (tinfo 0x92f2a180)
2019-02-11 00:01:25.302 5945-6010/io.ionic.starter I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
2019-02-11 00:01:25.302 5945-5999/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0xa48062c0: ver 3 0 (tinfo 0xa48038d0)
2019-02-11 00:01:25.313 5945-6010/io.ionic.starter W/cr_MediaCodecUtil: HW encoder for video/avc is not available on this device.
2019-02-11 00:01:25.372 5945-5999/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0xa48062c0: ver 3 0 (tinfo 0xa48038d0)
2019-02-11 00:01:25.450 5945-5999/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0xa48062c0: ver 3 0 (tinfo 0xa48038d0)
2019-02-11 00:01:25.458 5945-6010/io.ionic.starter D/EGL_emulation: eglCreateContext: 0x941716a0: maj 3 min 0 rcv 3
2019-02-11 00:01:25.460 5945-6010/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0x941716a0: ver 3 0 (tinfo 0x92f2a180)
2019-02-11 00:01:25.537 5945-6012/io.ionic.starter W/cr_CrashFileManager: /data/user/0/io.ionic.starter/cache/WebView/Crash Reports does not exist or is not a directory
2019-02-11 00:01:25.537 5945-5950/io.ionic.starter I/zygote: Do partial code cache collection, code=22KB, data=30KB
2019-02-11 00:01:25.541 5945-5950/io.ionic.starter I/zygote: After code cache collection, code=22KB, data=30KB
2019-02-11 00:01:25.541 5945-5950/io.ionic.starter I/zygote: Increasing code cache capacity to 128KB
2019-02-11 00:01:25.546 5945-5945/io.ionic.starter D/CordovaWebViewImpl: onPageDidNavigate(file:///android_asset/www/index.html)
2019-02-11 00:01:25.611 5945-5945/io.ionic.starter D/CordovaWebViewImpl: onPageFinished(file:///android_asset/www/index.html)
2019-02-11 00:01:25.619 5945-5945/io.ionic.starter D/CordovaWebViewImpl: onPageDidNavigate(http://localhost/)
2019-02-11 00:01:25.619 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/
2019-02-11 00:01:25.640 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/runtime.js
2019-02-11 00:01:25.641 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/polyfills.js
2019-02-11 00:01:25.644 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/styles.js
2019-02-11 00:01:25.645 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/cordova.js
2019-02-11 00:01:25.646 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/vendor.js
2019-02-11 00:01:25.647 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/main.js
2019-02-11 00:01:25.663 5945-5945/io.ionic.starter D/SystemWebChromeClient: http://localhost/: Line 10 : The key "viewport-fit" is not recognized and ignored.
2019-02-11 00:01:25.663 5945-5945/io.ionic.starter I/chromium: [INFO:CONSOLE(10)] "The key "viewport-fit" is not recognized and ignored.", source: http://localhost/ (10)
2019-02-11 00:01:25.997 5945-5991/io.ionic.starter E/chromium: [ERROR:service_manager.cc(156)] Connection InterfaceProviderSpec prevented service: content_renderer from binding interface: blink::mojom::BudgetService exposed by: content_browser
2019-02-11 00:01:26.012 5945-5945/io.ionic.starter D/JsMessageQueue: Set native->JS mode to EvalBridgeMode
2019-02-11 00:01:26.083 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/cordova_plugins.js
2019-02-11 00:01:26.101 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/plugins/cordova-plugin-statusbar/www/statusbar.js
2019-02-11 00:01:26.102 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/plugins/cordova-plugin-device/www/device.js
2019-02-11 00:01:26.106 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/plugins/cordova-plugin-splashscreen/www/splashscreen.js
2019-02-11 00:01:26.107 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/plugins/cordova-plugin-ionic-webview/src/www/util.js
2019-02-11 00:01:26.108 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/plugins/cordova-plugin-ionic-keyboard/www/android/keyboard.js
2019-02-11 00:01:26.201 5945-5945/io.ionic.starter W/zygote: Attempt to remove non-JNI local reference, dumping thread
2019-02-11 00:01:26.213 5945-5999/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0xa48062c0: ver 3 0 (tinfo 0xa48038d0)
2019-02-11 00:01:26.268 5945-5999/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0xa48062c0: ver 3 0 (tinfo 0xa48038d0)
2019-02-11 00:01:27.505 5945-5999/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0xa48062c0: ver 3 0 (tinfo 0xa48038d0)
2019-02-11 00:01:27.812 5945-5945/io.ionic.starter W/zygote: Attempt to remove non-JNI local reference, dumping thread
2019-02-11 00:01:27.826 5945-5999/io.ionic.starter D/EGL_emulation: eglMakeCurrent: 0xa48062c0: ver 3 0 (tinfo 0xa48038d0)
2019-02-11 00:01:27.878 5945-5945/io.ionic.starter W/zygote: Attempt to remove non-JNI local reference, dumping thread
2019-02-11 00:01:27.887 5945-5945/io.ionic.starter D/SystemWebChromeClient: http://localhost/main.js: Line 3385 : TypeError: Cannot read property 'apply' of null
2019-02-11 00:01:27.887 5945-5945/io.ionic.starter I/chromium: [INFO:CONSOLE(3385)] "TypeError: Cannot read property 'apply' of null", source: http://localhost/main.js (3385)
2019-02-11 00:01:27.894 5945-5945/io.ionic.starter D/SystemWebChromeClient: http://localhost/vendor.js: Line 75947 : Ionic Native: deviceready event fired after 973 ms
2019-02-11 00:01:27.895 5945-5945/io.ionic.starter I/chromium: [INFO:CONSOLE(75947)] "Ionic Native: deviceready event fired after 973 ms", source: http://localhost/vendor.js (75947)
2019-02-11 00:01:27.896 5945-5988/io.ionic.starter D/SERVER: Handling local request: http://localhost/assets/icon/favicon.png
2019-02-11 00:01:27.916 5945-5945/io.ionic.starter W/zygote: Attempt to remove non-JNI local reference, dumping thread
2019-02-11 00:01:27.924 5945-5945/io.ionic.starter D/CordovaWebViewImpl: onPageFinished(http://localhost/)
2019-02-11 00:01:27.951 5945-5945/io.ionic.starter W/zygote: Attempt to remove non-JNI local reference, dumping thread
2019-02-11 00:01:28.063 5945-5945/io.ionic.starter I/chatty: uid=10080(io.ionic.starter) identical 3 lines
2019-02-11 00:01:28.110 5945-5945/io.ionic.starter W/zygote: Attempt to remove non-JNI local reference, dumping thread

Chrome 調試器顯示:

TypeError: Cannot read property 'apply' of null
    at vendor.js:88820
    at NgRedux.push../node_modules/ng2-redux/lib/components/ng-redux.js.NgRedux.configureStore (vendor.js:87925)
    at new AppModule (main.js:1511)
    at _createClass (vendor.js:56970)
    at _createProviderInstance (vendor.js:56940)
    at initNgModule (vendor.js:56873)
    at new NgModuleRef_ (vendor.js:57600)
    at createNgModuleRef (vendor.js:57589)
    at Object.debugCreateNgModuleRef [as createNgModuleRef] (vendor.js:59420)
    at NgModuleFactory_.push../node_modules/@angular/core/fesm5/core.js.NgModuleFactory_.create (vendor.js:60124)
vendor.js:75947 Ionic Native: deviceready event fired after 776 ms

我通過在 config.xml 上設置正確的參數解決了這個問題

<preference name="AutoHideSplashScreen" value="false" />
<preference name="SplashScreenDelay" value="10000" />
<preference name="FadeSplashScreenDuration" value="1000" />
<preference name="SplashScreen" value="screen" />
<preference name="ShowSplashScreen" value="true" />
<preference name="ShowSplashScreenSpinner" value="false" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="FadeSplashScreen" value="true" />

然后,在我的platform.ready()指令上,我所做的就是Splashscreen.hide() ,然后在 android 上運行該項目。

ionic cordova run android

找到解決方案。 問題出在cordova-plugin-android-permissions 中 在 android 6+(也可能是 android 5,我的設備上沒有它)上,用戶應該手動接受權限。 在應用程序權限請求看起來像警報視圖。 並且此警報會自動停止啟動畫面(即使您沒有自動隱藏啟動畫面並且尚未調用 hide 方法)並中斷淡出動畫。 即使已經添加了權限,此權限請求也會破壞啟動畫面。

所以解決方案是在超時延遲等於淡出超時后,在 splashScreen.hide() 之后請求權限。

例子:
配置文件

<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="FadeSplashScreenDuration" value="1000" />
<preference name="SplashScreenDelay" value="30000" />
<preference name="ShowSplashScreenSpinner" value="false" />
<preference name="AutoHideSplashScreen" value="false" />
<preference name="FadeSplashScreen" value="true" />
<preference name="ShowSplashScreen" value="true" />

在 app.components.ts

  initializeApp() {
    this.platform.ready().then(() => {
      setTimeout(() => {
        this.splashScreen.hide();
      }, 1000);
    }
  }

著名的!!! setTimeout 延遲應等於 config.xml 中的 FadeSplashScreenDuration 參數值

結論:上面的代碼從初始屏幕平滑過渡,這將平滑地淡入您的啟動頁面。 根本不顯示白屏。 希望這會有所幫助。

我也遇到過這個問題,但就我而言,問題出在默認路由上。

當應用程序初始化時,它嘗試在默認路由上打開,即空路由,我們進一步重定向到實際工作路由,在我的情況下,空路由被重定向到“/dashboard”。

示例代碼

const routes: Routes = [
  {
    path: '',
    redirectTo: 'dashboard',
    pathMatch: 'full'
  },
  {
    path: 'dashboard',
    canActivate: [AuthGuard],
    loadChildren: './home/home.module#HomePageModule'
  },
  { 
    path: 'login',
    loadChildren: './public/login/login.module#LoginPageModule' 
  }
]

在上面的代碼中,我的 Empty 路由重定向到 [AuthGuard] 處於活動狀態的儀表板,並停留在循環中,所以我決定將其重定向到 [AuthGuard] 未處於活動狀態的路由,在我的情況下是“/login” . 通過重定向到 [Authgaurd] 未激活的登錄來更新代碼。

 const routes: Routes = [
      {
        path: '',
        redirectTo: 'login',
        pathMatch: 'full'
      },
      {
        path: 'dashboard',
        canActivate: [AuthGuard],
        loadChildren: './home/home.module#HomePageModule'
      },
      { 
        path: 'login',
        loadChildren: './public/login/login.module#LoginPageModule' 
      }
 ]

為Andriod 構建項目后,該應用程序運行成功。

如果有人在同一問題上遇到和我一樣的問題,Justed 會發布答案。

把它放在你的 config.xml 文件中

<preference name="ScrollEnabled" value="false" />
<preference name="android-minSdkVersion" value="19" />
<preference name="BackupWebStorage" value="none" />
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="FadeSplashScreenDuration" value="300" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreen" value="screen" />
<preference name="AutoHideSplashScreen" value="false" />
<preference name="SplashScreenDelay" value="3000" />

然后運行這個命令: ionic cordova build android它將在這里生成一個apk文件:your_project_folder/platforms/android/app/build/outputs/apk/debug/app-debug.apk

這應該可以在閃屏后沒有白屏卡住的情況下工作

配置文件

 <preference name="auto-hide-splash-screen" value="false" /> 
 <preference name="AutoHideSplashScreen" value="false" />

main.js請更改

this.platform.ready().then(function () {
        _this.statusBar.styleDefault();
        _this.splashScreen.hide();
    });

this.platform.ready().then(function () {
            _this.statusBar.styleDefault();
            setTimeout(function(){
                _this.splashScreen.hide();

            }, 3000);
        });

如果更改config.xml對您不起作用,請嘗試此操作

第 1 步
打開index.html
將 base href 從<base href="/" />更改為<base href="./" />

第2步:
打開tsconfig.json
將 compilerOptions 中的目標從"target": "es2015"更改為"target": "es5"

參考: https : //github.com/ionic-team/capacitor/issues/1878#issuecomment-523497238

調試您的應用程序並檢查它是否顯示任何錯誤應用程序卡在白屏上,主要是因為應用程序中的錯誤

就我而言,它與 android 平台配置有關。 我做了以下來解決這個問題:

  1. 刪除android文件夾(在您的項目目錄或平台目錄下。)
  2. 運行命令以將 android 添加為平台。

npx cap 添加android

以上命令用於帶電容器的離子。 如果您使用的是cordova,則可以使用常規命令。

  1. 打開 Android Studio 並創建 APK。 此 APK 應按預期工作。

如果你仍然在這里沒有答案,這就是我解決它的方法。

$ ionic cordova run android --simulator --verbose --optimization=false

如果它構建、運行然后進入白屏,請為開發者模式設置 chrome,然后打開以下頁面。

鉻://檢查/#devices

檢查控制台日志是否有任何錯誤,並根據需要修復它們。 奇怪的是它可以在普通的網絡瀏覽器中運行得很好。

注意: --optimization=false 標志對於讓您輕松讀取錯誤很重要。

祝你好運

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM