Generate IPA for inhouse distribution via command line

There are multiple teams in our organization developing iOS apps and these apps are usually distributed inhouse to our organization members. We have an Apple enterprise developer account. We used to give each team access to the account but they ended up adding the account to their XCode configuration and XCode would create a provisioning profile in a huge messy manner. It caused a lot of problems in account maintenance. So we have changed the scenario where in the teams request the admin for a provisioning profile and distribution certificate, using which they generate the IPA and sign it and send it to the admin for distribution.


My question here is: What is the best way to generate an IPA file for inhouse distribution given I've access to the enterprise distribution certificate (and key) and the provisioning profile for the bundle ID? I've used the following sequence of commands to do it, but they depend too much on the XCode setup of the machine and the XCode project configuration. Most of the time I get an IPA but the IPA won't install because (according to Apple Configurator console) a "Could not verify signer identity" error would be thrown.


xcodebuild clean -project appfoo.xcodeproj -configuration Release -alltargets
xcodebuild archive -project appfoo.xcodeproj -scheme appfooscheme -archivePath appfoo.xcarchive
xcodebuild -exportArchive -archivePath appfoo.xcarchive -exportPath AppFoo -exportFormat ipa -exportProvisioningProfile "AppFooProvisioningProfileName"


How can I make this simpler?

xcodebuild:


#!/bin/bash

PROJECT="someproject.xcodeproj"

TARGET="your target"

CONFIGURATION="debug, or release"

PROFILE="UDID of the provisioing profile"

IDENTITY="iPhone Distribution: signing identity"

KEYCHAIN="/Users/some-user/Library/Keychains/login.keychain"

PASSWORD="password"

DEST="generic/platform=iOS"

security unlock-keychain -p ${PASSWORD} ${KEYCHAIN}

xcodebuild -project "${PROJECT}" -target "${TARGET}" -configuration "${CONFIGURATION}" -destination "${DEST}" CODE_SIGN_IDENTITY="${IDENTITY}" OTHER_CODE_SIGN_FLAGS="--keychain ${KEYCHAIN}" APP_PROFILE="${PROFILE}" clean build


Archive:

#!/bin/bash

APPDIR="/PATH/debug-iphoneos or release-iphoneos"

CS_OUTDIR="/PATH"

OUTFILE="somefile.ipa"

PROV="/PATH/your_provisioing_profile.mobileprovision"

SIGN="iPhone Distribution: signing identity"


/usr/bin/xcrun -sdk iphoneos PackageApplication "${APPDIR}/some_app.app" -o "${OUTDIR}/${OUTFILE}" --sign "${SIGN}" --embed "${PROV}"

Wow! Thanks. Let me try that and update here.

Generate IPA for inhouse distribution via command line
 
 
Q