xcodebuild archive generates malformed xcarchive when adding custom build settings - ios

I'm trying to generate an xcarchive using xcodebuild that I can later export as an .ipa using the new functionality added with Xcode 5.
This works perfectly fine:
xcodebuild -workspace 'MyWorkspace.xcworkspace' -scheme 'MyScheme' -configuration 'Release' -archivePath tmp.xcarchive archive
xcodebuild -exportArchive -exportFormat IPA -archivePath tmp.xcarchive -exportPath app.ipa -exportWithOriginalSigningIdentity
But as soon as I add custom build settings to the archive command:
-derivedDataPath build SYMROOT=build/build.sym DSTROOT=build/build.dst OBJROOT=build/build.obj SHARED_PRECOMPS_DIR=build/build.pch
The .xcarchive generated is empty, but there is no error.
Any ideas?

For me, this had to do with the Installation Directory Deployment Build Setting in Xcode: CMake somehow set this to "", i.e. an empty string, when it should have been "/Applications", the Xcode default. For me, setting it to anything else than "/Applications" caused the resulting archive to be empty and therefore 'malformed'.
So maybe your project somehow did not have Installation Directory set to "/Applications", either because of CMake or something else.
To set this using CMake, add this to your target properties:
set_target_properties(${MODULE} PROPERTIES
...
XCODE_ATTRIBUTE_INSTALL_PATH "/Applications"
...
)

For me this error happened when I had no space left on the drive where I tried to create the archive. But I could not tell that from the errors int he console

In my case, I was missing the .xcarchive extension at the end of my path.
xcodebuild -exportArchive -archivePath /<path_to_archive>/file.xcarchive ...

In my case the 'archivepath' directory/file path was incorrectly set in previous steps, and it was looking into a directory which did not have .xcarchive file. Worth checking manually the paths and if the archive file exists in the directory

Related

“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 find DWARF_DSYM_FOLDER_PATH and DWARF_DSYM_FILE_NAME in xcode 9.3

I am using the Crashlytics in order to report the crash occurs in the iOS app. Here, I want to know how to find the path of these below dwarf folder and file in xcode:
DWARF_DSYM_FOLDER_PATH
DWARF_DSYM_FILE_NAME
You can do it using xcodebuild tool:
xcodebuild -project MyProject.xcodeproj -target MyTarget -showBuildSettings
Output of this command will contain Xcode env values including DWARF_DSYM_FOLDER_PATH and DWARF_DSYM_FILE_NAME.
You need to go to Organizer and select your archive file, select show in finder
after that you need to select show package content
and finally there is your DYSM folder
If you have a workspace and multiple schemes, you can use the following command from the xcodebuild tool.
xcodebuild -workspace Project.xcworkspace -scheme ProjectSceheme -showBuildSettings

Export .ipa file from Xcode project without ever opening Xcode

We have an API that users can call to create Cordova apps/projects, upload their www directory, and then start compilation and download the executable binary file. This binary file will then go into a private app store.
I'm having trouble with the compile step for iOS. The Cordova build step is no problem, but it doesn't output a binary file, like it does for Android. After reading everything I found on Stackoverflow and elsewhere, the plan was this:
xcodebuild clean -configuration Release -alltargets
xcodebuild -scheme MyApp archive -archivePath build/MyApp
xcodebuild -exportArchive -exportFormat ipa -archivePath "build/MyApp.xcarchive" -exportPath "MyApp.ipa" -exportProvisioningProfile "My Prov Profile"
Given that the signing identity and everything is set up correctly, it almost works. The first command executes fine. The second command just hangs.
However, if I open the project in Xcode, and then execute the commands, it compiles and exports, and I'm left with an .ipa file, which is what I wanted. It seems that Xcode sets up a workspace and some scheme-related things when the project is first opened.
Is there any way I can get xcodebuild (or xcrun, or anything, for that matter) to create this workspace file for me?
Or is there another way to approach this?
Right now, I have a solution where I actually open the Xcode project, wait 15 seconds, and then proceed. But I can think of a thousand ways that will fail at some point, so I would like to change it to something a little more elegant.
I currently have Xcode 6.3 installed, if that is relevant.
Update: Opal's answer below set me on the right path (I think). What I ended up doing, was exporting a shared scheme as per Opal's link, and using that as a template for future apps. The solutions was something like this:
# Copy shared scheme file into directory
mkdir /path/to/project/dir/MyApp.xcodeproj/xcshareddata
mkdir /path/to/project/dir/MyApp.xcodeproj/xcshareddata/xcschemes
cp data/MyScheme.xcscheme /path/to/project/dir/MyApp.xcodeproj/xcshareddata/xcschemes/.
# Use sed to replace app name in scheme file
sed -i '' "s/%app_name%/MyApp/g" MyApp.xcodeproj/xcshareddata/xcschemes/MyScheme.xcscheme
# CD into directory
cd /path/to/project/dir
# Move files from Cordova to our build directory
cp -r CordovaLib/build/* build/.
# Build and export
xcodebuild clean -configuration Release -alltargets
xcodebuild -scheme MyScheme archive -archivePath build/MyApp
xcodebuild -exportArchive -exportFormat ipa -archivePath "build/MyApp.xcarchive" -exportPath "MyApp.ipa" -exportProvisioningProfile "MyProvProfile"
It seems that the application you try to build has no shared schemes. Schemes if not shared, are created when project is loaded to xcode. To create shared schemes see this site.
These are the steps I used to automate ipa generation without opening xcode in my cordova environment. (xcode version: 6.0.1 cordova version: 3.6.0)
Change in cordova/build.xcconfig: CODE_SIGN_IDENTITY=iPhone Distribution (change "Developer" to "Distribution". )
run cordova build ios --device in cordova workspace that generates .app file
Sign using : xcrun -sdk iphoneos PackageApplication -v ${WORKSPACE}/platforms/ios/build/device/${application.name}.app -o ${WORKSPACE}/platforms/ios/build/${application.name}.ipa --embed ${ios.distribution.provisionfile}.mobileprovision --sign ${code.signing.identity}

xcconfig option in xcodebuild command

I have created an app in IOS and want to build and run it through command line. The xcodebuild command helps in building the app and its basic syntax is as follows:
xcodebuild -target "${TARGET_NAME}" -sdk "${TARGET_SDK}" -configuration Release -xcconfig "${BUILD_SETTINGS_FILE_PATH}"
Each target will contain its product name and other build settings. Now I don't want to take the product name/build settings specified in xcode target, but rather through some external file which can contain build settings. So, i tried using the -xcconfig option but I am not clear with its implementation. What kind of file it should be and how the path to the file be configured?. The official documentation also doesn't seem to be too clear.
xcodebuild PRODUCT_NAME argument affects all targets
.xcconfig file can be created using Xcode and the format of providing value is:
CUSTOM_CFBundleVersion = 3.0.
CUSTOM_CFBundleShortVersionString = 3.0

Generating ipa from xcode command-line

Whats the best approach for generating an IPA file from command-line?
I'm on xcode 4.2 and generating the archive using:
xcodebuild -scheme AppStore clean archive
This generates the .dSYM and .app files in the build output directory, after codesigning. How should I proceed to generate the .ipa file? In other words, I'm looking for the command-line equivalent of doing the following in GUI
Organizer - Archives
Share
iOS App Store Package
Don't Re-sign
Thanks!
The missing piece is using the PackageApplication utility.
/usr/bin/xcrun -sdk iphoneos PackageApplication -v $FULL_PATH_TO_APP -o $OUTPUT_PATH
You can also pass this script options for resigning, and profile embedding. Using the --sign and --embed flags respectively.
This tool makes it trivial to build (and distribute): https://github.com/nomad/shenzhen
After Archive, you need to "Export" to desired format ie ipa:
xcodebuild -sdk iphoneos7.0 -archivePath "path to archive file" -exportPath "path_for_export" -exportFormat ipa -exportArchive -exportProvisioningProfile "provisioning_profile_to_export_with"

Resources