ssh xcodebuild no signing certificate - ios

When I try to build my app trough ssh with xcodebuild
xcodebuild -sdk iphoneos10.1 -target <app_target> -configuration Debug CODE_SIGN_IDENTITY="iPhone Developer" PROVISIONING_PROFILE=<profile> CONFIGURATION_BUILD_DIR=<some_dir>
It spits an error
No signing certificate "iOS Development" found: No
"iOS Development" signing certificate matching team ID "team_id"
with a private key was found. Code signing is required for product
type 'Application' in SDK 'iOS 10.1'
If I run it without ssh it builds.
The CODE_SIGN_IDENTITY is different than the "certificate_name". Shouldn't they be the same? The one I ask for is "iPhone Developer" and the build error is about "iOS Development".
I have tried this answer (if at all relevant to my problem).
When ssh-ed and I try security list-keychains it lists the system keychain twice. If I have not ssh-ed it shows the user login keychain-db as well.
I unlock the login keychain when ssh-ed to see if it will be displayed in the list and it is not.

Well the easiest solution was to copy the certificate from the login keychain to the system keychain. Don't know how secure or correct that is.

CODE_SIGN_IDENTITY should something like this:
iPhone Developer: Your Name (3374ZYXN2A)
You can find it in your Key Chain:
open Keychain Access
find your certificate
right-click it and choose "Get Info"
Copy the entry in "Common Name"

Related

xcodebuild archive keeps trying to use "Development Certificate" even if I specify an "AdHoc Distribution" provisioning profile

I have been trying to build iOS app from command line (on Mac Machine) using xcodebuild command.
Here's the command I am using to export the archive:
xcodebuild -project "Path/BuildOutput/XCode/Unity-iPhone.xcodeproj" -scheme "Unity-iPhone" archive -archivePath "Path/BuildOutput/XCode/Archive.xcarchive" -destination "generic/platform=iOS" -configuration Release PROVISIONING_PROFILE="xxxxxxxx-yyyyyyyy"
The profile "xxxxxxxx-yyyyyyyy" is created on my Apple Developer website as an "Ad Hoc" type profile, and it uses a certificate with type "Distribution", which in creation is displayed as "Apple Distribution"
I am getting the following error:
error: No signing certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID "XXXXXXXXXX" with a private key was found. (in target 'Unity-iPhone' from project 'Unity-iPhone')
The error does not occur when I am using a provisioning profile with type "Development" and the corresponding certificate is also "iOS Development" type. It seems that despite I specify a profile with "Ad Hoc" type, xcodebuild still tries to find a corresponding "iOS Development" type certificate while the actual certificate type does not match.
The "Apple Distribution" certificate shows up correctly when I go to XCode Preference and "Manage Certificate"
I am stuck at this point and don't know what to do. Any help would be appreciated.
I experienced this same issue with Xcode 13. Xcode seems to be mixing up profiles/certs.
In the IDE, I noticed that I could fix this issue by re-selecting the provisioning profiles for each configuration (dev/QA/prod in my case). I had to select the wrong profile for each configuration, then the correct one, and I would see the error disappear. xcodebuild worked.
To fix without messing with Xcode, I added the CODE_SIGN_IDENTITY="iPhone Distribution" option to xcodebuild
In your case:
xcodebuild -project "Path/BuildOutput/XCode/Unity-iPhone.xcodeproj" -scheme "Unity-iPhone" archive -archivePath "Path/BuildOutput/XCode/Archive.xcarchive" -destination "generic/platform=iOS" -configuration Release PROVISIONING_PROFILE="xxxxxxxx-yyyyyyyy" CODE_SIGN_IDENTITY="iPhone Distribution"

Teamcity - CI/CD - iOS - xcodebuild - signing - No signing certificate "iOS Development" found

I have Teamcity installed with an Agent on a MAC. When I try to build the iOS project I have this error:
error: No signing certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID "#######" with a private key was found. (in target 'App' from project 'App').
I use this command line:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace ios/App/App.xcworkspace -scheme App clean build
I did test the command in a terminal directly on the mac and it Works! My certificates are located in the keychain in the session of the user that runs the Agent of Teamcity.
I did try to put the certificate in another keychain and grant access to the process that is executed by Teamcity using this command :
security unlock-keychain -p [password] ~/Library/Keychains/teamcity.keychain-db
Any ideas?
Managed to solve this. The issue was that for some reason teamcity was looking at System keychain, and of course found nothing.
Adding certificate to the system keychain resolved this.

Xcode signing using Jenkins

