Unable to archive project - ios

I am unable to archive my Swift project. When it's archiving, it fails at 90% of the progress. Showing the following error.
The project runs well in the simulator and on my device. But suddenly i am getting this error when archiving... It all worked well before.. Does anyone have any idea?

I got this problem with cocoapods, you should edit the file "YourTarget-framework.sh" in Pods > Target Support Files > Pods-Your Target.
You need to locate this line:
local code_sign_cmd="/usr/bin/codesign --force --sign {EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements "$1""
Replace it by :
local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements '"$1"'"

The path to the binary contains spaces ([...]/ArchiveIntermediates/Trusti - Release/[...]). This should be the problem. The error message displays the path cut before the first space.
I think you should use another product name, and adapt it in InfoPlist.strings if necessary.

Related

Codesign signs my framework as a directory. Why?

I have troubles with the code signing.
I am trying to codesign a framework and use the following command in my script
codesign --verbose --force --sign $(EXPANDED_CODE_SIGN_IDENTITY) $<TARGET_FILE_DIR:${app}>/Frameworks/${fw}.framework
Fo some reasons, that I can't understand, I have my framework signed as a directory
When I do codesign -vvv myLibrary.framework, everything is reported as properly signed, but later when I try to load the framework with dlopen, I see the error that signature is incorrect.
Why do I have it signed as directory ?
Thanks for any ideas.
Found the problem. Info.plist should specify executable and it was not set correctly. It was set to the directory name basically.
So, signcode signs everything as directory.

Xcode 8 can't archive "Command /usr/bin/codesign failed with exit code 1"

I've got a serious problem on Xcode 8 on macOS Sierra.
when I try to build my app, I get the following issue.
CodeSign /Users/me/Library/Developer/Xcode/DerivedData/MyApp-gnoiiwnelmxzdidnijaswisrwdqe/Build/Products/Debug-iphonesimulator/MyApp.app
cd /Users/me/Desktop/MyAppFolder1/MyAppFolder2/MyAppxcode
export CODESIGN_ALLOCATE=/Users/me/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
export PATH="/Users/me/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Users/me/Downloads/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
Signing Identity: "-"
/usr/bin/codesign --force --sign - --timestamp=none /Users/me/Library/Developer/Xcode/DerivedData/MyApp-gnoiiwnelmxzdidnijaswisrwdqe/Build/Products/Debug-iphonesimulator/MyApp.app
/Users/me/Library/Developer/Xcode/DerivedData/MyApp-gnoiiwnelmxzdidnijaswisrwdqe/Build/Products/Debug-iphonesimulator/MyApp.app: resource fork, Finder information, or similar detritus not allowed
Command /usr/bin/codesign failed with exit code 1
then I did https://forums.developer.apple.com/thread/48905 in the terminal as the following and it worked. but once I clean, the issue comes back.
cd /Users/me/Library/Developer/Xcode/DerivedData/MyApp-gnoiiwnelmxzdidnijaswisrwdqe/Build/Products/Debug-iphonesimulator/MyApp
ls -al# *
xattr -c *
and this solution doesn't work for archive with the following issue. is there any solution for it?
CodeSign /Users/me/Library/Developer/Xcode/DerivedData/MyApp-gnoiiwnelmxzdidnijaswisrwdqe/Build/Intermediates/ArchiveIntermediates/MyApp/InstallationBuildProductsLocation/Applications/MyApp.app
cd /Users/me/Desktop/MyAppFolder1/MyAppFolder2/MyAppxcode
export CODESIGN_ALLOCATE=/Users/me/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
export PATH="/Users/me/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Users/me/Downloads/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
Signing Identity: "iPhone Developer: My Name (**********)"
Provisioning Profile: "iOS Team Provisioning Profile: com.**********.*********"
(********-****-****-****-************)
/usr/bin/codesign --force --sign **************************************** --entitlements /Users/me/Library/Developer/Xcode/DerivedData/MyApp-gnoiiwnelmxzdidnijaswisrwdqe/Build/Intermediates/ArchiveIntermediates/MyApp/IntermediateBuildFilesPath/MyApp.build/Release-iphoneos/MyApp.build/MyApp.app.xcent --timestamp=none /Users/me/Library/Developer/Xcode/DerivedData/MyApp-gnoiiwnelmxzdidnijaswisrwdqe/Build/Intermediates/ArchiveIntermediates/MyApp/InstallationBuildProductsLocation/Applications/MyApp.app
/Users/me/Library/Developer/Xcode/DerivedData/MyApp-gnoiiwnelmxzdidnijaswisrwdqe/Build/Intermediates/ArchiveIntermediates/MyApp/InstallationBuildProductsLocation/Applications/MyApp.app: resource fork, Finder information, or similar detritus not allowed
Command /usr/bin/codesign failed with exit code 1
I found this solution in the Apple forum
cd ~/Library/Developer/Xcode/DerivedData
xattr -rc .
or
xattr -rc ~/Library/Developer/Xcode/DerivedData
Solution 1:
You can try file specific bash command like Mark McCorkle answered.
In terminal, goto project's root directory and execute one by one command
find . -type f -name '*.jpeg' -exec xattr -c {} \;
find . -type f -name '*.png' -exec xattr -c {} \;
find . -type f -name '*.tif' -exec xattr -c {} \;
Clean Xcode and Re Build. Done.
Solution 2:
You can fix this problem by finding files which holds finder information.
In terminal, goto project root directory and execute
ls -alR# . > kundapura.txt
This creates kundapura.txt in current directory. Now search for com.apple.FinderInfo and clear this attributes for all files. You can do it like this
xattr -c <filename>
Example: xattr -c guru.png
Once you clear all then you are able to code sign. Cheers
For me worked this:
cd ~/Library/Developer/Xcode/DerivedData
xattr -dr com.apple.FinderInfo *
And then rebuild
There is a more permanent fix for this. Fixing the attributes in the DerivedData works, but the problem keeps coming back. What you need to do is go to the directory shown when you get the 'resource fork, Finder information, or similar detritus not allowed', the one that contains the .App file. Then execute...
xattr -lr MyAppName.App
You can then see the resource files that have the attributes that need removing. Don't remove them from the .App file though, find the original files in your project and open the directory that contains them and execute...
xattr -rc .
This then fixes the ORIGINAL files. Rebuild should then function ok. It should also then rebuild properly for archive too.
This gets caused by some resource files having extra attributes on the file system, probably caused by macOS Sierra (as I started having it after upgrading to macOS Sierra).
Try executing xattr -c * on the whole DerivedData folder (as stated by the answer in https://forums.developer.apple.com/message/178039#178039):
cd ~/Library/Developer/Xcode/DerivedData
xattr -c *
Removing attributes only on the build folder fixed the issue for me when debugging. Removing attributes on the whole DerivedData folder fixed it for me in archiving too. Please note that it may cause other consequences (albeit highly unlikely), but you can always delete the DerivedData folder and it will be regenerated, in case anything gets broken.
Also, if it still fails, cleaning the project (not the build folder) after executing the command is a good idea.
I had this problem with one file from CocoaPods bundle.
I've updated CocoaPods to the latest version and run:
pod install
after that, the problem has gone away.
in my case issue was with Provisioning Profiles and Account, i fixed by doing these steps:
Xcode Preferences ->Accounts->Delete already added account and add it again
Generate new Provisioning Profiles and installed in Xcode
clean project and rebuild it
I want to show my answer because it may be of interest (I have wasted a lot of time with this error)
None of the previous answers (which have a high score) have been useful to me.
They may be correct, but they haven't solved my problem.
Origin:
I added a new Target to my iOS application: iMessage
When I added png images to the Assets. xcassets, the error occurred.
Solution:
Make a copy of png images with "Apple Preview App" and uncheck Alpha.
Error message disappears.
In my case,
Go to
Xcode preference
Locations
Click on Project Path arrow
In DerivedData folder search for your project name
Select project folder, Right click and Move to trash
Done!
I encountered this error on macOS Sierra 10.12.3, Xcode 8.2.
Fixing the DerivedData did not work for me.
After I deleted an expired Apple Worldwide Developer Relations Certificate Authority certificate in Keychain Access the error went away.
Sometimes even if you fixed and/or had correct code-signing done, the problem might lurk in 3rd-party packages.
If you closely check out your build error, you might find the name of the 3rd-party libraries on the error message.
In this case, you must build your 3rd-party libraries again. For example in my case, update it via carthage update and now the build succeeded properly.

Command /bin/sh failed with exit code 1 and Embedded pods framework

Not able to identified actual issue, During updating coco pod getting a message "Re-creating CocoaPods due to major version update."
(that was come only once) and pod updation is successful. After on build i am getting the error. Command /bin/sh failed with exit code 1.
Below is some detail also which i am getting
Code Signing /Users/Gaurav/Library/Developer/Xcode/DerivedData/Appname-******/Build/Products/Debug-iphoneos/Appname.app/Frameworks/Alamofire.framework with Identity iPhone Developer: Account Name (Account Id)
/usr/bin/codesign --force --sign ***************** --preserve-metadata=identifier,entitlements "/Users/UserName/Library/Developer/Xcode/DerivedData/Appname-***************/Build/Products/Debug-iphoneos/Appname.app/Frameworks/Alamofire.framework"
/Users/Username/Library/Developer/Xcode/DerivedData/Appname-************/Build/Products/Debug-iphoneos/Appname.app/Frameworks/Alamofire.framework: bundle format unrecognized, invalid, or unsuitable
I'm using iOS 8 as deployment target and Xcode 7.3.1
I have checked code signing identity that doesn't have any issue. I have reinstall again all pod and Alamofire also but not abel to identified issue.
Clean the project, and deleting the derived data (~/Library/Developer/Xcode/DerivedData/) fixed it for me
If it was complaining about a particular Pod and being unable to codesign it.
Below things work for me:
Select the Pods Project In the main editor window, select the Pod in
the targets dropdown
Under the general tab, and under the identity header, click choose
Info.plist file
Select the plist file for the Pod
The project should now build. For some reason, it seems to lose this setting, or not be able to reference it's own plist file.
Not 100% sure but I hope it helps someone.
I have the same issue. It happen after updating cocoaPods, so I just downgrading it and all works fine. I think we just need to wait for a new version of cocoaPods and for now you can use old version.
How to downgrade cocoaPods

iOS: Codesign error: bundle format unrecognized, invalid, or unsuitable in subcomponent Base.lproj

I have a project that was building just fine. Seemingly randomly, doing a Run one time resulted in a codesign error that I've been unable to resolve for 2 days.
The error reads:
bundle format unrecognized, invalid, or unsuitable
In subcomponent: /Users/user/Library/Developer/Xcode/DerivedData/.../Base.lproj
I'm not sure why this error sprung up. It may have happened after I selected a 'Team' in Xcode - but I can't remember (and I don't know why that would cause an issue). I tried cleaning up my Keychain, creating the bundle identifier in my developer account, a handful of Terminal commands from other posts, to no avail.
What's odd to me is that it seems to indicate it has something to do with Base.lproj - which holds only the LaunchScreen nib and my Main.storyboard. Could there be something in Storyboard that is causing a codesign issue? Something else? SOS.
This is a big stab in the dark, but I got this error when I added a directory named "resources". Removing it fixed the issue for me.
I ran into the same issue with Xcode 7.3.1 and cocoapods. I ended up doing the following:
1.Closed Xcode
2.Removed everything under my DerivedData folder
rm -fr /Users/{user}/Library/Developer/Xcode/DerivedData/*
3.Restarted Xcode and rebuilt the project
I got this error when I added the script fixing a keychain error -34018 which first had appeared in XCode 6.3.
#!/bin/sh
codesign --verify --force --sign "$CODE_SIGN_IDENTITY"
"$CODESIGNING_FOLDER_PATH"
If you are using CocoaPods, then update CocoaPods and then all the pods worked from me.
sudo gem update cocoapods followed by pod install

Codesign returned 1 (object ifile format invalid or unsuitable) bug

I'm working with Xcode 4.1 build 4B110f trying to get my iOS app ready for upload. It passes the Product|Archive step with no errors, asking twice for permission to sign something. But when I try a validate of the archive from the Organizer, it fails:
### Codesigning '/Users/uqrchern/Library/MobileDevice/Provisioning Profiles/70D2381D-3733-4F5D-88B2-4729572C2864.mobileprovision' with 'iPhone Distribution: Ron Chernich'
+ /usr/bin/codesign --force --preserve-metadata --sign iPhone Distribution: Ron Chernich --resource-rules=/var/folders/ul/ula1AHKnGpqQ9ftDnUL-l++++TM/-Tmp-/rybczU3EBd/Payload/ABRA-D.app/ResourceRules.plist --entitlements /var/folders/ul/ula1AHKnGpqQ9ftDnUL-l++++TM/-Tmp-/rybczU3EBd/entitlements_plistrZ1Vwko6 /var/folders/ul/ula1AHKnGpqQ9ftDnUL-l++++TM/-Tmp-/rybczU3EBd/Payload/ABRA-D.app
Program /usr/bin/codesign returned 1 : [/var/folders/ul/ula1AHKnGpqQ9ftDnUL-l++++TM/-Tmp-/rybczU3EBd/Payload/ABRA-D.app: replacing existing signature
/var/folders/ul/ula1AHKnGpqQ9ftDnUL-l++++TM/-Tmp-/rybczU3EBd/Payload/ABRA-D.app: object file format invalid or unsuitable
]
error: codesign failed with error 1
I've looked at all the similar problems and solutions (some of which make no sense whatever, or apply to really old versions of the tools). None have made the slightest difference.
I've also checked 3 times that verify is using the "production" certificate, as is the codesign step that produces the archive. I've even turned the above output into a schell script so I could try all certificates manually: same result every time.
Maybe the .app file being signed really is unsuitable?
Incidentally, codesign has no version flag, but the man page is dated June 1 2006. The binary has a file date of Nov 20 2010.
UPDATE (next day):
Researching the problem further found an obscure reference saying that codesign needs the following environment var set:
CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
Using the output from a failed Validate run, I created a shell script which exported this var just before the failing codesign --force step and viola! The codesign works.
But this does not really help me prepare my code for upload. Is there a way to include this into the script run by the Organizer Validate button??
A LITTLE LATER STILL, THE SOLUTION! :
Under the theory there is a script someplace which generates all the commands run during an Organizer Validate... run, I did some digging with grep and find. The script indeed exists and it's name is:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication
It's just Perl and the fix is to add the required environment var to the associative array %ENV right at the start, say at line 72:
$ENV{CODESIGN_ALLOCATE} = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate';
This totally fixes the problem. I've no idea where all the other posters on the web who think they fixed it by combinations of deleting certificates, building clean, shutting down and restarting Xcode, etc, etc are coming from. I'll just quietly assert that this fix favors science over superstition and works for me under Xcode 4.1 Build 4B110f and its associated PackageApplication script, running under Snow Leopard 10.6.8 with Perl 5.10.0
Just so that this can be taken off the unanswered list. Like you said, you need to add CODESIGN_ALLOCATE to the $ENV array:
$ENV{CODESIGN_ALLOCATE} = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate';
If everyone is in agreement here, I think this question can finally be closed.
When using a more recent version of Xcode, the default location is:
$ENV{CODESIGN_ALLOCATE} = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate';
In case you get this on a recent version of Xcode, what you actually want is, in the shell:
export CODESIGN_ALLOCATE=`xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
which will use the codesign_allocate from the version of Xcode you are using.
You can update the version of Xcode the command line tools use by running xcode-select -switch
I had this workaround in place for a long time, but after upgrading to Xcode 4.3 with iOS 5.1 SDK, my signing script (which calls codesign) stopped working with a cannot find code object on disk error:
output/Enterprise/Payload/MyProduct.app/MyProduct: replacing invalid existing signature
output/Enterprise/Payload/MyProduct.app/MyProduct: cannot find code object on disk
Code signing failed, not creating .ipa file
It seems this workaround isn't necessary for binaries built with Xcode 4.3. To fix, I updated my bash script to check if the location exists before exporting it:
# Only export the environment variable if the location exists,
# otherwise it breaks the signing process!
if [ -f "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate" ]
then
echo Export environment variable for codesign_allocate location
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
fi

Resources