How to pass the provisioning profile name in xcodebuild command? - ios

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.

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

xcodebuild Archive failed but xcarchive created

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.

xcode 8 xcodebuild manual code signing from command line for multiple provision profiles

In Xcode 7 I was building project through command line for multiple provision profiles by using following commands. I have multiple provision profiles and multiple code signing certificate linked to those profiles so I need to sign the IPA file with appropriate provision profile.
PROVISION_PROFILE="My Provision profile name"
xcodebuild -workspace ../ProjectName.xcworkspace -scheme "${PRODUCT_NAME}" -sdk iphoneos -configuration "${CONFIGURATION}" archive -archivePath "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.xcarchive"
xcodebuild -exportArchive -archivePath "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.xcarchive" -exportPath "${BINDIR}/${PACKAGE_NAME}-${CURVERSION}.ipa" -exportProvisioningProfile "${PROVISION_PROFILE}"
Now these commands not working for Xcode 8. I uncheck the automatically manage signing after that it gives below error
"someProjectName" requires a provisioning profile. Select a provisioning profile for the "Debug" build configuration in the project editor.
Code signing is required for product type 'Application' in SDK 'iOS 10.1'
Anybody please help me in this.
You are only specifying the provisioning profile in your -exportArchive command. In the -workspace command, Xcodebuild is reaching into the -scheme you specify, which looks at the project.pbxproj file and grabs the provisioning profiles you placed from the project editor for the configurations specified by the scheme being built.
If you open your project.pbxproj file in a text editor, you'll see that the Debug configuration has no provisioning profile listed, which is why Xcodebuild is throwing this error. To fix this, add your provisioning profiles in the project editor (or in project.pbxproj) for the configurations being built by your scheme.
Edit: Now that I better understand the requirements, editing my answer with another option. You can also do this to manually specify the provisioning profile in your build step:
xcodebuild -workspace ../ProjectName.xcworkspace -scheme "${PRODUCT_NAME}" -sdk iphoneos -configuration "${CONFIGURATION}" archive -archivePath "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.xcarchive" PROVISIONING_PROFILE="${PROVISION_PROFILE}"

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.

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