添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

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"
                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
– Xiao
                Apr 1, 2014 at 12:37
                or use /usr/libexec/PlistBuddy -c "Print UUID" /dev/stdin <<< $(security cms -D -i pathtofile.provision)
– Szymon Fortuna
                Jan 18, 2015 at 16:27

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).

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.

@MishaKarpenko, the github link you shared is expired. can you share me the script again ? Thanks – gstream Aug 16, 2017 at 8:42 @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? – Misha Karpenko Aug 16, 2017 at 8:49 @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 ? – gstream Aug 16, 2017 at 9:03

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"
                Doesn't work for me. It just takes whatever is the default profile for the target/scheme.
– Dmytro
                Feb 14, 2012 at 19:33
                Try to add PROVISIONING_PROFILE="$provision". It works fine for me when both (CODE_SIGN_IDENTITY & PROVISIONING_PROFILE are specified.
– Vitaliy Grigoruk
                Feb 14, 2012 at 19:39
                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/Provisioning 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
                Feb 22, 2012 at 17:38

I found a great workaround for building with jenkins.

Firstly, before setting up a job, download a jenkins plugin called:

Parameterized Trigger Plugin

https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin

Once you do that, create your job and while creating the job, select the

'This build is parameterized' checkbox

Create a String Parameter. I call mine CODE_SIGN_IDENTITY.

So the name field in the String Parameter should be:

Name: CODE_SIGN_IDENTITY

Default Value: iPhone Developer: XXX XXXXX

Description: Whatever you want to put there

Then in your Xcode Plugin, find the 'Custom xcodebuild arguments' field.

In the Custom xcodebuild arguments field, place the following value:

CODE_SIGN_IDENTITY=${CODE_SIGN_IDENTITY}

Finish setting up your job and you should be all set!

This will bypass the white space issue. The plugin is a life saver as it works wonderfully and you can customize your build with other parameters.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.