IPA Export Using XCodebuild and shell script - ios

I've been searching for long time for a way to export IPA using Xcodebuild and shell script , all i found was an old code and even XCodebuild error aren't understandable for me . Please if there's one who have tried to do this and found a solution for it , that will be awesome and helpfull
PS: In fact i've found a solution this script to generate IPA
THIS IS MY CODE
xcodebuild clean -workspace "${WORKSPACE_ABSOLUT_PATH}" -scheme "${SHEME_NAME}" -configuration Release
###Cleaning XCodeproj(Without Pods)
xcodebuild clean -project "${PROJECT_ABSOLUT_PATH}" -scheme "${SHEME_NAME}" -configuration Release
####Setting (Prod) Boolean value
#echo -n "" >"${PLIST_CONFIGURATION_NAME}"
##
#echo "Prod boolean value is $8"
##
#echo "<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>Prod</key><${PROD_BOOLEAN_VALUE}/></dict></plist>" >> "${PLIST_CONFIGURATION_NAME}"
##
#head "${PLIST_CONFIGURATION_NAME}"
#
#
###Preparing Archive (Generate .xcarchive file)
##
xcodebuild archive -workspace "${WORKSPACE_ABSOLUT_PATH}" -scheme "${SHEME_NAME}" -archivePath "${ARCHIVE_ABSOLUT_PATH}"
##
#
##Export Archive file (.xcarchive) to (.ipa) file
#
xcodebuild -exportArchive -archivePath "${ARCHIVE_ABSOLUT_PATH}" -exportPath "${IPA_ABSOLUT_EXPORT_PATH}" -exportFormat ipa -exportProvisioningProfile "${PROVISIONING_PROFILE_NAME}"

Since Xcode 8.3 , you will not be able to select provision profile for the ipa...
see if this tool helps you
https://github.com/johnny77221/export-IPA

Related

Making IPA from command line xcode 9

i have many projects embedded in single main project, i am trying to automate the build process. but issue is that i cant make build using command line.
Clean project
xcodebuild clean -project TestingCommandLine.xcodeproj -configuration Debug -alltargets
Make Archive
xcodebuild archive -project TestingCommandLine.xcodeproj -scheme "TestingCommandLine" -configuration Debug -archivePath myApp.xcarchive
Build IPA
xcodebuild -exportArchive -archivePath myApp.xcarchive -exportPath myApp.ipa -exportOptionsPlist exportOptions.plist
the same process works with simple project which does not have any dependencies.
The following build commands failed:
Ld watchos/Watch\ Extension.appex/iskanWatch\ Extension normal armv7k
(1 failure)
This is the actual failure error comes when i try to build.
Any help will be appreciated.

Including .dSYM file inside .ipa file

For iOS builds with Xcode 8, is it possible to include a generated .dSYM file into the .ipa file?
I'm building my ipa files like this (in Jenkins but it shouldn't matter) ...
# Create xarchive
xcodebuild
-workspace /sourcepath/myapp.xcworkspace
-sdk iphoneos
-scheme 'Distribution Production'
-configuration 'Distribution Production'
-archivePath '/outputpath/Distribution Production-iphoneos/myapp.xcarchive'
'CODE_SIGN_IDENTITY=********'
'PROVISIONING_PROFILE=App Enterprise PRD'
DEBUG_INFORMATION_FORMAT=dwarf-with-dsym
archive
# Create IPA
xcodebuild
-exportArchive
-archivePath '/outputpath/Distribution Production-iphoneos/myapp.xcarchive'
-exportOptionsPlist '/outputpath/Distribution Production-iphoneos/export_options.plist'
-exportPath '/outputpath/Distribution Production-iphoneos'
This generates an xarchive and lastly an ipa file. The xarchive then contains the .dSYM file but I'd like to have the .dSYM in the IPA file instead. Is this possible?
I tried using these arguments in addition when creating the xarchive:
'DWARF_DSYM_FOLDER_PATH=/outputpath/Distribution Production-iphoneos'
'DWARF_DSYM_FILE_NAME=Distribution Production.dSYM'
... but then the xarchive doesn't contain the dSYM and it isn't being found anywhere else.

Errors converting xcarchive to IPA - single-bundle archive + missing plist method values

