Xcode 3.2 provides an awesome new feature under the Build menu, \"Build and Archive\" which generates an .ipa file suitable for Ad Hoc distribution. You can also open the O
I found some of the other answers here hard to get going. This article did if for me. Some paths may need to be absolute, as mentioned in the other answers.
The Command:
xcrun -sdk iphoneos PackageApplication \
"/path/to/build/MyApp.app" \
-o "output/path/to/MyApp.ipa" \
--sign "iPhone Distribution: My Company" \
--embed "/path/to/something.mobileprovision"
I have given a brief description of steps to follow, and parameters to pass while generating an ipa using terrminal below:
Go to the folder which contains the MyApp.xcodeproject file in terminal
By using the command given below you will get all the Targets of the application
/usr/bin/xcodebuild -list
After the above command is executed, you will get a list of targets of which you should select a specific target you need to generate .ipa
/usr/bin/xcodebuild -target $TARGET -sdk iphoneos -configuration Release
The above command builds the project and creates a .app file.The path to locate the .app file is ./build/Release-iphoneos/MyApp.app
After Build gets succeeded then execute the following command to generate .ipa of the application using Developer Name and Provisioning Profile using the syntax below:
/usr/bin/xcrun -sdk iphoneos PackageApplication -v “${TARGET}.app” -o “${OUTDIR}/${TARGET}.ipa” –sign “${IDENTITY}” –embed “${PROVISONING_PROFILE}”
Explanation of each Parameter in the above syntax:
${TARGET}.app == Target path (ex :/Users/XXXXXX/desktop/Application/build/Release-iphoneos/MyApp.app)
${OUTDIR} == Select the output directory(Where you want to save .ipa file)
${IDENTITY} == iPhone Developer: XXXXXXX (XXXXXXXXXX)(which can be obtained from Keychain access)
${PROVISONING_PROFILE} == Path to the provisioning profile(/Users/XXXXXX/Library/MobileDevice/Provisioning Profiles/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.mobileprovision”)
if you use next tool: https://github.com/nomad/shenzhen
then this task is very easy:
which ipa 1>/dev/null 2>&1 || echo 'no shenzhen. to install use: sudo gem install shenzhen --no-ri --no-rdoc'
ipa build --verbose --scheme "${schemeName}"
source
Updating my answer with Xcode 9 and Swift
Archive
xcodebuild -workspace <ProjectName>/<ProjectName>.xcworkspace \
-scheme <schemeName> clean archive -configuration release \
-sdk iphoneos -archivePath <ProjectName>.xcarchive
IPA Export (please note the export option plist)
xcodebuild -exportArchive -archivePath <ProjectName>.xcarchive \
-exportOptionsPlist <ProjectName>/exportOptions.plist \
-exportPath <ProjectName>.ipa
For those who don't know about exportOptions.plist, https://blog.bitrise.io/new-export-options-plist-in-xcode-9
Those who were using this for building project in CI/CD tools like teamcity/jenkins, please make sure you are using the right xcode installed in the build agent for for both archive and export.
You can use either of below 2 options for this.
/Applications/Xcode 9.3.1.app/Contents/Developer/usr/bin/xcodebuild
xcode-select -switch /Applications/Xcode 9.3.1.app
Below is my old answer
Here is command line script for creating archive and IPA example. I have an iPhone xcode project , which is located in Desktop/MyiOSApp folder.
Execute following commands one by one:
cd /Users/username/Desktop/MyiOSApp/
xcodebuild -scheme MyiOSApp archive \
-archivePath /Users/username/Desktop/MyiOSApp.xcarchive
xcodebuild -exportArchive -exportFormat ipa \
-archivePath "/Users/username/Desktop/MyiOSApp.xcarchive" \
-exportPath "/Users/username/Desktop/MyiOSApp.ipa" \
-exportProvisioningProfile "MyCompany Distribution Profile"
This is tested with Xcode 5 and working fine for me.
try xctool, it is a replacement for Apple's xcodebuild that makes it easier to build and test iOS and Mac products. It's especially helpful for continuous integration. It has a few extra features:
No.3 is extremely useful. I don't if anyone can read the console output of xcodebuild, I can't, usually it gave me one line with 5000+ characters. Even harder to read than a thesis paper.
xctool: https://github.com/facebook/xctool
I found how to automate the build and archive process from the comand line, I just wrote a blog article explaining how you can achieve that.
The command you have to use is xcrun
:
/usr/bin/xcrun -sdk iphoneos PackageApplication \
-v "${RELEASE_BUILDDIR}/${APPLICATION_NAME}.app" \
-o "${BUILD_HISTORY_DIR}/${APPLICATION_NAME}.ipa" \
--sign "${DEVELOPER_NAME}" \
--embed "${PROVISONING_PROFILE}"
You will find all the details in the article. If you have any questions dont hesitate to ask.