xcode - building app with command line gives provisioning profile error - xcode

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.

Related

Manual signing with `xcodebuild` complains about missing signing certificate

Looking at discussion here, I am trying to manually sign my iOS in command line for CI.
I did a sed to replace automatic signing with manual signing as was required looking at discussion here.
sed -i '' 's/ProvisioningStyle = Automatic;/ProvisioningStyle = Manual;/' MyApp/MyApp.xcodeproj/project.pbxproj
The ran the following command to manually sign using xcodebuild
xcodebuild -project MyApp/MyApp.xcodeproj -scheme "MyApp" -configuration Release DEVELOPMENT_TEAM="97ARBCD76FG" PROVISIONING_PROFILE="xxxx-xxxx-xxxx"
I get the following error:
Provisioning profile "iOS Team Provisioning Profile: *" doesn't
include signing certificate "iPhone Distribution: My Company
(97ARBCD76FG)". 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'
What am I missing for the manual signing to work with xcodebuild?

Signing app with xcodebuild command line with PROVISIONING_PROFILE fails

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

xcodebuild fails through Jenkins

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.

xcodebuild: build Mac OS app

I'd like to do automating for my Mac App project.
My environment is Mac OS 10.8.3; Xcode 4.6.
I use the following command in the terminal:
xcodebuild -project pro.xcodeproj -target MyProject -configuration Debug CODE_SIGN_IDENTITY='Mac Developer: xxxxxx'
It ran well and I could see the MyProject.app was created in the workspace: /build/Debug.
Then I just copied it to the Jenkins configurations, like:
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer/
xcodebuild -project pro.xcodeproj -target MyProject -configuration Debug CODE_SIGN_IDENTITY='Mac Developer: xxxxxx'
However, the build always failed with :
Code Sign error: Provisioning profile 'EADA149E-1A30-4C3C-B42B-75DEA77308DF' can't be found
What makes me strange is that I could not find the "wrong" profile.
I find a same question Distributing .app file after command line xcodebuild call. But the "archive" is invalid in xcode 4.6.
So please help me about how can I do the automating for Mac App.
Thanks!
I find it and it is the same problem like "provison not found".
What you need to do is delete the referred provision file in prom.xcodeproj/project.pbxproj.
You can find the same answers here Codesign error: Provisioning profile cannot be found after deleting expired profile

CODE_SIGN_IDENTITY parameter for xcodebuild (Xcode 4)

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.

Resources