简体   繁体   English

迁移到 cordova-android-11 并处理新的启动画面 api

[英]Migrating to cordova-android-11 and dealing with the new splash-screen api

I am trying to migrate to cordova-android-11 (from 10.1.2).我正在尝试迁移到 cordova-android-11(从 10.1.2)。 The only issue I still have is the splashScreen.我仍然遇到的唯一问题是启动画面。 I understand that I now have to use the splashSCreen api.我知道我现在必须使用 splashSCreen api。 I tried to do this by creating a new Icon in android studio as described here: https://lessons.livecode.com/m/4069/l/1496759-how-to-create-and-use-adaptive-icons-on-android .我试图通过在 android studio 中创建一个新图标来做到这一点,如下所述: https ://lessons.livecode.com/m/4069/l/1496759-how-to-create-and-use-adaptive-icons-on -安卓 I subsequently added the newly created Icon (ic_launcher.xml) to my cordova project, in the resource folder.随后,我将新创建的图标 (ic_launcher.xml) 添加到我的 cordova 项目的资源文件夹中。 I added the path to this file as a preference in the config.xml, like so:我在 config.xml 中添加了该文件的路径作为首选项,如下所示:

However, this gives me 2 build errors.但是,这给了我 2 个构建错误。 Because the ic_launcher.xml refers to a foreground and a background image:因为 ic_launcher.xml 指的是前景和背景图像:

These do not exist in the Cordova-Android project. Cordova-Android 项目中不存在这些。 Even when I try to add them to my resources, they aren't copied over to my platforms/android folder.即使我尝试将它们添加到我的资源中,它们也不会复制到我的 platforms/android 文件夹中。

Can someone explain to me which files to add where and more generally how Cordova handles this new splash-api?有人可以向我解释要在何处添加哪些文件以及 Cordova 如何更一般地处理这个新的 splash-api? I can find a lot of documentation from android on how to create the new icons.我可以从 android 中找到很多关于如何创建新图标的文档。 But all I can find for Cordova-android is to add that preference to the config.xml, but nothing on what that file should contain.但我能找到的 Cordova-android 的全部内容是将该首选项添加到 config.xml,但没有关于该文件应包含的内容。 How does it handle different pixel densities?它如何处理不同的像素密度? The icon says any-dpi, but how does it achieve this in cordova?图标显示任何 dpi,但它是如何在 cordova 中实现的?

Thanks in Advance, Any help here is much appreciated!在此先感谢,非常感谢这里的任何帮助!

How to make adaptive icons: https://developer.android.com/studio/write/image-asset-studio#create-adaptive如何制作自适应图标: https ://developer.android.com/studio/write/image-asset-studio#create-adaptive

relevant SO question: Cordova 11 - Splash Screen - what goes in splashscreen.xml相关的 SO 问题: Cordova 11 - 启动画面 - splashscreen.xml 中的内容

I think this is deprecated, but it might be helpful in finding a solution: https://www.mathew-paul.nz/posts/cordova-android-adaptive-icons/我认为这已被弃用,但它可能有助于找到解决方案: https ://www.mathew-paul.nz/posts/cordova-android-adaptive-icons/

(copy to git issue: https://github.com/apache/cordova-android/issues/1528 ) (复制到 git 问题: https ://github.com/apache/cordova-android/issues/1528)

below are the files genereated by Android Studio以下是 Android Studio 生成的文件在此处输入图像描述

After a bunch of trial and error I think I finally got it to work in way that should work on all devices.经过多次试验和错误后,我想我终于让它以适用于所有设备的方式工作。 The essential steps I was missing, is that you HAVE TO put your Icon on a square background of size 288px and have your Icon fit within a 192px circle on there.我缺少的基本步骤是,您必须将图标放在大小为 288px 的正方形背景上,并将图标放在 192px 的圆圈内。 As @ddassa explains in the comments.正如@ddassa 在评论中解释的那样。

The second thing that I missed is in order to create the right xml.我错过的第二件事是创建正确的 xml。 You have to start with an.svg and create a Vector Asset rather than an Image Asset.您必须从 an.svg 开始并创建矢量资源而不是图像资源。 This.xml uses density independent pixels(dp's) and should thus work the same on all devices. This.xml 使用与密度无关的像素 (dp's),因此在所有设备上都应该相同。

TL;DR:长话短说:

Step 1 : create an svg of 288x288px.第 1 步:创建一个 288x288px 的 svg。 With the same background colour as the page your loading the icon on and put your logo in the middle of this square.使用与加载图标的页面相同的背景颜色,并将徽标放在该正方形的中间。 Your logo needs to fit within 192px.您的徽标需要在 192 像素以内。 Like in this image:就像这张图片: 图标大小

Step 2 : Use android studio to create an.xml file.第 2 步:使用 android studio 创建一个 .xml 文件。 To do this, open a new project with 'empty activity'.为此,打开一个带有“空活动”的新项目。 right click on the res folder, go to new -> Vector Asset.右键单击 res 文件夹,转到新建 -> Vector Asset。 Select your image from step 1. going through the wizard should result in generating one.xml file.从第 1 步中选择您的图像。通过向导应该会生成 one.xml 文件。

Step 3 : add this.xml file to your resources in Cordova and link to it in your config.xml like so:第 3 步:将 this.xml 文件添加到您在 Cordova 中的资源,并在您的 config.xml 中链接到它,如下所示:

<preference name="AndroidWindowSplashScreenAnimatedIcon" value="path to yourIcon.xml" />

The xml file has dp's, which stands for density independent pixels. xml 文件有 dp,代表密度独立像素。 From that I conclude that it should work independent from screen size and resolution.由此我得出结论,它应该独立于屏幕尺寸和分辨率工作。

link to splashscreen page in android docs (where I got the image from): https://developer.android.com/develop/ui/views/launch/splash-screen链接到 android 文档中的启动画面页面(我从中获取图像): https ://developer.android.com/develop/ui/views/launch/splash-screen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM