xcodebuild Archive failed but xcarchive created - ios

I recently started using On demand resources in my project.To support it i changed my build script so that now i first create an archive and then export it to ipa.
Here are the commands i am using
xcodebuild -project ABC.xcodeproj/ -configuration Debug -scheme "ABC" archive -archivePath bin/debug/ABC.xcarchive
xcodebuild -exportArchive -archivePath bin/debug/ABC.xcarchive -exportPath bin/debug -exportOptionsPlist ABC/content/Info_debug.plist
When i execute first command build runs smoothly but in the end it shows
CreateAssetPackManifestPlist
Creating AssetPackManifest.plist
** ARCHIVE FAILED **
There are no error logs or any other indication which show any problem. Even though it shows archive failed xcarchive file is created and i am able to use it to successfully export to ipa. I also installed and validated the ipa , app runs fine.
So i modified command to
xcodebuild -project AMC.xcodeproj/ -configuration Debug -scheme "ABC" archive -archivePath bin/debug/ABC.xcarchive || exit 0
Now everything is working fine but i am still unsure why command shows "Archive failed". What can be the reasons for it and is it ok to export it to ipa even though it shows archive failed.

Related

how to properly archive an ios app xcode 13

Well there are lots of articles/blog on archiving an iOS app, i've tried several of them, but i end up getting one error or the other, I'm setting up CI/CD, and I'm at the stage of archiving my app.
These are the most promising errors i've gotten so far, i say promising cause other errors encountered seem to be dead ends, but the below commands seems to be a step in the right direction.
1st Command
xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -sdk iphoneos -configuration AppStoreDistribution -archivePath $PWD/build/MyApp.xcarchive clean archive
Output
error: Signing for "MyApp" requires a development team. Select a development team in the Signing & Capabilities editor. (in target 'Decred Wallet' from project 'MyApp')
2nd Command
xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -sdk iphoneos -configuration MyApp\ Release -archivePath $PWD/build/MyApp.xcarchive clean archive
Output
error: No profiles for 'com.mydomian.myapp.test' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.mydomian.myapp.test'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'MyApp' from project 'MyApp')
has anyone done this recently, I need some insight please.
also a few steps to this
i already created a direcory mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles and copied my mobile provisioning file there, i also created a keychain and imported my .p12 file into it

CircleCI build fails because of CODE_SIGN_IDENTITY in xcodebuild command

I have inherited a project that uses Fastlane and CircleCI to generate builds. It has been broken for a while but I managed to get most of it working again. However the actual build keeps failing on the build server, locally all of my lanes already finish successfully.
I've been comparing what happens locally versus on the CI server and the difference seems to be in the way Circle archives the project. I've changed it so it will run locally and the errors remain the same:
xcodebuild -workspace ./App.xcworkspace -scheme App -configuration AdHoc -destination generic/platform=iOS -archivePath "/Users/me/Library/Developer/Xcode/Archives/2020-08-14/App 2020-08-14 13.08.37.xcarchive" archive "CODE_SIGN_IDENTITY=iPhone Distribution: ACME"
Results in:
error: No certificate for team '123ABC4DEF' matching 'iPhone Distribution: ACME' found: Select a different signing certificate for CODE_SIGN_IDENTITY, a team that matches your selected certificate, or switch to automatic provisioning. (in target '***********-SomeLibrary' from project '***********')
It looks like it wants to sign not only the main application using the CODE_SIGN_IDENTITY, expects 'iPhone Distribution: ACME' to be explicitly there and fails when it doesn't.
As soon as I remove the CODE_SIGN_IDENTITY part at the end it starts working locally:
xcodebuild -workspace ./App.xcworkspace -scheme App -configuration AdHoc -destination generic/platform=iOS -archivePath "/Users/me/Library/Developer/Xcode/Archives/2020-08-14/App 2020-08-14 13.08.37.xcarchive" archive"
I've been combing over all of the settings where this might be specified hardcoded but I couldn't find anything. GYM_CODE_SIGN_IDENTITY hasn't been added for example. So how is it possible that it doesn't add that CODE_SIGN_IDENTITY flag locally using Fastlane but yes remote on the server?
I've found out that it was a variable set up in the configuration of CircleCI:
https://app.circleci.com/settings/project/github/[your_org]/[your_app]/environment-variables

“ExportOptions.plist” couldn’t be opened because there is no such file.”

We are trying to run the project using terminal instead of Xcode->Product->Archieve. We have completed the clean, build and archive successfully. When export .ipa I am getting this following error “The file “ExportOptions.plist” couldn’t be opened because there is no such file.”. When I surf in stack overflow I can’t get any idea about plist file.
For example: we have an app with the original name MyApp
xcodebuild clean -workspace MyApp.xcworkspace -scheme Development
xcodebuild build -workspace MyApp.xcworkspace -scheme Development
xcodebuild archive -workspace MyApp.xcworkspace -scheme Development
-archivePath ~/Users/Desktop/SampleApp/MyApp.xcarchive
The above code works fine. When using the below line I am getting “ExportOptions.plist” error.


xcodebuild -exportArchive -archivePath
~/Users/Desktop/SampleApp/MyApp.xcarchive -exportPath
~/Users/Desktop/SampleApp/MyApp -exportOptionsPlist ~/Users/Desktop/SampleApp/ExportOptions.plist
My question is : 

Do we need to create plist manually? I have exported the test flight build for the previous one. I have an “ExportOptions.plist” file with .ipa file. Do we need to move the ExportOptions.plist into the output folder?
Do we need to create an output folder to export all .ipa and .plist? I have created “NewFolder” and tried it’s not working.
Correct me if I am using the wrong path for archive path, export path and exportOptionsPlist
ExportOptions.plist is required in Xcode 9. It lets you to specify some options when you create an ipa file. You can select the options in a friendly UI when you use Xcode to archive your app.
Follow this blog to generate one.
https://medium.com/#marksiu/how-to-build-ios-project-with-command-82f20fda5ec5
You need to create the plist file yourself. It tells xcodebuild how you want to export the archive.
Run xcodebuild -help command and look for “Available keys for -exportOptionsPlist” section. It describes what keys to use in the plist dictionary, what values are expected and what are default values if you omit the key. Since the keys are optional, the plist can be empty.
The Plist path should be the archived sample app folder:
#CLEAN
xcodebuild clean -workspace Sample.xcworkspace -scheme release
#BUILD
xcodebuild build -workspace Sample.xcworkspace -scheme release
#ARCHIVE
xcodebuild archive -workspace Sample.xcworkspace -scheme release -archivePath ./build/archive/Sample.xcarchive
#IPA
xcodebuild -exportArchive -archivePath ./build/archive/Sample.xcarchive -exportPath ./build/adhoc -exportOptionsPlist ./build/archive/Sample.xcarchive/info.plist

How to pass the provisioning profile name in xcodebuild command?

I want to fully automize the build option to generate archive and iPA through command line tools i.e xcodebuild.
Problem facing :- I am generating the archive using
xcodebuild -schme XYZ -archivePath .../XYZ.xcarchive archive.
Question :- The archive generated/signed via developer account whereas release is selected from Edit scheme.
First you need to the archive file with below command.
xcodebuild archive -project <PROJECT_NAME>.xcodeproj -scheme <NAME_OF_SCHEME> -archivePath <PROJECT_NAME>.xcarchive
And then you need to export the archive into an ipa.
xcodebuild -exportArchive -archivePath <PROJECT_NAME>.xcarchive -exportPath <PROJECT_NAME> -exportFormat ipa -exportProvisioningProfile "Name of Provisioning Profile"
However I am not sure this is what you are looking for.

Why won't my build phase scripts be executed when creating an IPA from command line?

Question - short version:
Why won't my build phase scripts be executed when creating an IPA from the command line?
When I'm running xcodebuild to create an IPA the predefined build phase scripts does not get executed. Why is that?
Question - lengthy version:
I have a workspace with a scheme I want to create an IPA out of from command line.
This works fine except for one thing; I have two scripts in the build phases of the target that is used to put the correct app version (CFBundleShortVersionString) and the correct svn revision number (CFBundleVersion). These to scripts works fine when archiving from xcode but for some reason they do not get run when archiving from command line.
First of all why is that?
Here are the scripts that are working (if archiving form xCode)
When archiving and creating the IPA from the command line I do (the essentials)
# Building
xcodebuild ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release clean build
# Creating IPA
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${PROJECT_BUILD_DIR}/${APPLICATION_NAME}.app" -o "${IPA_OUTPUT_PATH}/${APPLICATION_NAME}.ipa"
It works and creates an IPA but none of the build phase scripts gets executed leaving both the revision number and version number untouched.
All suggestions are appreciated!
UPDATE DUE TO BDASH's ANSWER
Instead of making a clean build I make an install as
xcodebuild install ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release
The predefined script will IN FACT be executed (can be seen in the project version number) with no errors during the install. However the created IPA will have a size of ~300 bytes (instead of ~10MB) and cannot be installed on a device.
Building the app before installing it, i.e.
# Building
xcodebuild clean build ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release
# Installing
xcodebuild install ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release
and then creating the IPA will result in an IPA with executed version script and of correct size BUT it is not possible installing it on a device. Trying to put it on a device will give an error message saying
"The program "MyApp" was not installed on you iPhone device "My Device" because an unknown error has occurred."
You have "Run script only when installing" checked for at least one of the script phases. That phase won't be run when using the build action to xcodebuild, only if using the install action.

Resources