xcode 6.1 升级后,我们如何手动修复“ResourceRules.plist: cannot read resources”错误?

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

How do we manually fix "ResourceRules.plist: cannot read resources" error after xcode 6.1 upgrade?

xcodejenkinsunity3dxcode6.1

提问by Tim

We are having the same issue found here, here, hereand here

我们在这里这里这里这里发现了同样的问题

Basically we upgraded to xcode 6.1 and our build are getting the "ResourceRules.plist: cannot read resources" error.

基本上我们升级到 xcode 6.1 并且我们的构建收到“ResourceRules.plist:无法读取资源”错误。

We have a Jenkins server that does our ios builds for us. We are using the Xcode pluginon Jenkins to do the actual build and signing. Any thoughts on how we can make this change without manually opening xcode and doing this solution found on the other answers:

我们有一个 Jenkins 服务器,可以为我们构建 ios。我们在 Jenkins上使用Xcode 插件来进行实际的构建和签名。关于如何在不手动打开 xcode 的情况下进行此更改并在其他答案中找到此解决方案的任何想法:

Click on your project > Targets > Select your target > Build Settings >

Code Signing Resource Rules Path

and add :

$(SDKROOT)/ResourceRules.plist

单击您的项目 > 目标 > 选择您的目标 > 构建设置 >

代码签名资源规则路径

并添加:

$(SDKROOT)/ResourceRules.plist

I'm very new to Xcode and iOS build in general. I have found the project.pbxproj file inside the Unity-iPhone.xcodeproj file. It looks like this contains the build settings under the /* Begin XCBuildConfiguration section */section it lists what looks like similar build properties foundin Xcode, however I do not see anything like "Code Signing Resource Rules Path".

总的来说,我对 Xcode 和 iOS 构建非常陌生。我在 Unity-iPhone.xcodeproj 文件中找到了 project.pbxproj 文件。看起来这包含/* Begin XCBuildConfiguration 部分下的构建设置*/部分它列出了在 Xcode 中找到的类似构建属性,但是我没有看到类似“代码签名资源规则路径”的内容。

Does anyone have experience manually editing this file? Is that a bad idea in general?

有没有人有手动编辑这个文件的经验?一般来说,这是一个坏主意吗?

Thanks

谢谢

回答by nick

If you're using Jenkins with the XCode plugin, you can modify the 'Code Signing Resource Rules Path'variable by adding:

如果您将 Jenkins 与 XCode 插件一起使用,您可以'Code Signing Resource Rules Path'通过添加以下内容来修改变量:

"CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist" 

to the

'Custom xcodebuild arguments'setting for the XCode plugin.

'Custom xcodebuild arguments'XCode 插件的设置。

This fix does not require the XCode GUI.

此修复不需要 XCode GUI。

回答by sidneys

I encountered the same problem. Nicks solution does work, but is requiring additional dependencies. You don't need the heavy-handed npm xcodemodule for this. Just add a line to this file: $PROJECT_ROOT/platforms/ios/cordova/build.xcconfig

我遇到了同样的问题。Nicks 解决方案确实有效,但需要额外的依赖项。为此,您不需要笨拙的npm xcode模块。只需在此文件中添加一行: $PROJECT_ROOT/platforms/ios/cordova/build.xcconfig

CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist

Note that before XCode 6.1.1, this needed to be specified as "$(SDKROOT)/ResourceRules.plist"(notice the quotes).

请注意,在 XCode 6.1.1 之前,这需要指定为"$(SDKROOT)/ResourceRules.plist"(注意引号)。

If you are running this inside automated build systems such as Jenkins and wont't/can't use any XCode GUI, just create a small Cordova hook, leveraging npm's fs.appendFile, at this location: $PROJECT_ROOT/hooks/before_build/ios_resourcerules.js(make sure it has chmod +x)