I am trying to sign and archive my Unity application with Jenkins. I have the Xcode jenkins plugin installed and everything seems to run well except for a strange problem.
During the xcodebuild phase, when the archive should be signed, I get the following error:
error: No signing certificate "iOS Development" found: No "iOS
Development" signing certificate matching team ID "QF6V2M666X" with a
private key was found. (in target 'Unity-iPhone')
Now the problem is that I am not trying to build for development, but for production. I have a production provisioning profile used, which is pointing the production certificate. The team id is the production team id (changed here for security reasons). Here is another part of the build output:
Going to invoke xcodebuild:, scheme: Unity-iPhone, sdk: DEFAULT,
project: DEFAULT, configuration: Release, clean: NO, archive:YES,
consolelog:YES, symRoot: DEFAULT, buildDir: DEFAULT,
developmentTeamID: QF6V2M666X
[sr-ios] $ /usr/bin/xcodebuild -scheme
Unity-iPhone -configuration Release archive -archivePath
When I open the project in Xcode, I can see that for some reason Xcode selects "IOSDeveloper" in the code signing identities part and not "IOSDistribution" (or the actual certificate in the provisioning profile):
I don't know if this can be changed from Jenkins, but I think Xcode should pick this up from the provisioning profile.
So I managed to find the problem and solve it, here is the solution for others.
In Unity 2018 they added a new option to the iOS player settings, in the "Other settings" section, called IOS Provisioning Profile->Profile type:
This option is used to select the signing identity. I guess you can use "Automatic" but in my case, since I am using Jenkins, I am setting it on a build script like this:
PlayerSettings.iOS.iOSManualProvisioningProfileType =
ProvisioningProfileType.Distribution;
When this option is set, xcode is able to sign the app correctly for distribution.

xcodebuild cannot find correct iOS Development Certificate under cron

I am currently using xcodebuild command line tool to build and deploy the app to iPhone as follows.
I saw in my login keychain that the iOS Development Certificate does exist but the key does not match Key1 as shown in the output. My question is how to allow xcodebuild to pick the correct iOS Development Certificate that is currently in the keychain.
Build Command
HOME=/Users/mcj xcodebuild build-for-testing -project ios/ios_test_app/HXKPIIOS/HXKPIIOS.xcodeproj -scheme HXKPIIOS -destination 'platform=iOS,id=<iPhoneUDID>' -derivedDataPath /opt/HX/HXKPI_Logs/kpi18_iOS_2018-06-23-21-20-01-149882/<iPhoneUDID>/build_derived_data | tee /opt/HX/HXKPI_Logs/kpi18_iOS_2018-06-23-21-20-01-149882/<iPhone UDID>/uitest/build1.log
Output
User defaults from command line:
IDEDerivedDataPathOverride = /opt/HX/HXKPI_Logs/kpi18_iOS_2018-06-23-21-20-01-149882/<iPhoneUDID>/build_derived_data
=== BUILD TARGET HXKPIIOS OF PROJECT HXKPIIOS WITH CONFIGURATION Debug ===
Check dependencies
Code Signing Error: No signing certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID "<Key1>" with a private key was found.
Code Signing Error: Code signing is required for product type 'Application' in SDK 'iOS 11.2'
Go to the Project Navigator >> "General" tab. Look for the "Signing" section and you will see your Team, Provisioning Profile, Signing Certificate, and your Signing Status. Perhaps there is an issue with your Status as you were unable to sign in with your account. In that case, simply press Sign In... and re-enter your credentials. Or, perhaps, you are signed in on a team that does not have your Signing. In that case, go to the Team section and simply change which team you are signed in with. And finally, check your signing certificate in the Signing section. If its empty, that's why Xcode doesn't recognize your certificate.

Cannot build project using xcodebuild, but can using Xcode.app

I am unable to make a build of my project using the xcodebuild command as it cannot find the singing identity for the development team. However, I can make a build using Xcode.app. This is the error I get with xcodebuild:
=== BUILD TARGET AppName OF PROJECT AppName WITH CONFIGURATION Release ===
Check dependencies
No signing certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID "1234567890" with a private key was found.
The project settings define that the code signing identify for release builds is set to "iPhone Distribution":
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
DEVELOPMENT_TEAM = 1234567890;
And I can see the signing certificate and key in my keychain for that identify:
The build command I am using is:
xcodebuild \
-workspace "AppName.xcworkspace" \
-scheme "AppName (Release)" \
-destination generic/platform=iOS \
build
The scheme defines to build using release configuration.
As it happens I was logged in to the build server using SSH and when you log in to a mac using SSH the keychain is not unlocked automatically, therefor even though a certificate did exist, xcodebuild could not access it.
This question on Super User explains how you can unlock the keychain over ssh, or you can just use Terminal.app locally.

Resources