xcodebuild cannot find correct iOS Development Certificate under cron - ios

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.

Related

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.

Attempting to install the Release version on my device gets conflict profiles

I am trying to install the Release version of my app on my device to test it.
When I select the Edit > Scheme and under RUN I choose "Release" for Build Configuration
But I get the error:
My App has conflicting provisioning settings. My App is automatically
signed for development, but a conflicting code signing identity iPhone
Distribution has been manually specified. Set the code signing
identity value to "iPhone Developer" in the build settings editor, or
switch to manual signing in the project editor. Code signing is
required for product type 'Application' in SDK 'iOS 10.2'
I have gone to Code Signing and Ensured that my release is my iOS Distribution
I have deleted all my profile, certs and re-imported. I have cleaned the build. I have removed my account.
When I switch to Manual Signing I get the error:
No signing certificate "iOS Distribution" found
No "iOS Distribution" signing certificate matching team ID "XXXXXXXXXX" with a private key was found.
But it is in my KeyChain.
I'm so frustrated. Has anyone else solved this?
You're supposed to use the iOS developer profile when running builds on your device. You can build in release mode still. However you can't install distribution signed binaries through Xcode.
You can create an ad-hoc profile to test push notification for the release build. It is same as the distribution build.

ssh xcodebuild no signing certificate

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"

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