I'm trying to convert my xcarchive to an IPA (XCode 7.1.1). The following command
xcodebuild
-exportArchive -archivePath foo.xcarchive -exportPath . -exportFormat IPA
Fails with the error
the archive at path 'foo.xcarchive' is not a single-bundle archive
Since the above command is technically deprecated, I also tried the new form:
xcodebuild
-exportArchive -archivePath foo.xcarchive -exportPath .
-exportOptionsPlist ipa.plist
Where the ipa.plist is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>app-store</string>
</dict>
</plist>
Which then resulted in the error:
error: exportArchive: exportOptionsPlist error for key 'method':
expected one of {}, but found app-store
Now, trying to debug this I opened the xcarchive folder and inspected its structure. I noticed that I have a folder on the same level as Products\Applications\foo.app so I deleted it and tried again to no avail (same results). I then proceeded to delete files from within foo.app until I remained with nothing but the DWARF binary - still no cigar (same result), though that could have been due to the fact that I messed up the app signature by deleting files manually.
Apple got back to me with a solution. As of Xcode 7 we should use xcodebuild instead of PackageApplication to produce the .ipa file.
xcodebuild has a new -exportArchive option to create an .ipa that works more like Xcode Organizer.
So we should now:
build an archive with xcodebuild archive
create the .ipa with xcodebuild -exportArchive
We now build the archive like this:
xcodebuild -workspace myApp.xcworkspace -scheme myApp -sdk iphoneos -configuration AppStoreDistribution archive -archivePath $PWD/build/myApp.xcarchive
We now export the .ipa like this:
xcodebuild -exportArchive -archivePath $PWD/build/myApp.xcarchive -exportOptionsPlist exportOptions.plist -exportPath $PWD/build
These two command create the files build/myApp.xcarchive and build/myApp.ipa
Note that xcodebuild -exportArchive requires a -exportOptionsPlist argument that points to a .plist file with export options. For a complete list of what you can put in that plist, run xcodebuild -help. The minimal contents of the file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>app-store</string>
<key>teamID</key>
<string>YOUR_TEN_CHARACTER_TEAM_ID</string>
</dict>
</plist>
Since the way you are creating an IPA is deprecated, you should do the following instead:
xcodebuild -scheme "Foo" -configuration Release clean build CODE_SIGN_IDENTITY="iPhone Distribution: Foo Corporation" -derivedDataPath "/path/to/some/folder/"
xcrun -sdk iphoneos PackageApplication "/path/to/some/folder/Build/Products/Release-iphoneos/foo.app" -o "/path/to/some/folder/foo.ipa"
Make sure you replace "Foo" with your schema name, and "iPhone Distribution: Foo Corporation" with your signing identity. And "/path/to/some/folder/" should be some build folder.
I got some similar strange errors from XCode 7.2 when building for the simulator on the command line. You could try to either add -sdk iphoneos to your xcodebuild command (in order to skip simulator builds), or add something like -destination 'platform=iOS Simulator,name=iPhone 6,OS=latest' if you're building for the simulator.
Try using absolute paths as parameters to xcodebuild options rather than relative paths.
So something like this:
xcodebuild -exportArchive -archivePath "$PWD/foo.xcarchive" \
-exportPath "$PWD" -exportOptionsPlist "$PWD/ipa.plist"
As long as your .xcarchive is intact and signed correctly, that should work. This is what I'm using in my build system.
I recently switched to using the fastlane gym tool to build and create ipa files... I had a problem where one command line worked for making ad-hoc builds and I needed a different config to make app store builds and couldn't resolve it. The fastlane stuff pretty much worked out of the box.
https://github.com/fastlane/gym
The problem was that one of our post-build steps left a stray folder in the TARGET_BUILD_DIR. This caused the generated xcarchive to be formatted as the dreaded generic archive. My attempts to delete the folder after the fact from the xcarchive itself were doomed to fail since the xcarchive has been flagged generic at the moment of its creation (as evidenced by some missing Info.plist fields). Once I made sure TARGET_BUILD_DIR contained only the .app after all the build phases were said and done, the generated xcarchive was formatted properly as an iOS app archive. That xcarchive, in turn, was easily exported to a proper IPA via xcodebuild -exportArchive -exportPlistOptions, which is the officially supported Apple recommendation that takes care of all the problematic SWIFT support folders and the like.
The archive at path foo.xcarchive is not a single-bundle archive.
About this error:
check edit scheme -> Build
untick other targets, including Analyze, Test, Run, Profile, Archive
xcodebuild the archive
export the archive again

XCodeBuild is not picking a configuration from my workspace

