CODE_SIGN_IDENTITY parameter for xcodebuild (Xcode 4)

43,180

Solution 1

A newer xcodebuild now allows settings to be specified. Taken from developer.apple.com:

xcodebuild [-project projectname] [-target targetname ...]
           [-configuration configurationname] [-sdk [sdkfullpath | sdkname]]
           [buildaction ...] [setting=value ...] [-userdefault=value ...]

I also found this resource for explaining the available settings

CODE_SIGN_IDENTITY (Code Signing Identity)
    Description: Identifier. Specifies the name of a code signing identity.
    Example value: iPhone Developer

However, PROVISIONING_PROFILE is missing from the index of available commands.

The command I finally used specified "CODE_SIGN_IDENTITY" & "PROVISIONING_PROFILE" settings.

xcodebuild -sdk <iphoneos> -target <target_name> -configuration <Debug> CODE_SIGN_IDENTITY="iPhone Developer: Mister Smith" PROVISIONING_PROFILE="XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX"

Solution 2

I had following problem:

Our developers used the 'iPhone Development' signing identity, but I needed to use the 'iPhone Distribution' signing identity for our automated integration system.

So I added the line:

codesign -f --sign "iPhone Distribution: XXXXXXX" ${PATH_TO_APP}

between the xcodebuild and the xcrun commands to swap the code signing identities (see the -f flag).

Solution 3

Just use CODE_SIGN_IDENTITY="iPhone Distribution:XXXXXX" with Xcode 4 (without [sdk=iphoneos*])

xcodebuild -project Project.xcodeproj -target Target -configuration Release -sdk iphoneos CODE_SIGN_IDENTITY="iPhone Distribution:XXXXXX"

Solution 4

As far as I know in Xcode 4 signing is done with xcrun tool:

/usr/bin/xcrun -sdk "iphoneos" PackageApplication -v "myapp.app" -o "myapp.ipa" --sign "iPhone Developer: XXXXX" --embed "XXXXX.mobileprovisioning"

It is a bit uncomfortable to use because you must specify both your identity and mobileprovisioning file. Especially uncomfortable if you use last one from ~/Library/MobileDevice/Provisioning Profiles/ directory because its name is changed every time provisioning profiles are updated automatically from Provisioning Portal.

Share:
43,180
Dmytro
Author by

Dmytro

iPhone/C++ engineer

Updated on July 09, 2022

Comments

  • Dmytro
    Dmytro almost 2 years

    I'm using xcodebuild utility shipped with Xcode 3 to automate my builds under Hudson. The command looks like it follows:

    xcodebuild -project Project.xcodeproj -target Target -configuration Release -sdk iphoneos CODE_SIGN_IDENTITY[sdk=iphoneos*]="iPhone Distribution:XXXXXX"
    

    I'm trying to use the same command for Xcode 4 but it seems that xcodebuild just ignores CODE_SIGN_IDENTITY parameter and signs with the provisioning profile which is selected for the target in Xcode.

    It's a quite crucial for me since I have to sign build with 3-4 different profiles. It works OK with Xcode 3 but doesn't work with Xcode 4.

    Any idea how to solve this problem?

  • Dmytro
    Dmytro about 12 years
    Doesn't work for me. It just takes whatever is the default profile for the target/scheme.
  • Vitaliy Grigoruk
    Vitaliy Grigoruk about 12 years
    Try to add PROVISIONING_PROFILE="$provision". It works fine for me when both (CODE_SIGN_IDENTITY & PROVISIONING_PROFILE are specified.
  • Dmytro
    Dmytro about 12 years
    that's my complete command xcodebuild -target Target -sdk iphoneos -configuration "Ad Hoc" "CODE_SIGN_IDENTITY[sdk=iphoneos*]==iPhone Distribution: XXX" "PROVISIONING_PROFILE=/Users/$USER/Library/MobileDevice/Prov‌​isioning Profiles/XXX.mobileprovision" When xcodebuild is trying to sign the app it takes another profile. The one which is default for this scheme /usr/bin/codesign --force --sign "iPhone Distribution: XXX1" "--resource-rules=ResourceRules.plist" --entitlements "App.xcent" "App.app" And XXX!=XXX1 unfortunately
  • Dmytro
    Dmytro about 12 years
    AFAIK to sign the app Xcode/xcodebuild uses /usr/bin/codesign application
  • Misha Karpenko
    Misha Karpenko about 12 years
    Anyway did you solve the problem? I'm building my apps with this command.
  • Xiao
    Xiao about 10 years
    The argument of PROVISIONING_PROFILE must be UUID, such like FAEB2AC2-33DB-4192-9711-06BD5ACD5ADD.You could get this UUID from iPhoneConfigUtility or just open .mobileprovision file with vim
  • Szymon Fortuna
    Szymon Fortuna over 9 years
    or use /usr/libexec/PlistBuddy -c "Print UUID" /dev/stdin <<< $(security cms -D -i pathtofile.provision)
  • serhii
    serhii over 6 years
    @MishaKarpenko, the github link you shared is expired. can you share me the script again ? Thanks
  • Misha Karpenko
    Misha Karpenko over 6 years
    @gstream79 Apologies as this project doesn't exist anymore. Are you experiencing problems with the xcrun call I've mentioned, or you're just trying to bring more convenience to your automation setup?
  • serhii
    serhii over 6 years
    @MishaKarpenko, thanks for your update. I am trying to code sign for embedded swift framework but it requires to select certain certificates. But I want to do it with "Automatically manage signing". So I need to get selected certificate identity under "Automatically manage signing" checked. Any idea how to do it ?
  • Misha Karpenko
    Misha Karpenko over 6 years
    @gstream79 Are you trying to do it in Xcode or in Terminal?
  • serhii
    serhii over 6 years
    @MishaKarpenko, I've added script in project's Build phase for it in XCode.
  • Misha Karpenko
    Misha Karpenko over 6 years
    @gstream79 Is it a 3rd party framework or the libswift one?