Xcode 8 Fastlane build with TeamCity codesign failed with exit code 1 - ios

I've got a weird serious problem with Xcode 8.3.2 on macOS Sierra. I could build the app locally on build machine with fastlane or manually executing commands. Both development and ad-hoc build can be created locally.
$ fastlane <lane_name>
But when tried the same from TeamCity it throws following error.
[exec]/usr/bin/codesign --force --sign 5609CEE02FBF256EDBF60DB28C1A2995A2153B5B --entitlements /Users/<username>/Library/Developer/Xcode/DerivedData/<AppName>-frpvxgdtafatrrgbjqbbepgfzvak/Build/Intermediates/ArchiveIntermediates/SabaMeeting/IntermediateBuildFilesPath/<AppName>.build/Release-iphoneos/<AppName>.build/<AppName>.app.xcent --timestamp=none /Users/<username>/Library/Developer/Xcode/DerivedData/<AppName>-frpvxgdtafatrrgbjqbbepgfzvak/Build/Intermediates/ArchiveIntermediates/SabaMeeting/InstallationBuildProductsLocation/Applications/<AppName>.app
[exec] /Users/<username>/Library/Developer/Xcode/DerivedData/SabaMeeting-frpvxgdtafatrrgbjqbbepgfzvak/Build/Intermediates/ArchiveIntermediates/SabaMeeting/InstallationBuildProductsLocation/Applications/<AppName>.app: unknown error -1=ffffffffffffffff
[exec] Command /usr/bin/codesign failed with exit code 1
[exec]
[exec] ** ARCHIVE FAILED **
[exec]
[exec]
[exec] The following build commands failed:
[exec] CodeSign /Users/<username>/Library/Developer/Xcode/DerivedData/SabaMeeting-frpvxgdtafatrrgbjqbbepgfzvak/Build/Intermediates/ArchiveIntermediates/<AppName>/InstallationBuildProductsLocation/Applications/SabaMeeting.app
[exec] (1 failure)
TeamCity pulls the code and even executes the commands but fails.
Build Step: Command Line is set TeamCity with a custom script.
Tried following ways but not working:
Xcode Preferences ->Accounts->Delete already added account and add it again
Generated new Distribution and Developer Certificate and installed in KeyChain. New Provisioning Profiles and installed in Xcode.
Verified keychain access to private keys by "Allow all applications to access this item". Moved Certificates from login to System with access control to all.
Reinstalled xcode 8.3.2, restarted the machine.
Apple Worldwide Developer Relations Certificate Authority is installed.
Verified resource fork, finder information, or similar detritus not allowed in the app and derived data directory. https://developer.apple.com/library/content/qa/qa1940/_index.html
The project doesn't use CocoaPods.
Tried clearing DerivedData.
Any many more r&d. Any help will be appreciated.

How does your lane look like on your fastfile? Please share it...
My guess;
3 Verified keychain access to private keys by "Allow all applications to access this item". Moved Certificates from login to System with access control to all.
Teamcity is probably not accessing to your certificates and failing.
Try this;
Move certificates back to login from system.
Add following before your gym or whatever fastlane command is building the .ipa. This will let teamcity unlock and access to keychain.
lane :beta do |options|
unlock_keychain(path:"login.keychain", password:"yoursystempassword")
sh "security set-keychain-settings -t 3600 -l ~/Library/Keychains/login.keychain"
gym(scheme: "yourapp", workspace:"probably you dont have a wokrspace so no need")
end

Related

IOS App Build issue: Command CodeSign failed with a nonzero exit code

