Cordova ios 错误构建 Images.xcassets

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36095819/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 08:43:25  来源:igfitidea点击:

Cordova ios error building Images.xcassets

ioscordovanpm

提问by csga5000

I've spent a lot of time trying to work this out to no avail.

我花了很多时间试图解决这个问题,但无济于事。

I udpated cordova and since el capitan my mac now has issues with NPM and cordova.

我更新了cordova,自从el capan 我的mac 现在有NPM 和cordova 的问题。

I got it to install but I have to use sudo for cordova now.

我安装了它,但我现在必须对cordova 使用sudo。

I triedthe following:

尝试了以下方法:

sudo cordova platform remove ios
sudo cordova platform add ios
sudo cordova build ios

And this gives me the following output:

这给了我以下输出:

** BUILD FAILED **


The following build commands failed:
    CompileAssetCatalog build/emulator/<AppName>.app <AppName>/Images.xcassets
(1 failure)
ERROR building one of the platforms: Error code 65 for command: xcodebuild with args: -xcconfig,/Users/MacUserName/Desktop/<AppName>/<AppName>/platforms/ios/cordova/build-debug.xcconfig,-project,<AppName>.xcodeproj,ARCHS=i386,-target,<AppName>,-configuration,Debug,-sdk,iphonesimulator,build,VALID_ARCHS=i386,CONFIGURATION_BUILD_DIR=/Users/MacUserName/Desktop/<AppName>/<AppName>/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/Users/MacUserName/Desktop/<AppName>/<AppName>/platforms/ios/build/sharedpch
You may not have the required environment or OS to build this project
Error: Error code 65 for command: xcodebuild with args: -xcconfig,/Users/MacUserName/Desktop/<AppName>/<AppName>/platforms/ios/cordova/build-debug.xcconfig,-project,<AppName>.xcodeproj,ARCHS=i386,-target,<AppName>,-configuration,Debug,-sdk,iphonesimulator,build,VALID_ARCHS=i386,CONFIGURATION_BUILD_DIR=/Users/MacUserName/Desktop/<AppName>/<AppName>/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/Users/MacUserName/Desktop/<AppName>/<AppName>/platforms/ios/build/sharedpch

Cordova version

科尔多瓦版本

sudo cordova -v
6.0.0

Update: I'm now running 6.1.1, still the same issue

更新:我现在运行的是 6.1.1,还是同样的问题

Cordova iOS platform version

Cordova iOS平台版本

sudo cordova platform ios -v
6.1.1

Mac Version: 10.11.3
XCode Version:7.2.1

Mac 版本:10.11.3
XCode 版本:7.2.1

采纳答案by csga5000

I would recommend using the cordova-icon and cordova-splash npm packages. This is because you can just put two images in your root, then the commands will work out the rest for you. They are written by cordova, and you can install using:

我建议使用 cordova-icon 和 cordova-splash npm 包。这是因为您可以在根目录中放置两个图像,然后命令将为您解决其余的问题。它们由cordova编写,您可以使用以下方法安装:

npm install -g cordova-icon
npm install -g cordova-splash

Then just put a 1024x1024 version of your logo as "icon.png" in the project root. And:

然后在项目根目录中放置一个 1024x1024 版本的徽标作为“icon.png”。和:

"The splash screen image should be 2208x2208 px with a center square of about 1200x1200 px. The image may be cropped around the center square."

https://www.npmjs.com/package/cordova-splash

“初始屏幕图像应为 2208x2208 像素,中心正方形约为 1200x1200 像素。图像可能会围绕中心正方形进行裁剪。”

https://www.npmjs.com/package/cordova-splash

Just put an image matching that description in the project root as "splash.png"

只需将与该描述匹配的图像作为“splash.png”放在项目根目录中

Remove any lines in config.xml that specify the images to use for ios, cordova-icon/splash will automatically put them in the correct place with the right names so that xcode will recognize them.

删除 config.xml 中指定要用于 ios 的图像的任何行,cordova-icon/splash 会自动将它们以正确的名称放在正确的位置,以便 xcode 识别它们。

Once you've got that setup, just execute these commands:

完成设置后,只需执行以下命令:

cordova platform remove ios
cordova platform add ios
cordova-icon
cordova-splash

Then run your build command. For me it is:

然后运行您的构建命令。对我来说是:

cordova build ios --build-config

But you may not have a build config, or need additional params. If the build fails (make sure you run the command even if you think it will fail - it will set things up) just open the generated workspace in platforms/ios in xcode, clean the project, and build. That should work.

但是您可能没有构建配置,或者需要额外的参数。如果构建失败(确保您运行命令,即使您认为它会失败 - 它会设置一切)只需在 xcode 中的平台 / ios 中打开生成的工作区,清理项目,然后构建。那应该工作。

回答by FrodmanG

I managed to fix this issue by:

