Android phonegap build 不显示闪屏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25385308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
phonegap build not showing splashscreen
提问by Peter Saxton
This question has been asked in the past but none of the answers that I have found have solved the problem for me.
这个问题过去曾被问过,但我找到的答案都没有为我解决这个问题。
I am trying to make a very simple phonegap app to show a splash screen and announce when it is ready. It is just a test app to work out how to use the splash screen.
我正在尝试制作一个非常简单的 phonegap 应用程序来显示启动画面并在它准备好时宣布。它只是一个测试应用程序,用于研究如何使用启动画面。
- I am using phonegap build through the phonegap cli.
- phonegap version 3.5.0
- tested on android only
- 我正在通过 phonegap cli 使用 phonegap build。
- phonegap 版本 3.5.0
- 仅在安卓上测试
I have a www folder where config.xml
is located. All the splashscreens are located within www/res/screen/<platform>/filename.png
我有一个 www 文件夹config.xml
。所有的启动画面都位于www/res/screen/<platform>/filename.png
my config file is
我的配置文件是
<?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="[email protected]" 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>
回答by Subjective Effect
You don't have the default splash tag which is
你没有默认的飞溅标签
<splash src="splash.png" />
It's in the documentation: http://docs.phonegap.com/phonegap-build/configuring/icons-and-splash/
它在文档中:http: //docs.phonegap.com/phonegap-build/configuring/icons-and-splash/
Update
更新
If you are using phonegap version cli-5.1.1 or above, you need the new splashscreen plugin from npm.
如果您使用的是 phonegap 版本 cli-5.1.1 或更高版本,则需要来自 npm 的新闪屏插件。
Here's the new plugin on github, there you can find how to use it:
这是github上的新插件,您可以在那里找到如何使用它:
回答by Peter Saxton
I solved the problem by adding
我通过添加解决了这个问题
<preference name="SplashScreen" value="splash" />
This is an additional preference to those generated when using phonegap create. I also can't find any good documentation on this.
这是对使用 phonegap create 时生成的那些的额外偏好。我也找不到任何关于此的好的文档。
In addition I do not require a default splashscreen as described in some questions when I add this preference
此外,当我添加此首选项时,我不需要某些问题中所述的默认启动画面
回答by howard.D
After researching and trying a lot, finally this worked for me:
经过大量研究和尝试,最终这对我有用:
Add this to your preferences:
将此添加到您的首选项中:
<preference name="SplashScreen" value="splash" />
and add this before your first splash image src entry:
并在您的第一个初始图像 src 条目之前添加:
<splash src="splash.png" />
Maybe important to mention because i did not know it:
也许很重要,因为我不知道:
If you use the online phonegap apk converter with hydration enabled to your application, u'll have to rebuild your app completly instead of just update it. This will help you also with preferences like "orientation" or "fullscreen" !
如果您使用在线 phonegap apk 转换器并为您的应用程序启用了水合作用,则您必须完全重建您的应用程序,而不仅仅是更新它。这也将帮助您设置“方向”或“全屏”等偏好!
回答by RAJESH KUMAR ARUMUGAM
In my Case I just Added <preference name="ShowSplashScreenSpinner" value="false"/>
it does the Magic.
在我的情况下,我刚刚添加了 <preference name="ShowSplashScreenSpinner" value="false"/>
它的魔力。
Here is the Android part in my config.xml
这是我的 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>
回答by Ajay Singh
Phonegap updates their build system regularly, so you may also want to keep in track of those changes. Till yesterday, I was seeing splash on android but didn't see it working today (on 6.5.0), even though I had not made any changes to config.xml
Phonegap 会定期更新他们的构建系统,因此您可能还想跟踪这些更改。直到昨天,我在 android 上看到了飞溅,但今天没有看到它(在 6.5.0 上),即使我没有对 config.xml 做任何更改
After adding the following preferences to their recently introduced builder version preference, it works again.
将以下首选项添加到他们最近引入的构建器版本首选项后,它又可以工作了。
<preference name='phonegap-version' value='cli-6.5.0' />
<preference name='pgb-builder-version' value='2' />
builder-version 1 for old builder and 2 for the new which uses cordova like builder.
builder-version 1 用于旧构建器,2 用于使用像构建器一样的cordova 的新构建器。
Read the following pgb blog post for more details.
阅读以下 pgb 博客文章以了解更多详细信息。
回答by Brett84c
After much frustration, I thankfully found this threadthat had various suggestions.
Simply changing the density
attribute to qualifier
on the splash elements in the config.xml file ended up fixing this issue for me. I'm including the plugin declaration in case it helps.
简单地将density
属性更改为qualifier
config.xml 文件中的 splash 元素最终为我解决了这个问题。我包括插件声明以防万一。
<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>
回答by Rathore
Cordova implements device-level APIs as plugins. Use the CLI's plugin command, described in The Command-Line Interface, to add this feature for a project: Please use following link for more information
Cordova 将设备级 API 实现为插件。使用命令行界面中描述的 CLI 插件命令为项目添加此功能:请使用以下链接获取更多信息
http://docs.phonegap.com/en/3.3.0/cordova_splashscreen_splashscreen.md.html
http://docs.phonegap.com/en/3.3.0/cordova_splashscreen_splashscreen.md.html
回答by jgleal
I had the same problem and I solved it by converting the splash image to be .pnginstead of .jpg.
我遇到了同样的问题,我通过将启动图像转换为.png而不是.jpg来解决它。
回答by Levon
You should (as in must) put your splash.png
-s inside www/res/drawable-*/splash.png
and icon.png
-s inside www/res/drawable-*/icon.png
so that to have this structure under www
folder
你应该(必须)把你的splash.png
-s 放在里面www/res/drawable-*/splash.png
,icon.png
-s 放在里面,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
And your config.xml
should contain these lines
你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" />
For full picture, here is the android section of my config.xml
对于完整图片,这是我的 android 部分 config.xml
<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>
Now execute phonegap remote build android
and open the log file from phonegap build.
现在phonegap remote build android
从 phonegap build执行并打开日志文件。
The log file is located at https://build.phonegap.com/apps/X/logs/android/build/
where X
is your App ID
日志文件位于https://build.phonegap.com/apps/X/logs/android/build/
何处X
是你的App ID
In the log you should see something like
在日志中,您应该看到类似
...
[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
...
If you see these lines then your splash screen should work.
如果您看到这些行,那么您的启动画面应该可以工作。
Also note this line in config.xml
还要注意这一行 config.xml
<preference name="SplashScreen" value="splash" />
<preference name="SplashScreen" value="splash" />
This tells the phonegap build that your splash screen png files are named as splash.png
. This way the system is able to locate them.
这告诉 phonegap 构建您的启动画面 png 文件被命名为splash.png
. 这样系统就能够找到它们。