This is my build command
xcodebuild -workspace MyApp.xcworkspace \
-scheme MySchemeName \
-configuration AdHoc \
clean archive
It works but its uses the default configuration for the archive scheme (which is release) instead of AdHoc which I specified. In fact if you specify -scheme ASchemeNameThatDosnNotExist it still works and silently ignores the configuration name.
The project is setup like this:
xcodebuild -list
Targets:
MyApp
MyAppTests
Build Configurations:
Debug
AdHoc
Release
If no build configuration is specified and -scheme is not passed then "Release" is used.
This project contains no schemes.
And the workspace like this:
xcodebuild -workspace MyApp.xcworkspace -list
Schemes:
MyApp
Pods
Pods-AFNetworking
.. More pods
I.e. There are no targets and no configurations in the workspace.
How do I make a target visible to the workspace? Or is there another way?
It's impossible to configure target for workspace. You can create a scheme based on a particular target and then build a project passing scheme name. Setting configuration via '-configuration' switch works fine for me. I use xcode v. 5.0.2.
In general a configuration is set via action. You can create multiple schemes for archiving (with different configurations) and there's no need to pass configuration at all. Default configuration will be taken.
Thank you #Opal for your answer. I was initially mislead by your statement that '-configuration' was working. In fact, this does not work, and the specified configuration is silently ignored when performing an xcodebuild via the workspace:
xcodebuild -workspace $WORKSPACE.xcworkspace \
-scheme $SCHEME \
-configuration QA \
clean archive -archivePath archives/$APP_NAME
xcodebuild -exportArchive \
-archivePath archives/$APP_NAME.xcarchive \
-exportPath . \
-exportOptionsPlist $WORKSPACE/ExportOptions.plist
mv $APP_NAME.ipa $APP_NAME.$VERSION.$BUILD_NUMBER.ipa
However, after creating a custom shared scheme for that configuration, "myapp-QA", the build completes correctly:
xcodebuild -workspace $WORKSPACE.xcworkspace \
-scheme $SCHEME-QA \
clean archive -archivePath archives/$APP_NAME-QA
xcodebuild -exportArchive \
-archivePath archives/$APP_NAME-QA.xcarchive \
-exportPath . \
-exportOptionsPlist $WORKSPACE/ExportOptions.plist
mv $APP_NAME-QA.ipa $APP_NAME.$VERSION.$BUILD_NUMBER.qa.ipa
There is an issue with using configuration & scheme arguments. A scheme has its own configuration and most probably it overrides configuration specified via xcodebuild -configuration.
You can solve it by using configuration & target:
xcodebuild -project <project>.xcodeproj \
-configuration <configuration> \
-target <target> \
-sdk iphonesimulator \
clean build

Build Project From Terminal throws Provisioning Profile error

I am trying to create ipa of my application using terminal.
I am able to successfully build my application, but when converting into an ipa, it throws the following error:
Check dependencies
Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning profile with the UUID “/Users/xxxx/Downloads/Certificate/xxxx.mobileprovision”, however, no such provisioning profile was found.
CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 7.0'
** ARCHIVE FAILED **
When I try to build the same application using X-Code, it works fine with the same provisioning profile.
The script I am running to build the ipa is
xcodebuild -verbose -project Build_Project_From_Terminal.xcodeproj -scheme nameOfProject -configuration Release -sdk iphoneos clean archive CONFIGURATION_BUILD_DIR="/Users/xxxx/Desktop/xxxx/Project Name/build" PROVISIONING_PROFILE="/Users/xxxxx/Downloads/Certificate/xxxxx.mobileprovision"
EDIT 1:
I have changed my script to
DEVELOPER_NAME="xxxxxxxxx" APP_NAME="xxxxxx"
xcodebuild archive -project $APP_NAME.xcodeproj -scheme $APP_NAME -archivePath ./$APP_NAME.xcarchive
xcodebuild -exportArchive -exportFormat APP -archivePath ./$APP_NAME.xcarchive -exportPath ./$APP_NAME.ipa
iphoneos PackageApplication -v ./$APP_NAME.app -o ./$APP_NAME.ipa --sign $DEVELOPER_NAME --embed ./*.mobileprovision
With this I am getting $APP_NAME.ipa.app as output. When I try to install this, it does not install at all.
Any help will be appreciated.
Please use an alternate method. This is a working example
DEVELOPER_NAME="Your apple developer name"
APP_NAME="application name"
xcodebuild archive -workspace $APP_NAME.xcworkspace -scheme $APP_NAME -archivePath ./$APP_NAME.xcarchive
xcodebuild -exportArchive -exportFormat APP -archivePath ./$APP_NAME.xcarchive -exportPath ./$APP_NAME.ipa
iphoneos PackageApplication -v ./$APP_NAME.app -o ./$APP_NAME.ipa --sign $DEVELOPER_NAME --embed ./*.mobileprovision
Save above shell script in a file (abc.sh) and save that file in your project folder along with your provision profile. Run this script using terminal will save ipa in the project directory.

Resources