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

13,118

Solution 1

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.

Once you've done this XCode will automatically create, manage, and use team provisioning profiles. -allowProvisioningUpdates tells xcodebuild to 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.

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 xcodebuild which 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:

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 xcodebuild command we use for building with automatic provisioning looks like this:

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 xcodebuild will 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.

Solution 2

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

Solution 3

On my project I use gradle-xcodePlugin utility. It's not typical for iOS development to use Gradle :), but it's quite good instrument. It's a wrapper under xcodebuild tool. It's very easy to setup, configuration is in the build.gradle file. 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.

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

I run building by executing $ ./gradlew xcodebuild

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

Solution 4

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

XCODE CONFIG FILE : Create a file that contains following details

  • DEVELOPMENT_TEAM = "MY_TEAM_ID"
  • CODE_SIGN_IDENTITY = iPhone Developer
Share:
13,118
TheWaterProgrammer
Author by

TheWaterProgrammer

#include <AlwaysAStudent> int main(int argc, char *argv[]) { std::thread always_keep_learning([&] { Learn(); }); always_keep_learning.detach(); return 0; }

Updated on June 30, 2022

Comments

  • TheWaterProgrammer
    TheWaterProgrammer almost 2 years

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

    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 xcodebuild command line.

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

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

    I understand from official documentation that one should prefer automatic signing. But how to do this with xcodebuild command line

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

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

    But that didn't help