phonegap build没有显示splashscreen

时间:2014-08-19 13:56:03

标签: android cordova splash-screen phonegap-build

过去曾问过这个问题,但我找到的答案都没有解决我的问题。

我正在尝试创建一个非常简单的phonegap应用程序来显示启动画面,并在它准备好时宣布。它只是一个测试应用程序,可以解决如何使用启动画面。

  • 我正在通过phonegap cli使用phonegap构建。
  • phonegap version 3.5.0
  • 仅在Android上测试

我有一个config.xml所在的www文件夹。所有启动画面都位于www/res/screen/<platform>/filename.png

我的配置文件是

<?xml version='1.0' encoding='utf-8'?>
<widget id="uk.co.workshop14.splashscreen-example-app" version="0.1.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>splashscreen-example-app</name>
    <description>
        Hello World sample application that responds to the deviceready event.
    </description>
    <author email="support@phonegap.com" href="http://phonegap.com">
        Peter
    </author>

    <preference name="permissions" value="none" />
    <preference name="phonegap-version" value="3.5.0" />
    <preference name="orientation" value="default" />
    <preference name="target-device" value="universal" />
    <preference name="fullscreen" value="true" />
    <preference name="webviewbounce" value="true" />
    <preference name="prerendered-icon" value="true" />
    <preference name="stay-in-webview" value="false" />
    <preference name="ios-statusbarstyle" value="black-opaque" />
    <preference name="detect-data-types" value="true" />
    <preference name="exit-on-suspend" value="false" />
    <preference name="show-splash-screen-spinner" value="true" />
    <preference name="auto-hide-splash-screen" value="false" />
    <preference name="SplashScreenDelay" value="10000" />
    <preference name="disable-cursor" value="false" />
    <preference name="android-minSdkVersion" value="7" />
    <preference name="android-installLocation" value="auto" />

    <gap:plugin name="org.apache.cordova.device" />
    <gap:plugin name="org.apache.cordova.splashscreen" />

    <icon src="icon.png" />
    <icon gap:platform="android" gap:qualifier="ldpi" src="res/icon/android/icon-36-ldpi.png" />
    <icon gap:platform="android" gap:qualifier="mdpi" src="res/icon/android/icon-48-mdpi.png" />
    <icon gap:platform="android" gap:qualifier="hdpi" src="res/icon/android/icon-72-hdpi.png" />
    <icon gap:platform="android" gap:qualifier="xhdpi" src="res/icon/android/icon-96-xhdpi.png" />
    <icon gap:platform="blackberry" src="res/icon/blackberry/icon-80.png" />
    <icon gap:platform="blackberry" gap:state="hover" src="res/icon/blackberry/icon-80.png" />
    <icon gap:platform="ios" height="57" src="res/icon/ios/icon-57.png" width="57" />
    <icon gap:platform="ios" height="72" src="res/icon/ios/icon-72.png" width="72" />
    <icon gap:platform="ios" height="114" src="res/icon/ios/icon-57-2x.png" width="114" />
    <icon gap:platform="ios" height="144" src="res/icon/ios/icon-72-2x.png" width="144" />
    <icon gap:platform="webos" src="res/icon/webos/icon-64.png" />
    <icon gap:platform="winphone" src="res/icon/windows-phone/icon-48.png" />
    <icon gap:platform="winphone" gap:role="background" src="res/icon/windows-phone/icon-173.png" />

    <gap:splash gap:platform="android" gap:qualifier="port-ldpi" src="res/screen/android/screen-ldpi-portrait.png" />
    <gap:splash gap:platform="android" gap:qualifier="port-mdpi" src="res/screen/android/screen-mdpi-portrait.png" />
    <gap:splash gap:platform="android" gap:qualifier="port-hdpi" src="res/screen/android/screen-hdpi-portrait.png" />
    <gap:splash gap:platform="android" gap:qualifier="port-xhdpi" src="res/screen/android/screen-xhdpi-portrait.png" />
    <gap:splash gap:platform="blackberry" src="res/screen/blackberry/screen-225.png" />
    <gap:splash gap:platform="ios" height="480" src="res/screen/ios/screen-iphone-portrait.png" width="320" />
    <gap:splash gap:platform="ios" height="960" src="res/screen/ios/screen-iphone-portrait-2x.png" width="640" />
    <gap:splash gap:platform="ios" height="1136" src="res/screen/ios/screen-iphone-portrait-568h-2x.png" width="640" />
    <gap:splash gap:platform="ios" height="1024" src="res/screen/ios/screen-ipad-portrait.png" width="768" />
    <gap:splash gap:platform="ios" height="768" src="res/screen/ios/screen-ipad-landscape.png" width="1024" />
    <gap:splash gap:platform="winphone" src="res/screen/windows-phone/screen-portrait.jpg" />

    <access origin="*" />