我设法通过以下方式解决了这个问题:

  • removing any icon or splash screen references in the config.xmlfile;
  • put a splash.pngand/or icon.pngfiles in the www/resourcesfolder of your cordova project; then,
  • run the ionic cordova resources --iconor ionic cordova resources --splashcommand
  • 删除文件中的任何图标或启动画面引用config.xml
  • 将一个splash.png和/或icon.png文件放在www/resources您的cordova项目的文件夹中;然后,
  • 运行ionic cordova resources --iconorionic cordova resources --splash命令

this will create all the correct splash/icon files for you and add them to the config.xmlfile. That warning then goes away.

这将为您创建所有正确的启动/图标文件并将它们添加到config.xml文件中。然后那个警告就消失了。

Hope this works!

希望这有效!

回答by Shashank Saxena

  1. Rename Platform/ios
  2. on terminal type: cordova platform add ios
  3. cordova build ios.
  1. 重命名平台/ios
  2. 在终端类型上: cordova platform add ios
  3. cordova build ios.

worked at my case

在我的情况下工作

回答by Ayman Salama

Ths simple solution that I have tried is to add the correct size of the image 1024x1024

我尝试过的简单解决方案是添加正确大小的图像 1024x1024

   <platform name="ios">
        <icon src="res/icon-1024.png" />
    </platform>

回答by kris

I got this error when I was using cordova-iconbut my icon.pngimage was not square.

我在使用时遇到此错误,cordova-icon但我的icon.png图像不是方形的。

Changing the icon.pngto a square image and re-doing cordova-iconmeant that cordova build iosnow works for me.

将其更改icon.png为方形图像并重新执行cordova-icon意味着cordova build ios现在对我有用。

回答by Nicolas Albert

For a solo icon.pngfile, the image must be 1024x1024to get working with a solo <icon src="icon.png"/>in the config.xml.

对于 solo icon.png文件,图像必须为1024x1024才能<icon src="icon.png"/>config.xml 中使用 solo 。

I have to this with cordova-cli 6.5.0, cordova-ios 4.5.1and xcodebuild 9.0.

我必须使用cordova-cli 6.5.0cordova-ios 4.5.1xcodebuild 9.0

回答by geoathome

After digging into cordova_lib I think it's clear (to me) that cordova is not supposed to resize the icon for you but only copy them if they exist and have the right dimensions.

在深入研究 cordova_lib 之后,我认为很明显(对我而言)cordova 不应该为您调整图标的大小,而仅在它们存在且尺寸正确时才复制它们。

See this code in cordova-lib\src\cordova\metadata\ios_parser.js:

在cordova-lib\src\cordova\metadata\ios_parser.js 中查看此代码:

// See https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/LaunchImages.html
// for launch images sizes reference.
var platformIcons = [
    {dest: 'icon-60.png', width: 60, height: 60},
    {dest: '[email protected]', width: 120, height: 120},
    {dest: '[email protected]', width: 180, height: 180},
    {dest: 'icon-76.png', width: 76, height: 76},
    {dest: '[email protected]', width: 152, height: 152},
    {dest: 'icon-small.png', width: 29, height: 29},
    {dest: '[email protected]', width: 58, height: 58},
    {dest: 'icon-40.png', width: 40, height: 40},
    {dest: '[email protected]', width: 80, height: 80},
    {dest: 'icon.png', width: 57, height: 57},
    {dest: '[email protected]', width: 114, height: 114},
    {dest: 'icon-72.png', width: 72, height: 72},
    {dest: '[email protected]', width: 144, height: 144},
    {dest: 'icon-50.png', width: 50, height: 50},
    {dest: '[email protected]', width: 100, height: 100}
];

var destIconsFolder, destSplashFolder;
var xcassetsExists = folderExists(path.join(platformRoot, 'Images.xcassets/'));

if (xcassetsExists) {
    destIconsFolder = 'Images.xcassets/AppIcon.appiconset/';
} else {
    destIconsFolder = 'Resources/icons/';
}

platformIcons.forEach(function (item) {
    var icon = icons.getBySize(item.width, item.height) || icons.getDefault();
    if (icon){
        var src = path.join(appRoot, icon.src),
            dest = path.join(platformRoot, destIconsFolder, item.dest);
        events.emit('verbose', 'Copying icon from ' + src + ' to ' + dest);
        shell.cp('-f', src, dest);
    }
});

The best option seems to be using a plugin which does the resizing for you with hooks. Check out Generating iOS and Android icons in Cordova / PhoneGapor https://github.com/disusered/cordova-icon-gmfor a new more futureproof version of the same plugin (hooks in directories are deprecated in 6.x).

最好的选择似乎是使用一个插件,它通过钩子为你调整大小。查看在 Cordova / PhoneGaphttps://github.com/disusered/cordova-icon-gm 中生成 iOS 和 Android 图标以获取相同插件的新的更具前瞻性的版本(目录中的钩子在 6.x 中已弃用)。

回答by Martina

I managed to solve this issue by removing the non-storyboard splash references in config.xml, the newest version of cordova seems to be only using the storyboard ones:

我设法通过删除 config.xml 中的非故事板飞溅引用来解决这个问题,最新版本的cordova似乎只使用故事板:

So removed:

所以删除:

    <splash src="res/ios/splash/Default~iphone.png" width="320" height="480"/>
    <splash src="res/ios/splash/Default@2x~iphone.png" width="640" height="960"/>
    <splash src="res/ios/splash/Default-Portrait~ipad.png" width="768" height="1024"/>
    <splash src="res/ios/splash/Default-Portrait@2x~ipad.png" width="1536" height="2048"/>
    <splash src="res/ios/splash/Default-Landscape~ipad.png" width="1024" height="768"/>
    <splash src="res/ios/splash/Default-Landscape@2x~ipad.png" width="2048" height="1536"/>
    <splash src="res/ios/splash/Default-568h@2x~iphone.png" width="640" height="1136"/>
    <splash src="res/ios/splash/Default-667h.png" width="750" height="1334"/>
    <splash src="res/ios/splash/Default-736h.png" width="1242" height="2208"/>
    <splash src="res/ios/splash/Default-Landscape-736h.png" width="2208" height="1242"/>

And kept only these:

并且只保留了这些:

        <splash src="res/ios/splash/Default@2x~iphone~anyany.png" />
        <splash src="res/ios/splash/Default@2x~iphone~comany.png" />
        <splash src="res/ios/splash/Default@2x~iphone~comcom.png" />
        <splash src="res/ios/splash/Default@3x~iphone~anyany.png" />
        <splash src="res/ios/splash/Default@3x~iphone~anycom.png" />
        <splash src="res/ios/splash/Default@3x~iphone~comany.png" />
        <splash src="res/ios/splash/Default@2x~ipad~anyany.png" />
        <splash src="res/ios/splash/Default@2x~ipad~comany.png" />

回答by Oshadha Punchihewa

This is not a difficult error.Only thing has to do is remove all lines with

这不是一个困难的错误。唯一要做的就是删除所有行

Images.xcastsets

图像.xcastsets

from

platform/ios/.xcodeproject

平台/ios/.xcodeproject

Then remove platform ionic cordova platform rm ios, Add platform again and build.

然后删除platform ionic cordova platform rm ios,再次添加platform,build。

ionic cordova platform add ios

ionic cordova build ios

离子cordova平台添加ios

离子科尔多瓦构建ios

回答by Bryan

I had the same problem as the OP and whilst the accepted answer was correct and helpful there is now an updated (and maintained) resource generator on npm called cordova-res, which replaces cordova-icon and cordova-splash. Also, the required splash screen dimensions have increased. All the details you need are on the npmjs cordova-res page, from which I have taken the following info.

我遇到了与 OP 相同的问题,虽然接受的答案是正确且有帮助的,但现在 npm 上有一个更新(并维护)的资源生成器,名为cordova-res,它取代了cordova-icon 和cordova-splash。此外,所需的启动画面尺寸也增加了。您需要的所有详细信息都在npmjs cordova-res 页面上,我从中获取了以下信息。

Install with:

安装:

npm install -g cordova-res 

You'll need your icon.png and splash.png (the website says JPEG or PNG) images ready. These need to have the following dimensions:

你需要准备好你的 icon.png 和 splash.png(网站说 JPEG 或 PNG)图像。这些需要具有以下尺寸:

icon.(png|jpg) must be at least 1024 × 1024px

icon.(png|jpg) 必须至少为 1024 × 1024px

splash.(png|jpg) must be at least 2732 × 2732px (note the increased size)

splash.(png|jpg) 必须至少为 2732 × 2732px(注意增加的尺寸)

Just a little side note about the splash screen. Your image needs to be in the centre of the splash screen so that different rectangular device sized images are generated without cropping your splash screen image. As the accepted answer says, the size of this centre image needs to be about 1200 x 1200px.

只是关于闪屏的一点说明。您的图像需要位于初始屏幕的中心,以便在不裁剪初始屏幕图像的情况下生成不同矩形设备大小的图像。正如公认的答案所说,此中心图像的大小需要约为 1200 x 1200 像素。

Place these images in a resources folder in your project:

将这些图像放在项目的资源文件夹中:

resources/
├── icon.png
└── splash.png

Before you generate the resources it might be worth removing and adding your ios platform (and others if you're building them too) to start with a clean platform folder. I don't know for sure if this is necessary.

在您生成资源之前,可能值得删除和添加您的 ios 平台(以及其他平台,如果您也在构建它们)以从一个干净的平台文件夹开始。我不确定这是否有必要。

cordova platform remove ios
cordova platform add ios

Run the following to generate the resources:

运行以下命令以生成资源:

$ cordova-res

Then you can build your platform:

然后你可以构建你的平台:

cordova build ios

Now all should be OK and hopefully resolved your xcassets error, as it did for me.

现在一切都应该没问题,并希望解决您的 xcassets 错误,就像对我所做的那样。