Generating ipa from xcode command-line - ios

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"

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 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.

xcode 7: Building for enterprise and adhoc with the same archive

Currently using the xcode 6 build process, we first create the xcarchive with the following command
xcodebuild -workspace OurApp.xcworkspace -scheme MainScheme \
clean archive -archivePath OurApp.xcarchive -sdk "iphoneos" \
-configuration "Release" CODE_SIGNING_REQUIRED="NO" \
CODE_SIGN_IDENTITY="" PROVISIONING_PROFILE=""
By not doing any code signing and provisioning, we then use the exportArchive command to generate the respective enterprise and adhoc ipas using the same archive like this.
xcodebuild -exportArchive -archivePath OurApp.xcarchive \
-exportPath OurApp-adhoc.ipa -exportFormat "ipa" \
-exportProvisioningProfile "Our Adhoc Provisioning Profile"
and
xcodebuild -exportArchive -archivePath OurApp.xcarchive \
-exportPath OurApp-enterprise.ipa -exportFormat "ipa" \
-exportProvisioningProfile "Our Enterprise Provisioning Profile"
Note that we would have our servers set the appropriate code sign identity before running these exportArchive commands. This worked really well for us since we could use the same xcarchive(takes 8 minutes to compile) and create multiple variants with it(exportArchive step doesn't take more than 30 seconds).
In Xcode7, Apple Introduced exportOptionsPlist. Xcode 7 also saw the introduction of features such as Swift Support and Universal Links, both of which we deploy. These two features require you to use exportOptionsPList it seems. The only way I was able to get exportOptionsPlist is that I could no longer set CODE_SIGN_IDENTITY and PROVISIONING_PROFILE to "" when generating IPA. As a result, our build times will double since we now have to build the xcarchive twice
I was wondering if anyone knows a way to create an enterprise IPA and an adhoc ipa using the same xcarchive.
Hi its not possible because whenever you create an iPA from Archive it create each iPA separately for Adhoc or Enterprise or else.

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}

xcodebuild archive generates malformed xcarchive when adding custom build settings

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

Resources