xcode xcodebuild 可以管理自动签名吗?

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

Can xcodebuild manage automatic signing?

iosxcodecordovaxcode8

提问by JW.

SUMMARY:

概括:

If you open a project in Xcode 8 with "Automatically manage signing" enabled and a new bundle ID, it will automatically create and download a provisioning profile for it. But how can I make the same thing happen with xcodebuild, so I can use it on a remote build server?

如果您在 Xcode 8 中打开一个项目并启用“自动管理签名”和一个新的包 ID,它会自动为它创建和下载一个配置文件。但是我怎样才能用 实现同样的事情xcodebuild,以便我可以在远程构建服务器上使用它?

DETAILS:

细节:

I'm trying to build a Cordova app on a Mac. Cordova configures the Xcode project to use "Automatically manage signing", so I'm trying to use that.

我正在尝试在 Mac 上构建 Cordova 应用程序。Cordova 将 Xcode 项目配置为使用“自动管理签名”,所以我正在尝试使用它。

I change the bundle ID often, so I want Cordova to be able to build it with a new bundle ID, that hasn't been used before.

我经常更改包 ID,因此我希望 Cordova 能够使用以前未使用过的新包 ID 来构建它。

But when I run cordova build ios --release --device --buildConfig build.json, I get a return code 65 and the following error:

但是当我运行时cordova build ios --release --device --buildConfig build.json,我得到一个返回码 65 和以下错误:

Check dependencies
No profiles for 'com.my.bundle.id' were found:  Xcode couldn't find a provisioning profile matching 'com.my.bundle.id'.
Code signing is required for product type 'Application' in SDK 'iOS 10.3'

** ARCHIVE FAILED **

The following build commands failed:
    Check dependencies
(1 failure)
Error: Error code 65 for command: xcodebuild with args: -xcconfig,/cordova-project/platforms/ios/cordova/build-debug.xcconfig,-workspace,MyApp.xcworkspace,-scheme,MyApp,-configuration,Debug,-destination,generic/platform=iOS,-archivePath,MyApp.xcarchive,archive,CONFIGURATION_BUILD_DIR=/cordova-project/platforms/ios/build/device,SHARED_PRECOMPS_DIR=/cordova-project/platforms/ios/build/sharedpch