I am trying to build my IOS app (developed using capacitor and ionic frameworks).
Just after integrating Google Firebase and adding Resources/GoogleService-Info.plist file I am having followng error while building my app in XCode.
Command CodeSign failed with a nonzero exit code
CodeSign /Users/piyush/Library/Developer/Xcode/DerivedData/App-cfgpruswvcmgvpcxuzeyccwfgdyx/Build/Products/Debug-iphonesimulator/App.app (in target 'App' from project 'App')
cd /Users/piyush/Downloads/ncsmobileapp/ios/App
export CODESIGN_ALLOCATE\=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
Signing Identity: "-"
/usr/bin/codesign --force --sign - --entitlements /Users/piyush/Library/Developer/Xcode/DerivedData/App-cfgpruswvcmgvpcxuzeyccwfgdyx/Build/Intermediates.noindex/App.build/Debug-iphonesimulator/App.build/App.app.xcent --timestamp\=none --generate-entitlement-der /Users/piyush/Library/Developer/Xcode/DerivedData/App-cfgpruswvcmgvpcxuzeyccwfgdyx/Build/Products/Debug-iphonesimulator/App.app
/Users/piyush/Library/Developer/Xcode/DerivedData/App-cfgpruswvcmgvpcxuzeyccwfgdyx/Build/Products/Debug-iphonesimulator/App.app: code object is not signed at all
In subcomponent: /Users/piyush/Library/Developer/Xcode/DerivedData/App-cfgpruswvcmgvpcxuzeyccwfgdyx/Build/Products/Debug-iphonesimulator/App.app/AppIcon60x60#2x.png
Command CodeSign failed with a nonzero exit code
I tried cleaning the build cahce, restarting the xcode.
re-building the app through capacitor, but nothig solved this issue yet.
Can anyone help in solving this issue?
Update
While archiving the app following error occurs:
CodeSign /Users/piyush/Library/Developer/Xcode/DerivedData/App-cfgpruswvcmgvpcxuzeyccwfgdyx/Build/Intermediates.noindex/ArchiveIntermediates/App/InstallationBuildProductsLocation/Applications/App.app (in target 'App' from project 'App')
cd /Users/piyush/Downloads/ncsmobileapp/ios/App
export CODESIGN_ALLOCATE\=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
Signing Identity: "Apple Development: Piyush Aggarwal (ZWHGYV6A62)"
Provisioning Profile: "iOS Team Provisioning Profile: app.neo.school"
(d2353688-03d7-47ff-942f-4f34fd4c6a93)
/usr/bin/codesign --force --sign 5FE6CDFE4B615D56B70C5DAEB7A151005A1122AE --entitlements /Users/piyush/Library/Developer/Xcode/DerivedData/App-cfgpruswvcmgvpcxuzeyccwfgdyx/Build/Intermediates.noindex/ArchiveIntermediates/App/IntermediateBuildFilesPath/App.build/Release-iphoneos/App.build/App.app.xcent --generate-entitlement-der /Users/piyush/Library/Developer/Xcode/DerivedData/App-cfgpruswvcmgvpcxuzeyccwfgdyx/Build/Intermediates.noindex/ArchiveIntermediates/App/InstallationBuildProductsLocation/Applications/App.app
/Users/piyush/Library/Developer/Xcode/DerivedData/App-cfgpruswvcmgvpcxuzeyccwfgdyx/Build/Intermediates.noindex/ArchiveIntermediates/App/InstallationBuildProductsLocation/Applications/App.app: code object is not signed at all
In subcomponent: /Users/piyush/Library/Developer/Xcode/DerivedData/App-cfgpruswvcmgvpcxuzeyccwfgdyx/Build/Intermediates.noindex/ArchiveIntermediates/App/InstallationBuildProductsLocation/Applications/App.app/AppIcon60x60#2x.png
Command CodeSign failed with a nonzero exit code
Please try to delete the derived data and clean the build.
Steps to delete derived data:-
1.Open your project,Go to files -> Workspace Settings
Then you will find a derived data location with an arrow:-
Just click on that arrow,after that you will find a folder named derived data,
delete all the files inside derived data folder.
Then it will working fine.
The issue was due to resources folder.
I created that folder to add my GoogleServices-Info.plist file.
I renamed my resources folder and changaed the path to my GoogleServices-Info.pllist file by following code in build phrases of the app in xcode:
PATH_TO_GOOGLE_PLISTS="${PROJECT_DIR}/App/[FOLDER NAME]"
cp -r "$PATH_TO_GOOGLE_PLISTS/GoogleService-Info.plist" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/GoogleService-Info.plist" ;
I have the same (random) issue when Archiving project where OneSignal (specifically OneSignalNotificationServiceExtension) framework is included. What I have to do to make it work (w00t) is to change KeyChain Trust setting on Apple Worldwide Developer Relations Certification Authority (Expires: Tuesday, 7 February 2023 at 22:48:47 Central European ) certificate back to Use System Defaults and then again back to Always Trust. I have no idea why this works, but it works.

Building Xcode project with Jenkins gives codesign error

I'm trying to build Xcode project with Jenkins. Project for Xcode generated by Unity Engine.
I am able to build this project directly from Xcode GUI, but when trying to build project through Jenkins i'm getting following error at the end of build:
Signing Identity: "iPhone Developer: MyName MySurname (XXXXXXXXXX)"
Provisioning Profile: "iOS Team Provisioning Profile: *"
(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX)
/usr/bin/codesign --force --sign 37DF6AF254E5A4856B1BA024D199DEE3CE596A58 --entitlements /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/myapplication.app.xcent --timestamp=none /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app
/Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app: errSecInternalComponent
Command CodeSign failed with a nonzero exit code
** BUILD FAILED **
The following build commands failed:
CodeSign /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app
(1 failure)
Build step 'Xcode' marked build as failure
Finished: FAILURE
I tried to reproduce following command in terminal, and it woked fine without any errors:
/usr/bin/codesign --force --sign 37DF6AF254E5A4856B1BA024D199DEE3CE596A58 --entitlements /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/myapplication.app.xcent --timestamp=none /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app
It asked me for my password two times(and same password specified in Jenkins job settings for Xcode), and finished without any errors.
Keychain i used to sign project is unlocked with: security unlock-keychain login.keychain
The question is - what could be the reason of following behavior? How can i solve this problem?
Thanks in advance!
Jenkins is SSHing into the box and not receiving access to your keychain. Jenkins needs to unlock the keychain before performing the build. It looks like you already understand how to unlock your keychain via password prompt. You need to have Jenkins perform the unlock without a prompt.
Have Jenkins run the following before your build command:
security unlock-keychain -p <YourPassword> ~/Library/Keychains/login.keychain
If you'd rather not store the password in cleartext script area of your build, Jenkins offers various ways to store secrets and retrieve them as variables. Here's a decent write-up on doing that: https://support.cloudbees.com/hc/en-us/articles/203802500-Injecting-Secrets-into-Jenkins-Build-Jobs
Alternatively:
security unlock-keychain -p `cat ~/.file_with_your_password` ~/Library/Keychains/login.keychain

