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?
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"
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.
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"
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.
Related
I trying to sign my app command line using Xcode.
Running xcodebuild command-line on MyApp.xcodeproj like so:
xcodebuild -project "MyApp.xcodeproj" -target "MyApp" -sdk "iphoneos" -configuration *Release* PROVISIONING_PROFILE="xxxx-xxxx-xxxx-xxxx" CODE_SIGN_IDENTITY="iPhone Developer: something.com (SOMEVALUE)"
Gives following error:
Check dependencies
Provisioning profile "iOS Team Provisioning Profile: *" doesn't include signing certificate "iPhone Developer: something.com (SOMEVALUE)".
Provisioning profile "iOS Team Provisioning Profile: *" is Xcode managed, but signing settings require a manually managed profile.
Code signing is required for product type 'Application' in SDK 'iOS 10.3'
** BUILD FAILED **
What is wrong ? What is missing in my xcodebuild command ?
How can I include the signing certificate that its asking about ?
What I tried from answer & comments below
As I understand, a dedicated distribution profile should be used with Release build. That is present in the system. I just need to know how to use it with xcodebuild command for manual signing if I can.
Executing security find-identity -p codesigning -v | grep "$CODE_SIGN_IDENTITY" gives a list of 5 signing identities ones of them clearly states as iPhone Distribution: My Company (SOME123ID).
*So, can I use the distribution profile with xcodebuild manual signing? If yes, How can I get the actual ID of a distribution profile to use with xcodebuild command?
Using PROVISIONING_PROFILE is deprecated since Xcode8. Try PROVISIONING_PROFILE_SPECIFIER instead. PROVISIONING_PROFILE_SPECIFIER="Human Readable Prov Profile Name"
It may also be necessary to turn off Xcode's Automatic Signing:
Xcode9: simply append CODE_SIGN_STYLE="Manual" to your xcodebuild command
Xcode8: sed -i '' 's/ProvisioningStyle = Automatic;/ProvisioningStyle = Manual;/' TestApp/TestApp.xcodeproj/project.pbxproj && xcodebuild ...
You can check your Xcode Version on the command-line with xcodebuild -version
We have been doing CI builds through Jenkins. I did not set up Jenkins so I can't answer questions about how its set up.
We are adding a WatchKit extension. We are following these steps https://developer.apple.com/library/mac/qa/qa1814/_index.html to switch from specifing the provisioning profile to switching to automatic.
The build command fails through Jenkins, but if I run the command from the command line, it works. I think both are using the same user. The distribution certificate is in the login keychain and the system keychain.
Our command is
xcodebuild -configuration Release -target "mobile" -sdk "iphoneos8.3" -scheme "mobile" clean archive
The error we get is like this for each extension and application:
Code Sign error: No code signing identities found: No valid signing identities (i.e. certificate and private key pair) matching the team ID “XXXXXXXXXX” were found.
CodeSign error: code signing is required for product type 'App Extension' in SDK 'iOS 8.3'
Any advice how to fix or troubleshoot this error?
Try moving the certificates you required in your Keychain. Move them from Login to System
Try adding Jenkins profile management plugin & adding prov and then compile using XCBuild.
When I execute the following command via Execute Shell, I am able to run xcodebuild:
security unlock-keychain -p ${OSPASSWORD} ~/Library/Keychains/login.keychain-db && xcodebuild -scheme ${XCODE_SCHEME} -sdk ${XCODE_SDK} -archivePath \"build\" -configuration Release archive
Hope it helps.
I am writing a build script for my phonegap-ios program. I am experiencing some problems during the code signing process. I use my script to build and code signing the project and generate ipa file. But the ipa failed to install to my iphone via iTunes. And I compared the ipa file which generated by my build script and the ipa file generated from Xcode organizer. The build script doesn't contain embedded.mobileprovision and resourceRules.plist. So anyone can tell me anything wrong with my build script? I have made sure paths are right. I use Xcode 4.6.3 (4H1503) and my Mac OS is 10.8.4. My build script is listed below. Thanks.
xcodebuild -project $PROJECT_NAME.xcodeproj -arch i386 -target $PROJECT_NAME -configuration Release -sdk $SDK clean build VALID_ARCHS="i386" CONFIGURATION_BUILD_DIR="$PROJECT_PATH/build"
codesign -f -v -s "$CODE_SIGN" "$PROJECT_PATH/$APP"
xcrun -log -sdk iphoneos PackageApplication -v "$PROJECT_PATH/$APP" -o "$PROJECT_PATH/build/$PROJECT_NAME.ipa" --embed "$PROFILE"
I had same problem while trying to automate my build of iOS app. Apparently xcrun in order to embed provisioning profile, requires an --sign "iPhone Distribution: ..." option to be specified on command line.
I'm trying to archive an app from command line but it gives the following error:
Code Sign error: The identity 'iPhone Distribution: XXX' doesn't match any valid, non-expired certificate/private key pair in your keychains
And I'm using the following lines to build and archive the app:
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
xcodebuild -target TestAppLogicTests \
-sdk iphonesimulator \
-configuration Debug \
TEST_AFTER_BUILD=YES \
clean build | /usr/local/bin/ocunit2junit.rb
# tests passed archive app
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
/usr/bin/xcrun xcodebuild -scheme TestApp clean archive \
CODE_SIGN_IDENTITY="iPhone Distribution: XXX"
I'm sure that my CODE_SIGN_IDENTITY is correct (I've checked it in the .pbxproj file). I've already tried to redownload my distribution certificate but that didn't work either. It's working fine in xCode itself.
Anyone has an idea on what I could try?
Thanks!
Open keychain. Do you see your developer (or distribution) certificate)?
If yes, can you click on it to open a dropdown?
Under it, do you see a text called private key with something else?
If you don't see any dropdown and private key, you must:
Initiate 'Request certificate from authority' from keychain
Export certificate on your hard drive.
Upload this certificate to your apple developer account's provisioning profile section (revoke older certificate)
Update your provisioning profile with newer certificate (go inside each of them and check your certificate)
Download new provisioning profile by opening and refreshing XCode
Close XCode.
Build using command line.
If this is confusing, there are plenty of questions that explains this in more details, like this one.
I am currently having issues creating an IPA file through the xcode command line tool (xcodebuild and xcrun). I first run the following:
xcodebuild -scheme scheme -sdk iphoneOS6.0 -arch armv7 -configuration config clean build#
where scheme and config is the relevant scheme and configuration
I then run
xcrun -sdk iphoneos PackageApplication -v appPath -o ipaPath -sign codesignature
where appPath and ipaPath are paths to the app and ipa and the codesignature what I am signing the ipa with. I have also tried embedding the provisioning profile
The process produces an ipa file however when I try to drag it into itunes it tells me that it is not a valid IPA. I have also tried this process through ad hoc distribution process via Archive in xcode and managed to create a valid IPA, however as I am trying to automate the process this isn't really what I want.
Any thoughts why the IPA would be invalid?
Thanks
You've forgotten to --embed your provisioning profile.
I do something like this
xcrun -sdk iphoneos PackageApplication -v -o `pwd`/out.ipa --sign "iPhone Distribution: Company Name (ID)" --embed /path/to/mobileprovision