简体   繁体   English

使用 Xcode 的“新构建系统”写入构建目录 info.plist

[英]Writing to build directory info.plist using Xcode's "New Build System"

Before using the "New Build System", we had a build phase script like this:在使用“新构建系统”之前,我们有一个像这样的构建阶段脚本:

infoplist="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
builddate=`date`
/usr/libexec/PlistBuddy -c "Set :BuildDateString $builddate" "${infoplist}"

The point of this way to write to the plist at runtime without dirtying the project and having to stash the changes.这种在运行时写入 plist 的方式的要点,而不会弄脏项目并且不必隐藏更改。 This still works well and perfectly when using the "Legacy Build System".在使用“旧版构建系统”时,这仍然可以很好地工作。

On the "New Build System", this script does not work.在“新构建系统”上,此脚本不起作用。 The directory variables and writing to the plist will works but the changes are somehow overwritten.目录变量和写入 plist 将起作用,但更改以某种方式被覆盖。

Is there a way to write to a built plist via the build phase script?有没有办法通过构建阶段脚本写入构建的 plist? If not, is there a way to achieve the goal of writing information only when the application runs without dirtying the local repo.如果没有,有没有办法实现仅在应用程序运行时写入信息而不弄脏本地存储库的目标。

As @rpstw points out, any custom build steps will run before the New Build System's Process .../Info.plist step.正如@rpstw 指出的那样,任何自定义构建步骤都将新构建系统的Process .../Info.plist步骤之前运行。

  • To run a shell script after Xcode finishes building, you can add it to your scheme(s) as a build post-action:要在 Xcode 完成构建后运行 shell 脚本,您可以将其作为构建后操作添加到您的方案中:

Product > Scheme > Edit Scheme... > Build > Post-actions

在此处输入图片说明

  • If you're going to reference any build system environment variables (eg BUILT_PRODUCTS_DIR or INFOPLIST_PATH ), make sure you change the Provide build settings from selection.如果您要引用任何构建系统环境变量(例如BUILT_PRODUCTS_DIRINFOPLIST_PATH ),请确保选择中更改提供构建设置

  • Add your shell script, but remember that if you edit any file in the app bundle (ie Info.plist ), you'll need to re-sign the app.添加您的 shell 脚本,但请记住,如果您编辑应用程序包中的任何文件(即Info.plist ),您将需要重新签署应用程序。 Add this to your post build step:将此添加到您的后期构建步骤:

export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
/usr/bin/codesign --force --sign - --entitlements "${TARGET_TEMP_DIR}/${FULL_PRODUCT_NAME}.xcent" --timestamp=none "${CODESIGNING_FOLDER_PATH}"

在此处输入图片说明

It looks like that sometimes, under the "New Build System", the Process Info.plist step is after all the Run custom scripts step.看起来有时,在“新构建系统”下, Process Info.plist步骤毕竟是Run custom scripts步骤。

So I use script to generate another custom.plist at the bundle所以我使用脚本在包中生成另一个custom.plist

#!/usr/bin/env ruby
require 'cfpropertylist'
require 'pathname'

build_info = {
    'Time' => Time.now.to_s,
    'CommitHash' => `git log --pretty="%h" | head -n1`.rstrip
}

plist = CFPropertyList::List.new
plist.value = CFPropertyList.guess(build_info)
plist_path = Pathname.new(ENV['BUILT_PRODUCTS_DIR']) /  ENV['CONTENTS_FOLDER_PATH'] / 'build_info.plist'
plist.save(plist_path, CFPropertyList::List::FORMAT_XML)

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

相关问题 Copy Bundle Resources 构建阶段包含此目标的 Info.plist 文件 'Info.plist' in xcode 6? - The Copy Bundle Resources build phase contains this target's Info.plist file 'Info.plist' in xcode 6? 如何在Info.plist中读取自定义键的值并在Xcode的构建设置中使用它? - How can I read a custom key's value in Info.plist and use it in Xcode's build settings? Xcode 6构建因缺少Info.plist文件而失败 - Xcode 6 build failing with missing Info.plist file 如何使用replaceregexp从ANT脚本更新Xcode项目info.plist构建版本 - How to update Xcode project info.plist build version from ANT script using replaceregexp 无需提供新版本即可更改info.plist值的方法 - Way to change info.plist value without giving new build 使用单个Info.plist构建单独的iPhone和iPad应用 - Using single Info.plist to build separate iPhone and iPad apps 使用Xcode的预处理来设置info.plist键和值 - Using Xcode's preprocessing to set info.plist keys and values 离子构建失败Info.plist未找到 - Ionic build fails Info.plist not found 添加iOS Charts Framework后无法构建Xcode Project(找不到Info.plist) - Xcode Project cannot build after adding iOS Charts Framework (Info.plist not found) Xcode:从“构建设置”中误删除了info.plist和prefix.pch - Xcode: Accidentally deleted info.plist and prefix.pch from 'build settings'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM