xcode 如何使用 xcodebuild 命令行使用 Xcode9 进行自动签名?

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

How to use xcodebuild command line to do automatic signing with Xcode9?

iosxcodeprovisioning-profilexcodebuildxcode9

提问by programmer_of_the_galaxies

I have Xcode9 installed on my OSX machine. I am using xcodebuildcommand line to sign my app which of course uses the latest Xcode9 based commaline tools.

我的 OSX 机器上安装了 Xcode9。我正在使用xcodebuild命令行来签署我的应用程序,这当然使用最新的基于 Xcode9 的逗号工具。

Following is the way I am trying to sign my app:

以下是我尝试签署我的应用程序的方式:

xcodebuild -project "MyProject.xcodeproj" -scheme "MyProject" -sdk "iphoneos" -configuration Release PROVISIONING_PROFILE="MyProject_ProvisioningProfile" DEVELOPEMENT_TEAM="MY_TEAM_ID"

But, it gives the following error.

但是,它给出了以下错误。

Code Signing Error: Provisioning profile "profile_name" is Xcode managed, but signing settings require a manually managed profile.
Code Signing Error: Code signing is required for product type 'Application' in SDK 'iOS 11.0'

But when I build using Xcode9 UI IDE selecting "Automatic signing", it works. I want to replicate the same using xcodebuildcommand line.

但是当我使用 Xcode9 UI IDE 选择“自动签名”构建时,它可以工作。我想使用xcodebuild命令行复制相同的内容。

I read that with Xcode 9 installed, we can do automatic signing from command line just like Xcode UI does.

我读到安装了 Xcode 9 后,我们可以像 Xcode UI 一样从命令行进行自动签名。

Question:
How should I modify xcodebuildcommand to do automatic signing just the way it is done on Xcode UI based tool?

问题:
我应该如何修改xcodebuild命令以按照在基于 Xcode UI 的工具上完成的方式进行自动签名?

I understand from official documentationthat one should prefer automatic signing. But how to do this with xcodebuildcommand line

我从官方文档中了解到,人们应该更喜欢自动签名。但是如何使用xcodebuild命令行执行此操作

Looking at this discussion, I tried switching it on the project.pbxprojfile using sed.

看着这个讨论,我尝试project.pbxproj使用sed.

sed -i '' 's/ProvisioningStyle = Manual;/ProvisioningStyle = Automatic;/' <ProjectName>.xcodeproj/project.pbxproj

But that didn't help

但这没有帮助

回答by Adam

Based on the error it appears you haven't enabled automatic signing in your project settings. There is no way to perform a one-off automatically-signed build from the command line when your project is configured for manual signing.

根据错误,您似乎没有在项目设置中启用自动签名。当您的项目配置为手动签名时,无法从命令行执行一次性自动签名构建。

With your project open in XCode select your root project in the Project Navigator on the left. Click the Target you wish to configure. Click the General tab. In the Signing section tick the "Automatically manage signing" checkbox. You also have to pick a development team. If you have multiple targets you may need to repeat these steps for all of them.

在 XCode 中打开您的项目后,在左侧的项目导航器中选择您的根项目。单击要配置的目标。单击常规选项卡。在签名部分勾选“自动管理签名”复选框。您还必须选择一个开发团队。如果您有多个目标,则可能需要对所有目标重复这些步骤。

Once you've done this XCode will automatically create, manage, and use team provisioning profiles. -allowProvisioningUpdatestells xcodebuildto do the same provisioning management that the XCode IDE is doing implicitly. Note that these profiles are not visible to you in the development portal.

完成此操作后,XCode 将自动创建、管理和使用团队配置文件。-allowProvisioningUpdates告诉xcodebuild执行与 XCode IDE 隐式执行相同的配置管理。请注意,您在开发门户中看不到这些配置文件。

You will run into a new provisioning error because you're specifying a provisioning profile. Automatic signing means you have to let XCode figure out everything. It complains if you try to tell it anything other than your development team. In your case you're telling xcodebuildwhich provisioning profile to use. But XCode insists on using the team provisioning profile(s) it manages and will throw up its hands in disgust if told otherwise:

您将遇到新的配置错误,因为您正在指定配置文件。自动签名意味着您必须让 XCode 弄清楚一切。如果你试图告诉它除了你的开发团队之外的任何事情,它会抱怨。在您的情况下,您是在告诉xcodebuild要使用哪个配置文件。但是 XCode 坚持使用它管理的团队配置文件,如果另有说明,将会厌恶地举手:

Code Signing Error: MyProject has conflicting provisioning settings. MyProject is automatically signed, but provisioning profile MyProject_ProvisioningProfile has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor, or switch to manual signing in the project editor.

The xcodebuildcommand we use for building with automatic provisioning looks like this:

xcodebuild我们用于构建自动配置的命令如下所示:

xcodebuild -configuration Release PLATFORM_NAME=iphoneos SDKROOT=iphoneos11.2 -project myproject.xcodeproj -allowProvisioningUpdates build

Based on that give this version of your command a try after you've enabled automatic signing in the project settings:

在此基础上,在项目设置中启用自动签名后,尝试使用此版本的命令:

xcodebuild -project "MyProject.xcodeproj" -scheme "MyProject" -sdk "iphoneos" -configuration Release DEVELOPEMENT_TEAM="MY_TEAM_ID"

One other thing to be aware of is that xcodebuildwill not update the managed provisioning profiles unless it cannot find them locally. On our CI servers we have a pre-build step that deletes them to force a refresh. XCode stores its managed provisioning profiles under ~/Library/MobileDevice/Provisioning\ Profiles.

要注意的另一件事是,xcodebuild除非在本地找不到托管配置文件,否则不会更新托管配置文件。在我们的 CI 服务器上,我们有一个预构建步骤,可以删除它们以强制刷新。XCode 将其托管配置文件存储在~/Library/MobileDevice/Provisioning\ Profiles.

回答by torap

Try adding export_xcargs: "-allowProvisioningUpdates", that will work

尝试添加export_xcargs: "-allowProvisioningUpdates",这会起作用

回答by Igor Kotkovets

On my project I use gradle-xcodePluginutility. It's not typical for iOS development to use Gradle :), but it's quite good instrument. It's a wrapper under xcodebuildtool. It's very easy to setup, configuration is in the build.gradlefile. It's enough documentation on GitHub to setup it. It does automatically building, exporting, delivering to TestFlight beta testing and more. I use it for a year.

在我的项目中,我使用gradle-xcodePlugin实用程序。使用 Gradle 对 iOS 开发来说并不常见:),但它是一个非常好的工具。它是xcodebuild工具下的包装器。设置非常简单,配置在build.gradle文件中。GitHub 上有足够的文档来设置它。它会自动构建、导出、交付给 TestFlight beta 测试等等。我用了一年。

You will forget syntax of xcodebuild -project ...for always. Just keep this plugin up to date.

你会忘记xcodebuild -project ...for always 的语法。只要保持这个插件是最新的。

I run building by executing $ ./gradlew xcodebuild

我通过执行来运行构建 $ ./gradlew xcodebuild

Maybe this tool help you to avoid spending time for solving issues with each Xcode update, as it did for me ;)

也许这个工具可以帮助你避免花费时间来解决每次 Xcode 更新的问题,就像对我一样;)

回答by Om Prakash

xcodebuild -project -scheme WebDriverAgentRunner -destination id=7b7ba65e1f3bbb87460aef17866efe6f6e473c24 -configuration Release -xcconfig -allowProvisioningUpdates build-for-testing

xcodebuild -project -scheme WebDriverAgentRunner -destination id=7b7ba65e1f3bbb87460aef17866efe6f6e473c24 -configuration Release -xcconfig -allowProvisioningUpdates build-for-testing

XCODE CONFIG FILE: Create a file that contains following details

XCODE CONFIG FILE:创建一个包含以下详细信息的文件

  • DEVELOPMENT_TEAM = "MY_TEAM_ID"
  • CODE_SIGN_IDENTITY = iPhone Developer
  • DEVELOPMENT_TEAM = "MY_TEAM_ID"
  • CODE_SIGN_IDENTITY = iPhone 开发者