PhoneGap Build Android 不显示闪屏

Posted

技术标签:

【中文标题】PhoneGap Build Android 不显示闪屏【英文标题】:PhoneGap Build Android Not Displaying Splashscreen 【发布时间】:2018-01-31 02:44:30 【问题描述】:

这是我的 config.xml 中与启动屏幕相关的代码:

    <splash src="splash.png" />
    <icon src="icon.png"/>
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="10000" />
    <platform name="android">
        <preference name="SplashScreen" value="res/screens/android/drawable-land-ldpi-screen.png" />  
        <splash src="res/screens/android/drawable-land-ldpi-screen.png"/>  
        <icon density="ldpi" src="res/icons/android/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="res/icons/android/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="res/icons/android/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="res/icons/android/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="res/icons/android/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="res/icons/android/drawable-xxxhdpi-icon.png" />
        <splash density="land-ldpi" src="res/screens/android/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="res/screens/android/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="res/screens/android/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="res/screens/android/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="res/screens/android/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="res/screens/android/drawable-land-xxxhdpi-screen.png" />
        <splash density="port-ldpi" src="res/screens/android/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="res/screens/android/drawable-port-mdpi-screen.png" />
        <splash density="port-hdpi" src="res/screens/android/drawable-port-hdpi-screen.png" />
        <splash density="port-xhdpi" src="res/screens/android/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="res/screens/android/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="res/screens/android/drawable-port-xxxhdpi-screen.png" />
    </platform>
    <platform name="ios">
        <preference name="SplashScreen" value="res/screens/ios/Default-568h@2x~iphone.png" />  
        <splash src="res/screens/ios/Default-568h@2x~iphone.png"/>  
        <icon  platform="ios" src="res/icons/ios/icon.png"  />
        <icon  platform="ios" src="res/icons/ios/icon@2x.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-40.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-40@2x.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-50.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-50@2x.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-60.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-60@2x.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-60@3x.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-72.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-72@2x.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-76.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-76@2x.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-small.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-small@2x.png"  />
        <icon  platform="ios" src="res/icons/ios/icon-small@3x.png"  />
        <splash  platform="ios" src="res/screens/ios/Default-568h@2x~iphone.png"  />
        <splash  platform="ios" src="res/screens/ios/Default-667h.png"  />
        <splash  platform="ios" src="res/screens/ios/Default-736h.png"  />
        <splash  platform="ios" src="res/screens/ios/Default-Landscape-736h.png"  />
        <splash  platform="ios" src="res/screens/ios/Default-Landscape@2x~ipad.png"  />
        <splash  platform="ios" src="res/screens/ios/Default-Landscape~ipad.png"  />
        <splash  platform="ios" src="res/screens/ios/Default-Portrait@2x~ipad.png"  />
        <splash  platform="ios" src="res/screens/ios/Default-Portrait~ipad.png"  />
        <splash  platform="ios" src="res/screens/ios/Default@2x~iphone.png"  />
        <splash  platform="ios" src="res/screens/ios/Default~iphone.png"  />
    </platform>

在 iOS 上,启动画面可以完美显示,但在 android 上什么都没有显示。有人对如何解决此错误有任何建议吗?我尝试添加cordova s​​plashscreen插件,但这似乎会使android应用程序在打开时崩溃。我是否遗漏了另一段重要的代码?

【问题讨论】:

Hello @zmalter99 尝试删除 android 标签内的下一个标签: 【参考方案1】:

我为您创建了一个示例,我签入了设备并出现了启动画面。

添加插件

cordova-plugin-splashscreen

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Splashscreen Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" src="js/PushNotification.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() 
        navigator.splashscreen.show();
    

    </script>
  </head>
  <body>
    <h1>Example</h1>
  </body>
</html>

config.xml

    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="3000" />
    <platform name="android">            
            <splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
            <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
            <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
            <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
            <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
            <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
        </platform>
<plugin name="cordova-plugin-splashscreen" spec="~3.2.1" />

我创建了一个名为“resources”的文件夹并添加了启动画面图像并在 config.xml 文件中给出了它的路径。

它正在工作。

【讨论】:

以上是关于PhoneGap Build Android 不显示闪屏的主要内容,如果未能解决你的问题,请参考以下文章

在 Android 上为 PhoneGap App 更改应用程序主题(使用 phonegap Build)

在 Android Phonegap Build 中集成广告

PhoneGap Build - 为 Android 设备设置启动画面

使用 PhoneGap Build 为 iOS 构建现有的 PhoneGap 项目

PhoneGap Build Android 不显示闪屏

我该如何克服这个问题:ANDROID_SUPPORT_V4_VERSION in phonegap build