</widget>

9 个答案:

答案 0 :(得分:22)

您没有默认的启动标记

<splash src="splash.png" />

它在文档中: http://docs.phonegap.com/phonegap-build/configuring/icons-and-splash/

更新

如果您使用的是手机版本cli-5.1.1或更高版本,则需要使用npm的新启动画面插件。

这里是github上的新插件,你可以在那里找到如何使用它:

https://github.com/apache/cordova-plugin-splashscreen

答案 1 :(得分:7)

我通过添加

解决了这个问题
<preference name="SplashScreen" value="splash" />

这是使用phonegap create时生成的首选项。我也找不到任何好文件。

此外,当我添加此首选项时,我不需要像某些问题中所述的默认启动画面

答案 2 :(得分:2)

经过研究和尝试,最后这对我有用:

将此添加到您的偏好设置:

<preference name="SplashScreen" value="splash" />

并在第一个启动图像src条目之前添加:

<splash src="splash.png" />

也许很重要,因为我不知道:

如果您使用在线phonegap apk转换器启用了水合作用,您必须完全重建您的应用程序,而不是只更新它。这也可以帮助您使用“方向”或“全屏”等首选项!

答案 3 :(得分:0)

Cordova将设备级API实现为插件。使用命令行界面中描述的CLI插件命令为项目添加此功能:请使用以下链接获取更多信息

http://docs.phonegap.com/en/3.3.0/cordova_splashscreen_splashscreen.md.html

答案 4 :(得分:0)

我遇到了同样的问题,我通过将启动图像转换为 .png 而非 .jpg 解决了这个问题。

答案 5 :(得分:0)

您应该(必须)将splash.png - s放入www/res/drawable-*/splash.pngicon.png - 在www/res/drawable-*/icon.png内,以便在www文件夹下设置此结构

res
├── drawable-hdpi
│   └── icon.png
├── drawable-land-hdpi
│   └── splash.png
├── drawable-land-ldpi
│   └── splash.png
├── drawable-land-mdpi
│   └── splash.png
├── drawable-land-xhdpi
│   └── splash.png
├── drawable-land-xxhdpi
│   └── splash.png
├── drawable-land-xxxhdpi
│   └── splash.png
├── drawable-ldpi
│   └── icon.png
├── drawable-mdpi
│   └── icon.png
├── drawable-port-hdpi
│   └── splash.png
├── drawable-port-ldpi
│   └── splash.png
├── drawable-port-mdpi
│   └── splash.png
├── drawable-port-xhdpi
│   └── splash.png
├── drawable-port-xxhdpi
│   └── splash.png
├── drawable-port-xxxhdpi
│   └── splash.png
├── drawable-xhdpi
│   └── icon.png
├── drawable-xxhdpi
│   └── icon.png
└── drawable-xxxhdpi
    └── icon.png