(I can manually run that xcodebuild command and get the same error, so it's probably not a Cordova issue.)

(我可以手动运行该 xcodebuild 命令并得到相同的错误,所以这可能不是 Cordova 问题。)

My build.json file looks like this:

我的 build.json 文件如下所示:

{
    "ios": {
        "debug": {
            "codeSignIdentity": "iPhone Developer",
            "developmentTeam": "MY_TEAM_ID",
            "packageType": "development"
        },
        "release": {
            "codeSignIdentity": "iPhone Developer",
            "developmentTeam": "MY_TEAM_ID",
            "packageType": "enterprise"
        }
    }
}

I'm using cordova 7.0.1, cordova-ios 4.4.0, Xcode 8.3.3, and MacOS 10.12.5. I have an Apple Enterprise account.

我使用的是cordova 7.0.1、cordova-ios 4.4.0、Xcode 8.3.3和MacOS 10.12.5。我有一个 Apple Enterprise 帐户。

WHAT I TRIED:

我试过的:

If I open the generated project in Xcode, it fixes the automatic signing, and from then on I can run cordova successfully with that bundle ID. But if I try to run it with a different bundle ID, it will fail again.

如果我在 Xcode 中打开生成的项目,它会修复自动签名,然后我可以使用该包 ID 成功运行cordova。但是如果我尝试使用不同的包 ID 运行它,它将再次失败。

I tried using security unlock-keychain ~/Library/Keychains/login.keychain-dbfirst, since that's worked in the past, but it didn't help.

我先尝试使用security unlock-keychain ~/Library/Keychains/login.keychain-db,因为这在过去有效,但没有帮助。

I also tried opening my private signing key in Keychain Access and setting it to "Allow all applications to access this item", without any luck.

我还尝试在 Keychain Access 中打开我的私人签名密钥并将其设置为“允许所有应用程序访问此项目”,但没有任何运气。

I get the same error regardless of whether I pass --debugor --releaseto cordova.

无论我是通过--debug还是--release科尔多瓦,我都会遇到同样的错误。

采纳答案by itai195

This isn't directly supported in Xcode 8. In Xcode 9, however, you can pass -allowProvisioningUpdates to xcodebuild and automatic signing will work just as in the Xcode UI, without needing any additional tools.

这在 Xcode 8 中不直接支持。但是,在 Xcode 9 中,您可以将 -allowProvisioningUpdates 传递给 xcodebuild,自动签名将像在 Xcode UI 中一样工作,无需任何其他工具。

e.g. cordova run ios --buildFlag="-allowProvisioningUpdates"

例如 cordova run ios --buildFlag="-allowProvisioningUpdates"

回答by mommcilo

Answer is yes. What I used and what I can confirm is working and it is great:

答案是肯定的。我使用的和我可以确认的工作是有效的,它很棒:

https://fastlane.tools/

https://fastlane.tools/

You can set up everything to be automatic:

您可以将一切设置为自动:

  1. Signing keys
  2. Taking screenshots
  3. Uploading on iTunes
  1. 签名密钥
  2. 截屏
  3. 在 iTunes 上上传

and many other things

和许多其他事情

In background it is using xcodebuild command line. I was skeptic that something like this is possible, but just set up, start and enjoy.

在后台它使用 xcodebuild 命令行。我怀疑这样的事情是可能的,但只是设置,开始并享受。

回答by S. Matsepura

For Automatically manage signingyou can use Fastlane. It's easy to install and setup.

因为Automatically manage signing你可以使用Fastlane。安装和设置很容易。

For using it on a remote build server - you can use Jenkins.

要在远程构建服务器上使用它 - 您可以使用Jenkins

Here example.You need to setup Jenkinswith Fastlaneto your remote machine. Than Jenkinswill check your repository threador just by you command to it. After it Jenkinsrun Fastlaneon remote build server. And Fastlanewill create all certificate and other setup that you write in Fastfile.

这里的例子。您需要设置JenkinsFastlane您的远程计算机。比Jenkins将检查你的repository thread或只是由你命令它。在远程构建服务器上Jenkins运行之后Fastlane。并且Fastlane将创建的所有证书和其他设置,你写Fastfile

If you have only one deploy certificate, you can use Fastlaneservice called Match

如果您只有一个部署证书,则可以使用Fastlane名为的服务Match

Easily sync your certificates and profiles across your team using Git

使用 Git 在整个团队中轻松同步您的证书和配置文件

or just send and setup it locally.

或者只是在本地发送和设置它。

Hope it helps you, good luck!

希望能帮到你,祝你好运!

Here example for beta deploy(for me work with Xcode 9):

这里的例子beta deploy(对我来说Xcode 9):

 desc "Build devFoo and upload it to Fabric"
      lane :uploadToFabric do
        cocoapods
        cert(
        development: true,
        output_path: "./fastlane"
        )
        sigh(
        development: true,
        output_path: "./fastlane"
        )
        clear_derived_data
        gym(
        scheme: "Foo",
        configuration: "Debug",
        clean: true,
        output_directory: "./fastlane",
        )
        crashlytics(
        api_token: "foofoofoofoo",
        build_secret: "foofoofoofoo",
        emails: ["[email protected]"],
        notifications: true
        )
        slack(
        message: "New build for test successfully deployed in Fabric",
        success: true
        )
      end

Here example for release deploy:

以下是发布部署示例:

desc "Build and upload it to the AppStore and TestFlight"
  lane :uploadToAppStore do
    cocoapods

    cert(
    development: false,
    output_path: "./fastlane"
    )
    sigh(
    development: false,
    app_identifier: "foofoo",
    output_path: "./fastlane"
    )
    clear_derived_data
    gym(
    scheme: "Foo",
    configuration: "Release",
    clean: false,
    output_directory: "./fastlane",
    )
    deliver(
    force: true,
    app_identifier: "foo",
    skip_metadata: true,
    skip_screenshots: true,
    submit_for_review: false,
    skip_binary_upload: false
    )
    slack(
    message: "New build successfully deployed to AppStore",
    success: true
    )
    upload_symbols_to_crashlytics(dsym_path: "./fastlane/foo.app.dSYM.zip")
    slack(
    message: "dSYM symbolication files uploaded to Crashlytics",
    success: true
    )

回答by Fares Ben Hamouda

You can do it using fastlane.

您可以使用 fastlane 来完成。

https://fastlane.tools/

https://fastlane.tools/

cert: Fetch or generate the latest available code signing identity

cert:获取或生成最新的可用代码签名身份

sigh: Generates a provisioning profile. Stores the profile in the current folder

叹息:生成配置文件。将配置文件存储在当前文件夹中

ps : If you are running it from a CI server (for example jenkins) you need then to unlock login keychain :

ps:如果您从 CI 服务器(例如 jenkins)运行它,则需要解锁登录钥匙串:

security unlock-keychain -p PASSWORD /Users/YOUR-USER/Library/Keychains/login.keychain

Example within the fastfile :

fastfile 中的示例:

cert(
  development: true,
)

sigh(
  development: true,
  app_identifier: "YOUR_APP_IDENTIFIER"
)

Here's an example of a basic Fastfile :

这是一个基本的 Fastfile 示例:

fastlane_version "2.27.0"
default_platform :ios

platform :ios do

lane :beta do
   cert
   sigh
   gym
end

error do |lane, exception|
  puts "Got an error! #{exception.error_info.to_s}"
end

end

回答by Gandhi

As far as my understanding and recent readings, the answer to OP's question:

就我的理解和最近的阅读而言,OP 问题的答案是:

"Can xcodebuild manage automatic signing?" is "YES" but not as per the OP's expectations in lines of "when you haven't created the app ID or provisioning profile yet, and you want to create it automatically the way Xcode does"

xcodebuild 可以管理自动签名吗?” 是“是”,但不符合 OP 的预期,例如“当您还没有创建应用程序 ID 或配置文件,并且您想像 Xcode 那样自动创建它时”

As per this informative blogon xcode8 and automatic code signing, it clearly states that :

根据这篇关于 xcode8 和自动代码签名的信息性博客,它明确指出:

"If you want to create for example an App Store signed IPA, on the Mac you have to have both a Wildcard, Team / Development AND the App Store distribution certificates and provisioning profiles!"

“例如,如果您想创建 App Store 签名的 IPA,在 Mac 上您必须同时拥有通配符、团队/开发和 App Store 分发证书和配置文件!”

Hence, the app ID and provisioning profile wont be auto created. Fastlane may be a workaround to this problem but i guess that is not the OP's expectation. Hope it makes sense.

因此,不会自动创建应用程序 ID 和配置文件。Fastlane 可能是解决此问题的方法,但我想这不是 OP 的期望。希望这是有道理的。

回答by Vahan Babayan

There is no way to manage signing automatically using xcodebuild. You must either use third parties like Fastlaneas mentioned before or use manual code signing as mentioned here.

无法使用xcodebuild. 您必须使用Fastlane前面提到的第三方或使用此处提到的手动代码签名。

回答by sleepwalkerfx

As some other answers have already mentioned, what you are looking for is a release automation tool called Fastlane. https://fastlane.tools/

正如其他一些答案已经提到的,您正在寻找的是一个名为 Fastlane 的发布自动化工具。https://fastlane.tools/

If you are not familiar with it, I believe best place to get started would be raywenderlich's fastlane tutorial.

如果您不熟悉它,我相信最好的入门地点是 raywenderlich 的 fastlane 教程。

https://www.raywenderlich.com/136168/fastlane-tutorial-getting-started-2

https://www.raywenderlich.com/136168/fastlane-tutorial-getting-started-2

回答by Hashmat Khalil

Notice: This answer assumes that bundle ID and provisioning profiles are created manually. Only build process can be automated using this method.

注意:此答案假定包 ID 和配置文件是手动创建的。只有构建过程可以使用这种方法自动化。

Yes that is possible even without using third party tools. you should be comfortable using script file or a make file. I'm using 2 lines of code in a makefile on Mac Mini at work. And that gives us either ad-hocor appstoreversion ready for upload according to our configuration.

是的,即使不使用第三方工具也是可能的。您应该习惯于使用脚本文件或 make 文件。我在工作时在 Mac Mini 上的 makefile 中使用了 2 行代码。这给了我们无论是ad-hocappstore版本准备上传根据我们的配置。

  1. make sure your project has enabled automatic configuration.
  2. make sure on your remote mac that all singing certificates and provisioning are downloaded. for this case, I always, for the first building, open Xcode and build & export on my remote machine. If that works then nothing is missing. But make sure that you always allow access to the singing certificate. Xcode also asks this for the first the build. Otherwise a popup will show up on your remote server and waits till someone allows access to the signing certificate.
  3. you need a plist file:
  1. 确保您的项目已启用自动配置。
  2. 确保在您的远程 mac 上下载了所有歌唱证书和配置。对于这种情况,我总是在第一次构建时打开 Xcode 并在我的远程机器上构建和导出。如果这有效,那么什么都没有丢失。但请确保您始终允许访问歌唱证书。Xcode 也会在第一次构建时询问这个。否则,您的远程服务器上将显示一个弹出窗口,并等待有人允许访问签名证书。
  3. 你需要一个 plist 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>  
  <key>teamID</key>  
  <string>MY_TEAM_ID_XXYY</string> //put your iPhone distribution team ID. in my case developer team ID is different than my distribution team ID. just wondering.
  <key>method</key>  
  <string>app-store</string> // for appstore upload or use <string>ad-hoc</string> for ad-hoc  
  <key>uploadSymbols</key>  
  <true/>  
  <key>uploadBitcode</key>  
  <true/>  
</dict>  
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>  
  <key>teamID</key>  
  <string>MY_TEAM_ID_XXYY</string> //put your iPhone distribution team ID. in my case developer team ID is different than my distribution team ID. just wondering.
  <key>method</key>  
  <string>app-store</string> // for appstore upload or use <string>ad-hoc</string> for ad-hoc  
  <key>uploadSymbols</key>  
  <true/>  
  <key>uploadBitcode</key>  
  <true/>  
</dict>  
</plist>

You should save plist configuration somewhere accessible, e.g., as options.plist just a reminder: make sure that you have your ad-hoc/distribution provisioning profile on your remote Mac.

您应该将 plist 配置保存在可访问的地方,例如,作为 options.plist 只是一个提醒:确保您的远程 Mac 上有您的临时/分发配置文件。

  1. xcodebuildwill create an archive then we can export .app. In your make file or script file use these lines:
  1. xcodebuild将创建一个存档然后我们可以导出 .app。在您的 make 文件或脚本文件中,使用以下几行:

4.1. First we create the archive file.

4.1. 首先我们创建存档文件。

xcodebuild archive -derivedDataPath build/ -project myProject.xcodeproj -scheme myScheme -archivePath build/ios/myProject.xcarchive

derivedDataPathparameter is just a folder that can be deleted later after building the app. you know how much junk is produced in derived data. projectname is your project name, and schemename is right after play|stopbutton in Xcode. You must choose an archive name and path for the next step.

derivedDataPath参数只是一个文件夹,可以在构建应用程序后删除。您知道派生数据中产生了多少垃圾。 projectname 是您的项目名称,schemenameplay|stop紧跟在 Xcode 中的按钮之后。您必须为下一步选择存档名称和路径。

4.2 After your archive has been built successfully, use this code to create the app:

4.2 成功构建存档后,使用此代码创建应用程序:

xcodebuild -exportArchive -archivePath build/ios/myProject.xcarchive -exportPath build/ios/ -exportOptionsPlist build/ios/options.plist

Here you use the archive name and path that was used in previous step. exportOptionsPlistneeds to know the path and name for your plist configuration that we created in step 3.

此处使用上一步中使用的存档名称和路径。exportOptionsPlist需要知道我们在第 3 步中创建的 plist 配置的路径和名称。

And that's it! You can run these commands in a terminal window it will build your app as well. You can put these 2 line in a script file / makefile and use variables for project name, path and options.plist, Then you can use that to build all of your apps.

就是这样!您可以在终端窗口中运行这些命令,它也将构建您的应用程序。您可以将这两行放在脚本文件/makefile 中,并使用项目名称、路径和 options.plist 变量,然后您可以使用它来构建所有应用程序。

PS: If anything is unclear please let me know and I will add more explanation.

PS:如果有什么不清楚的请告诉我,我会添加更多解释。

回答by mgarciaibanez

If you are archiving the xCode project with xcodebuild and you have xCode 9 installed you can provide the following FLAGS to the compilation command:

如果您使用 xcodebuild 归档 xCode 项目并且安装了 xCode 9,则可以向编译命令提供以下标志:

CODE_SIGN_STYLE="Manual" \
DEVELOPMENT_TEAM="" \

It will set the automatic signing to false and the development team to empty. You can set the values you need. For instance:

它会将自动签名设置为 false,并将开发团队设置为空。您可以设置您需要的值。例如:

xcodebuild \
-scheme "your_scheme" \
-sdk iphoneos \
-archivePath "/Users/youruser/Developer/Jenkins/Home/customWorkspace/folder/platforms/ios/build/device/yourproject.xcarchive" \
-configuration Release \
-allowProvisioningUpdates \
CONFIGURATION_BUILD_DIR="/Users/youruser/Developer/Jenkins/Home/customWorkspace/folder/platforms/ios/build/device" \
CODE_SIGN_IDENTITY="your code sign identity" \
PROVISIONING_PROFILE="your provisioning profile" \
CODE_SIGN_STYLE="Manual" \
DEVELOPMENT_TEAM="" \
archive

Then you can create the ipa with -exportArchive and it will create the ipa as you need

然后您可以使用 -exportArchive 创建 ipa,它将根据您的需要创建 ipa