Use xcodebuild (Xcode 8) and automatic signing in CI (Travis/Jenkins) environments

pablobart :

With the release of Xcode 8, Apple introduced a new way of managing the signing configuration. Now you have two options Manual and Automatic.

According to the WWDC 2016 Session about Code signing (WWDC 2016 - 401 - What's new in Xcode app signing), when you select Automatic signing, Xcode is going to:

  • Create signing certificates
  • Create and update App IDs
  • Create and update provisioning profiles

But according to what Apple says in that session, the Automatic Signing is going to use Development signing and will be limited to Xcode-created provisioning profiles.

The issue comes when you try to use Automatic Signing on a CI environment (like Travis CI or Jenkins). I'm not able to figure out an easy way to keep using Automatic and sign for Distribution (as Xcode forces you to use Development and Xcode-created provisioning profiles).

The new "Xcode-created provisioning profiles" do not show up in the developer portal, although I can find then in my machine... should I move those profiles to the CI machine, build for Development and export for Distribution? Is there a way to override the Automatic Signing using xcodebuild?

pablobart :

After trying a few options, these are the solutions that I was able to use on my CI server:

  • Include the Developer certificate and private key as well as the auto generated provisioning profiles in the CI environment:

Using Automatic signing forces you to use a Developer certificate and auto-generated provisioning profiles. One option is to export your development certificate and private key (Application -> Utilities -> Keychain Access) and the auto-generated provisioning profiles to the CI machine. A way to locate the auto-generated provisioning profiles is to navigate to ~/Library/MobileDevice/Provisioning\ Profiles/, move all files to a backup folder, open Xcode and archive the project. Xcode will create auto-generated development provisioning profiles and will copy them to the Provisioning Profiles folder.

xcodebuild archive ... will create a .xcarchive signed for Development. xcodebuild -exportArchive ... can then resign the build for Distribution

  • Replace 'Automatic' with 'Manual' when building on a CI environment

Before calling xcodebuild a workaround is to replace all instances of ProvisioningStyle = Automatic with ProvisioningStyle = Manual in the project file. sed can be used for a simple find an replace in the pbxproj file:

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

@thelvis also created a Ruby script to do this using the xcodeproj gem. The script gives you a better control over what is changed.

xcodebuild will then use the code signing identity (CODE_SIGN_IDENTITY) set in the project, as well as the provisioning profiles (PROVISIONING_PROFILE_SPECIFIER). Those settings can also be provided as parameters to xcodebuild and they will override the code signing identity and/or provisioning profile set in the project.

EDIT: with Xcode 9, xcodebuild has a new build settings parameter CODE_SIGN_STYLE to select between Automatic and Manual so there's no need to find and replace instances of automatic with manual in the project file, more info in WWDC 2017 Session 403 What's New in Signing for Xcode and Xcode Server

  • Switch to manual signing

Manual signing will provide total control over the code signing identities and provisioning profiles being used. It's probably the cleanest solution, but with the downside of losing all the benefits of Automatic signing.

To learn more about code signing with Xcode 8 I really recommend this article as well as the WWDC2016 session 401 - What's new in Xcode app signing

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Can xcodebuild manage automatic signing?

Xcode 8/xcodebuild: how to trigger 'Update Signing' from command line?

Automatic signing for iOS app in VSTS Xcode Task

Automatic signing is unable to resolve an issue on xcode

Change the signing team in Xcode 8

ssh xcodebuild no signing certificate

Xcodebuild- Travis CI can't archive a project that uses cocoapods due to code signing error?

CMake and Code Signing in XCode 8 for iOS projects

Code signing issue in Xcode version 8

How to build an IPA without signing in Xcode 8

How to get a distribution app when using xcodebuild -exportArchive (Xcode8.3, Auto Signing)?

Archiving app using Xcode10.1 Automatic Automatic signing is unable to resolve an issue with " " target's entitlements

Where is the "enable automatic sigin" on Xcode 8?

Xcode 8 Provisioning Profile only contains "Automatic"

Xcode 8 automatic build when any change

Self / automatic / no signing state

iTunes Connect submission code signing entitlements error Xcode 8

Multiple Environments in Travis CI

Xcode: No signing certificate

How can I use the legacy build system with Xcode 10's `xcodebuild`?

Use Xcode 8 with iOS 11

Use Swift 2.2 in Xcode 8?

xCode 6 how to fix "Use of undeclared identifier" for automatic property synthesis?

Xcode 8 shows error that provisioning profile doesn't include signing certificate

None of your accounts are a member, code signing errors after upgrading to Xcode 8

Invalid Code Signing Entitlements for iCloud, Core Data and Xcode 6.01 with iOS 8

Xcode8/SDK iOS 10.2 device, profiles and code signing problems

Is Xcode 8 developer signing broken today (1/28/2017 12:40 PM US EST)?

Ionic 4 with capacitor: xcodebuild fails with manual signing process