您的config.xml应该包含这些行

    <splash qualifier="land-hdpi" src="res/drawable-land-hdpi/splash.png" />
    <splash qualifier="land-ldpi" src="res/drawable-land-ldpi/splash.png" />
    <splash qualifier="land-mdpi" src="res/drawable-land-mdpi/splash.png" />
    <splash qualifier="land-xhdpi" src="res/drawable-land-xhdpi/splash.png" />
    <splash qualifier="land-xxhdpi" src="res/drawable-land-xxhdpi/splash.png" />
    <splash qualifier="land-xxxhdpi" src="res/drawable-land-xxxhdpi/splash.png" />
    <splash qualifier="port-hdpi" src="res/drawable-port-hdpi/splash.png" />
    <splash qualifier="port-ldpi" src="res/drawable-port-ldpi/splash.png" />
    <splash qualifier="port-mdpi" src="res/drawable-port-mdpi/splash.png" />
    <splash qualifier="port-xhdpi" src="res/drawable-port-xhdpi/splash.png" />
    <splash qualifier="port-xxhdpi" src="res/drawable-port-xxhdpi/splash.png" />
    <splash qualifier="port-xxxhdpi" src="res/drawable-port-xxxhdpi/splash.png" />
    <icon qualifier="hdpi" src="res/drawable-hdpi/icon.png" />
    <icon qualifier="ldpi" src="res/drawable-ldpi/icon.png" />
    <icon qualifier="mdpi" src="res/drawable-mdpi/icon.png" />
    <icon qualifier="xhdpi" src="res/drawable-xhdpi/icon.png" />
    <icon qualifier="xxhdpi" src="res/drawable-xxhdpi/icon.png" />
    <icon qualifier="xxxhdpi" src="res/drawable-xxxhdpi/icon.png" />

完整图片,这是我的config.xml

的android部分
<platform name="android">
    <allow-intent href="market:*" />
    <preference name="android-minSdkVersion" value="14" />
    <preference name="android-targetSdkVersion" value="22" />
    <preference name="SplashScreen" value="splash" />
    <preference name="SplashScreenDelay" value="3000" />
    <preference name="ShowSplashScreenSpinner" value="false" />
    <preference name="FadeSplashScreen" value="false" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <splash qualifier="land-hdpi" src="res/drawable-land-hdpi/splash.png" />
    <splash qualifier="land-ldpi" src="res/drawable-land-ldpi/splash.png" />
    <splash qualifier="land-mdpi" src="res/drawable-land-mdpi/splash.png" />
    <splash qualifier="land-xhdpi" src="res/drawable-land-xhdpi/splash.png" />
    <splash qualifier="land-xxhdpi" src="res/drawable-land-xxhdpi/splash.png" />
    <splash qualifier="land-xxxhdpi" src="res/drawable-land-xxxhdpi/splash.png" />
    <splash qualifier="port-hdpi" src="res/drawable-port-hdpi/splash.png" />
    <splash qualifier="port-ldpi" src="res/drawable-port-ldpi/splash.png" />
    <splash qualifier="port-mdpi" src="res/drawable-port-mdpi/splash.png" />
    <splash qualifier="port-xhdpi" src="res/drawable-port-xhdpi/splash.png" />
    <splash qualifier="port-xxhdpi" src="res/drawable-port-xxhdpi/splash.png" />
    <splash qualifier="port-xxxhdpi" src="res/drawable-port-xxxhdpi/splash.png" />
    <icon qualifier="hdpi" src="res/drawable-hdpi/icon.png" />
    <icon qualifier="ldpi" src="res/drawable-ldpi/icon.png" />
    <icon qualifier="mdpi" src="res/drawable-mdpi/icon.png" />
    <icon qualifier="xhdpi" src="res/drawable-xhdpi/icon.png" />
    <icon qualifier="xxhdpi" src="res/drawable-xxhdpi/icon.png" />
    <icon qualifier="xxxhdpi" src="res/drawable-xxxhdpi/icon.png" />
</platform>

现在执行phonegap remote build android并从phonegap build打开日志文件。

日志文件位于https://build.phonegap.com/apps/X/logs/android/build/XApp ID

在日志中,您应该看到类似

的内容
...
[crunch] Processing image to cache: /project/res/drawable-hdpi/icon.png => /project/bin/res/drawable-hdpi/icon.png
[crunch]   (processed image to cache entry /project/bin/res/drawable-hdpi/icon.png: 0% size of source)
[crunch] Processing image to cache: /project/res/drawable-land-ldpi/splash.png => /project/bin/res/drawable-land-ldpi/splash.png
...

如果您看到这些线条,那么您的启动画面应该可以正常工作。

另请注意config.xml

中的这一行

<preference name="SplashScreen" value="splash" />

这告诉phonegap构建你的启动画面png文件被命名为splash.png。这样系统就能找到它们。

答案 6 :(得分:0)

在我的案例中,我刚刚添加<preference name="ShowSplashScreenSpinner" value="false"/>它就是魔术。

以下是我的config.xml中的Android部分

    <platform name="android">
        <allow-intent href="market:*" />
        <preference name="ShowSplashScreenSpinner" value="false"/>
    <splash src="res/screen/android/splash-land-hdpi.png" density="land-hdpi"/>
   <splash src="res/screen/android/splash-land-hdpi.png" density="land-ldpi"/>
   <splash src="res/screen/android/splash-land-hdpi.png" density="land-mdpi"/>
   <splash src="res/screen/android/splash-land-hdpi.png" density="land-xhdpi"/>
   <splash src="res/screen/android/splash-land-hdpi.png" density="port-hdpi"/>
   <splash src="res/screen/android/splash-land-hdpi.png" density="port-ldpi"/>
   <splash src="res/screen/android/splash-land-hdpi.png" density="port-mdpi"/>
   <splash src="res/screen/android/splash-land-hdpi.png" density="port-xhdpi"/> 
 </platform>

答案 7 :(得分:0)

Phonegap会定期更新其构建系统,因此您可能还希望跟踪这些更改。直到昨天,我看到了android的闪光但是今天没有看到它(6.5.0),即使我没有对config.xml进行任何更改

将以下首选项添加到最近引入的构建器版本首选项后,它再次起作用。

<preference name='phonegap-version' value='cli-6.5.0' />
<preference name='pgb-builder-version' value='2' />

builder-version 1 for old builder,2是new使用cordova like builder。

阅读以下pgb博客文章了解更多详情。

https://blog.phonegap.com/phonegap-7-0-1-now-on-build-and-it-includes-some-important-changes-89087fe465f5

答案 8 :(得分:0)

非常沮丧之后,我很幸运地发现this thread有各种各样的建议。

只需将config.xml文件中的splash元素的density属性更改为qualifier即可解决此问题。我包含插件声明以防万一。

<plugin name="cordova-plugin-splashscreen" spec="~5.0.2" />

<platform name="android">
    <icon qualifier="ldpi" src="www/res/icon/android/drawable-ldpi-icon.png" />
    <icon qualifier="mdpi" src="www/res/icon/android/drawable-mdpi-icon.png" />
    <icon qualifier="hdpi" src="www/res/icon/android/drawable-hdpi-icon.png" />
    <icon qualifier="xhdpi" src="www/res/icon/android/drawable-xhdpi-icon.png" />
    <icon qualifier="xxhdpi" src="www/res/icon/android/drawable-xxhdpi-icon.png" />
    <icon qualifier="xxxhdpi" src="www/res/icon/android/drawable-xxxhdpi-icon.png" />
    <splash qualifier="land-ldpi" src="www/res/screen/android/drawable-land-ldpi-screen.png" />
    <splash qualifier="land-mdpi" src="www/res/screen/android/drawable-land-mdpi-screen.png" />
    <splash qualifier="land-hdpi" src="www/res/screen/android/drawable-land-hdpi-screen.png" />
    <splash qualifier="land-xhdpi" src="www/res/screen/android/drawable-land-xhdpi-screen.png" />
    <splash qualifier="land-xxhdpi" src="www/res/screen/android/drawable-land-xxhdpi-screen.png" />
    <splash qualifier="land-xxxhdpi" src="www/res/screen/android/drawable-land-xxxhdpi-screen.png" />
    <splash qualifier="port-ldpi" src="www/res/screen/android/drawable-port-ldpi-screen.png" />
    <splash qualifier="port-mdpi" src="www/res/screen/android/drawable-port-mdpi-screen.png" />
    <splash qualifier="port-hdpi" src="www/res/screen/android/drawable-port-hdpi-screen.png" />
    <splash qualifier="port-xhdpi" src="www/res/screen/android/drawable-port-xhdpi-screen.png" />
    <splash qualifier="port-xxhdpi" src="www/res/screen/android/drawable-port-xxhdpi-screen.png" />
    <splash qualifier="port-xxxhdpi" src="www/res/screen/android/drawable-port-xxxhdpi-screen.png" />
</platform>