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

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.

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.

Codemagic iOS Flutter deploy fails on archive

I have a question where and how to add allowProvisioningUpdates in Xcode? My Codemagic account is connected with App Store Connect, bundle id and app are also created.
Build process fails on the app archive, but Xcode build is successfully done.
Can I somehow add allowProvisioningUpdates to this command?
Execute "xcodebuild -workspace /Users/builder/clone/ios/Runner.xcworkspace -scheme Runner -config Release -archivePath build/ios/xcarchive/Runner_1pxkp9aq.xcarchive archive COMPILER_INDEX_STORE_ENABLE=NO"
Every time build process returns me this message after fail:
Error: No profiles for 'com.xxx.xxx' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.xxx.xxx'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'Runner' from project 'Runner')
Do you have some suggestions, on how to resolve this?
Thanks.
The error itself is probably actually unrelated, and adding the flag will not change much.
If you're using .yaml and are trying to set up automatic code signing I would encourage you to add xcode-project use-profiles before your build step.
For automatic .yaml code signing with Flutter iOS the workflow should include:
a) keychain initialize
b) app-store-connect fetch-signing-files "your.bundle.id" --type IOS_APP_STORE --create
If you wish to use development certificate then IOS_APP_DEVELOPMENT as type.
d) keychain add-certificates
e) xcode-project use-profiles
f) flutter build ios
g) xcode-project build-ipa --workspace "ios/Runner.xcworkspace" --scheme "Runner" (change to your workspace and scheme)
In addition you should implement versioning, if you do not want to do it manually for each build.
If you're not using automatic code signing, then you will need to upload your provisioning profile and the process will be a bit different. But the process is somewhat similar, you can take a look at the documentation: https://docs.codemagic.io/code-signing-yaml/signing-ios/

xcodebuild can't sign ios application although the developer certificate and provisioning profile are installed

There is one logged-in user in xCode, but I need to build on behalf of another user. From this user there is a fresh iPhone Developer certificate and corresponding provisioning profile.
- The certificate is installed in the keychain.
- Provisioning profile is installed in the correct Xcode directory.
xcodebuild passes that user's Team Id:
xcodebuild archive \
-workspace XXXXXXXXXXXXXXXX.xcworkspace \
-scheme XXXXXXXXXXXXXXXX \
-archivePath ./XXXXXXXXXXXXXXXX.xcarchive \
-destination generic/platform=iOS \
IPHONEOS_DEPLOYMENT_TARGET=10.0 \
TARGETED_DEVICE_FAMILY="1" \
CODE_SIGN_ENTITLEMENTS=XXXXXXXXXXXXXXXX.entitlements \
DEVELOPMENT_TEAM=$teamId \
-parallelizeTargets \
-jobs 4 \
-verbose \
ENABLE_BITCODE=NO \
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS=NO \
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS=NO \
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS=NO \
-allowProvisioningUpdates
Signing does not work:
Check dependencies
[08:44:01][Step 8/14] Code Signing Error: No account for team "XXXXXXXXXX". Add a new account in the Accounts preference pane or verify that your accounts have valid credentials.
[08:44:01][Step 8/14] Code Signing Error: No profiles for 'com.xxxxxxxxxxxx.xxxxxxxxxxxx' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.xxxxxxxxxxxx.xxxxxxxxxxxx'.
[08:44:01][Step 8/14] Code Signing Error: Code signing is required for product type 'Application' in SDK 'iOS 11.4'
What didn't help:
Clean xCode's cache (just removing the folder ~/Library/Developer/Xcode/DerivedData)
Cleaning the keychain from expired certificates
Checked TeamId and appId to match exactly developer.apple.com
It turned out that Mac has 2 copies of xcode. Both copies deleted. One is reinstalled.
there are 2 errors left after deleting the parameter -allowProvisioningUpdates:
[09:16:31][Step 8/14] Check dependencies
[09:16:31][Step 8/14] Code Signing Error: No profiles for 'com.xxxxxxxxxxxx.xxxxxxxxxxxx' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.xxxxxxxxxxxx.xxxxxxxxxxxx'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild.
[09:16:31][Step 8/14] Code Signing Error: Code signing is required for product type 'Application' in SDK 'iOS 11.4'
If I open project from xCode, disable auto-signing, select provisioning profiles, start the archive build, it is successfully completed. But I need to build project from command line (TeamCity)

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.

building xcode project from jenkins fails. when building in command line runs just fine. why?

building xcode project from jenkins fails.
when building in command line runs just fine.
why?
this is is the error I get:
[BEROR]Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning profile with the UUID “_UUID_”, however, no such provisioning profile was found.
[BEROR]CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 7.1'
this is the command line used:
xcodebuild -project PROJECTNAME.xcodeproj/ -target TARGETNAME -configuration Release -sdk iphoneos7.1 clean build
ps: anything with OBJECT was censored so this question can appear online, there was real data there before.
Are you using the login key-chain or did you create a different key-chain for jenkins builds app signing?
If you are just using the login key-chain make sure you unlock the key-chain during the build.
If you are using a different key-chain make sure you swap key-chains and then unlock it.
Jenkins - Xcode build works codesign fails - this thread is quite informative.
Also adding these 2 commands to your build can help you debug it:
/usr/bin/security list-keychains
/usr/bin/security find-identity

Resources