如果您在 Jenkins 等自动构建系统中运行它并且不会/不能使用任何 XCode GUI,只需在此位置创建一个小的 Cordova 钩子,利用 npm 的fs.appendFile$PROJECT_ROOT/hooks/before_build/ios_resourcerules .js(确保它有 chmod +x)

#! /usr/local/bin/node
var fs = require("fs");

fs.appendFileSync('build.xcconfig', '\nCODE_SIGN_RESOURCE_RULES_PATH =  $(SDKROOT)/ResourceRules.plist', function (err) {
 if (err) throw err;
  console.log('CODE_SIGN_RESOURCE_RULES_PATH added to Cordova iOS build configuration.');
});

This will mightbe merged in an upcoming Cordova release, so the hook will become unnecessary (i'm creating asee this PR for Cordova-iOS).

可能会在即将发布的 Cordova 版本中合并,因此钩子将变得不必要(我正在为 Cordova-iOS创建一个请参阅此 PR)。

In case the above JavaScript snippet fails to execute due to a "wrong argument" failure, replace the file's content as follows:

如果上述 JavaScript 代码段由于“错误参数”失败而无法执行,请按如下方式替换文件内容:

#!/bin/bash

if [ ! -f ./build.xcconfig ]; then
  echo "[ERROR] hook befor_build/ios_resourcerules.sh cannot execute, ./build/xcconfig not found in $PWD"
  exit 1
fi

echo '// (CB-7872) Solution for XCode 6.1 signing errors related to resource envelope format deprecation' >> ./build.xcconfig
echo 'CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist' >> ./build.xcconfig
echo 'CODE_SIGN_RESOURCE_RULES_PATH added to Cordova iOS build configuration.'

回答by Ben Flynn

If you want to get really crazy, you can directly update PackageApplication.

如果你真的想疯了,你可以直接更新PackageApplication。

# In /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication
my @codesign_args = ("/usr/bin/codesign", "--force", "--preserve-metadata=identifier,entitlements,resource-rules",
                     "--sign", $opt{sign},
                     "--resource-rules=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/ResourceRules.plist");
# OLD:               "--resource-rules=$destApp/ResourceRules.plist");

I was already hacking this script to accept a keychain arg, so it made sense for me. Note I'm not using the Xcode Jenkins plugin -- I'm using Jenkins but running all the build commands from a script.

我已经在破解这个脚本来接受钥匙串 arg,所以这对我来说很有意义。注意我没有使用 Xcode Jenkins 插件——我使用的是 Jenkins 而是从脚本运行所有构建命令。

回答by Renaud Tilte

After the new release of XCode 7 on 23rd Sept 2015, Apple started rejecting any application that is using CODE_SIGN_RESOURCE_RULES_PATH, making the Jenkins build automatically rejected. However, setting CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plistinto the Custom xcodebuild arguments causes a build failure.

在 2015 年 9 月 23 日发布新的 XCode 7 之后,Apple 开始拒绝任何使用 的应用程序CODE_SIGN_RESOURCE_RULES_PATH,从而自动拒绝 Jenkins 构建。但是,设置CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist自定义 xcodebuild 参数会导致构建失败。

This answer resolved the issue: https://stackoverflow.com/a/32762413/5373468

这个答案解决了这个问题:https: //stackoverflow.com/a/32762413/5373468

This is clearly a bug that Apple forgot to fix a while ago, as this article is also highlighting: http://cutting.io/posts/packaging-ios-apps-from-the-command-line/

这显然是 Apple 不久前忘记修复的错误,因为本文还强调:http: //cutting.io/posts/packaging-ios-apps-from-the-command-line/

回答by martinmose

I had EXACTLY the same problem, as you have. We are building our iOS app on Jenkins, so we couldn't manually set "Code Signing Resource Rules Path".

我和你有完全一样的问题。我们正在 Jenkins 上构建我们的 iOS 应用程序,因此我们无法手动设置“代码签名资源规则路径”。

I have wrote a small NodeJS file which does the job for me (see the code below).

我写了一个小的 NodeJS 文件,它为我完成了这项工作(见下面的代码)

The script use a nice NodeJS package called xcodewhich helps me with the parsing of the xcode.xcodeproj file.

该脚本使用了一个名为xcode的不错的 NodeJS 包,它帮助我解析 xcode.xcodeproj 文件。

I don't know if you are using Cordova/Phonegap or what you are using, but if you are can just copy the code and make a Cordova hook. If not I'm sure you can execute the file from Jenkins, with some small changes.

我不知道你是在使用 Cordova/Phonegap 还是你在使用什么,但如果你是,你可以复制代码并制作一个 Cordova 钩子。如果不是,我确定您可以从 Jenkins 执行该文件,并进行一些小的更改。

Anyways, I hope this script will help you:

无论如何,我希望这个脚本能帮助你:

#!/usr/bin/env node

var CODE_SIGN_RESOURCE_RULES_PATH = '"$(SDKROOT)/ResourceRules.plist"';

var fs = require("fs");
var path = require("path");
var xcode = require('xcode');
var projectRoot = process.argv[2];

function getProjectName(protoPath) {
    var cordovaConfigPath = path.join(protoPath, 'www', 'config.xml');
    var content = fs.readFileSync(cordovaConfigPath, 'utf-8');

    return /<name>([\s\S]*)<\/name>/mi.exec(content)[1].trim();
}

function run(projectRoot) {
    var projectName = getProjectName(projectRoot);
    var xcodeProjectName = projectName + '.xcodeproj';
    var xcodeProjectPath = path.join(projectRoot, 'platforms', 'ios', xcodeProjectName, 'project.pbxproj');
    var xcodeProject;

    if (!fs.existsSync(xcodeProjectPath)) {
        return;
    }

    xcodeProject = xcode.project(xcodeProjectPath);

    console.log('Setting Code Sign Resource Rules Path for ' + projectName + ' to: [' + CODE_SIGN_RESOURCE_RULES_PATH + '] ...');
    xcodeProject.parse(function(error){
        if(error){
            console.log('An error occured during parsing of [' + xcodeProjectPath + ']: ' + JSON.stringify(error));
        }else{
            var configurations = nonComments(xcodeProject.pbxXCBuildConfigurationSection());
            for (config in configurations) {
                var buildSettings = configurations[config].buildSettings;

                buildSettings['CODE_SIGN_RESOURCE_RULES_PATH'] = CODE_SIGN_RESOURCE_RULES_PATH;
            }

            fs.writeFileSync(xcodeProjectPath, xcodeProject.writeSync(), 'utf-8');

            console.log('[' + xcodeProjectPath + '] now has Code Signing Resource Rules Path set to:[' + CODE_SIGN_RESOURCE_RULES_PATH + '] ...');
        }
    });
}

var COMMENT_KEY = /_comment$/;
function nonComments(obj) {
    var keys = Object.keys(obj),
        newObj = {}, i = 0;

    for (i; i < keys.length; i++) {
        if (!COMMENT_KEY.test(keys[i])) {
            newObj[keys[i]] = obj[keys[i]];
        }
    }

    return newObj;
}

run(projectRoot);

回答by Kaan Yy

We are using Unity + Jenkins for auto builds.

我们正在使用 Unity + Jenkins 进行自动构建。

You can achieve with post process cs scripts; however; for quick (and dirty fix) you can apply following bash command after Unity but before xcode:

您可以使用后期处理 cs 脚本来实现;然而; 为了快速(和肮脏的修复),您可以在 Unity 之后但在 xcode 之前应用以下 bash 命令:

sed -i '' 's/CONFIGURATION_BUILD_DIR/CODE_SIGN_RESOURCE_RULES_PATH = "$(SDKROOT)\/ResourceRules\.plist";\'$'\n                CONFIGURATION_BUILD_DIR/g' /Users/admin/Jenkins/workspace/PROJECTNAME/Build/PROJECTNAME/Unity-iPhone.xcodeproj/project.pbxproj