No matching provisioning profiles found - NativeScript iOS deploy

I want to publish an update of my NativeScript app into AppStore. Until yesterday the following steps worked:
move into app directory (from Terminal)
execute tns publish ios
enter valid e-mail & password combination
Now I need to do another update, but I keep getting the following error:
=== BUILD TARGET HandyApp OF PROJECT HandyApp WITH CONFIGURATION Release ===
Check dependencies
Code Sign error: No matching provisioning profiles found: No provisioning profiles matching an applicable signing identity were found.
** ARCHIVE FAILED **
The following build commands failed:
Check dependencies
(1 failure)
Command xcodebuild failed with exit code 65
# publish ios
I am working under Xcode 7.3. I checked my iPhone Developer certificate in Xcode and in my keychain, it is active and not expired. The Provisioning Profile is shown in Xcode. I ensured to use the certificate that is saved in apple.developer.com (by downloading it and replacing the old one in that directory).
I got:
my .mobileprovision
my .cer
my .p12
everything in the same directory.
Still there seems something not to be matching. I just can't figure out what might be running wrong. Does anyone know what else I could try to get it working?

Codesign returns unknown error after "replacing existing signature"

I am trying to build a Xamarin iOS app using xbuild on Jenkins. Sometimes the build fails during the codesigning process with an unknown error -1=ffffffffffffffff and sometimes the build succeeds. The provisioning profile is stored in a separate keychain jenkins.keychain (not the system or login keychain) that is referenced by Jenkins through the Keychains and Provisioning Profiles Plugin.
This is the console log of Jenkins:
Target _CodesignAppBundle:
Codesign Task
CodesignAllocate: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
DisableTimestamp: False
Entitlements: obj/iPhone/In-House/Entitlements.xcent
Keychain: <null>
Resources:
bin/iPhone/In-House/MyApp.app
ResourceRules: <null>
SigningKey: 123
ExtraArgs: <null>
IsAppExtension: False
Tool /usr/bin/codesign execution started with arguments: -v --force --sign 123 --entitlements /private/var/lib/jenkins/workspace/Master/Apps/iOS/obj/iPhone/In-House/Entitlements.xcent /private/var/lib/jenkins/workspace/Master/Apps/iOS/bin/iPhone/In-House/MyApp.app
bin/iPhone/In-House/MyApp.app: error : /private/var/lib/jenkins/workspace/Master/Apps/iOS/bin/iPhone/In-House/MyApp.app: replacing existing signature
/private/var/lib/jenkins/workspace/Master/Apps/iOS/bin/iPhone/In-House/MyApp.app: unknown error -1=ffffffffffffffff
Task "Codesign" execution -- FAILED
Done building target "_CodesignAppBundle" in project "/private/var/lib/jenkins/workspace/Master/Apps/iOS/MyApp.csproj".-- FAILED
As suggested in Codesign returned unknown error -1=ffffffffffffffff I added set-key-partition-list -S apple-tool:,apple:,codesign: -s -k ${KEYCHAIN_PW} ${KEYCHAIN_PATH} to my build script but it did not fix the issue.
Do you have any idea how to address this issue? Why is there an existing signature to be replaced?
Update 1 - We keep getting the error after:
switching from xbuild to msbuild version 15.3.0.0
setting jenkins keychain to "Allow all applications to access this item"
deleting the derived data folder
not using relative paths for security commands
A similar problem is described in the Apple forum.
What fixed the issue:
The keychain filename extension changed from *.keychain to *.keychain-db on macOS Sierra. The code signing error was caused by referencing the old keychain file while we were editing in fact the jenkins.keychain-db file containing updated certificates. Keychains with the new extension are rejected from the upload with Jenkins' keychain plugin. So we do not use the keychain plugin any longer and store the signing certificates inside the login.keychain-db. With this we can successfully build the app without the unknown error.
My resolution to this problem was ensuring that the Mac had proper permissions to use the new certificate. I was getting this code signing issue when trying to run a Jenkins job, but things ran properly on my local machine. When I tried manually code signing one of the Swift libraries (e.g. libswiftos.dylib), the Mac then asked for a password to be able to use the new certificate. Once I did that, the Jenkins job ran successfully.
Restarting the Mac could Fix the issue

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