A Mac App Store Build Without an Xcode Project: Packaging a Swift Package by Hand

HappyRec for Mac has no Xcode project. It is a Swift package: three targets, one of them Objective-C++ wrapping a vendored C++ pitch-shifting library, built with swift build from the command line. That works well for writing code. It does nothing at all for shipping it, because the Mac App Store does not want a binary. It wants a signed application bundle, inside a signed installer package, carrying a provisioning profile and the right entitlements, with nothing quarantined anywhere inside it.
Xcode normally hides all of that behind the Archive button. Without Xcode you do it yourself, in two short shell scripts. This post walks through both, because each line in them exists because something failed without it, and most of those failures are silent.
Why a package and not a project
The package manifest is the whole build description. There is no .pbxproj to merge, and the same command builds the app on any Mac with the command line tools installed:
// swift-tools-version:5.9
import PackageDescription
let package = Package(
name: "HappyRec",
platforms: [.macOS(.v13)],
targets: [
.target(name: "ObjCExceptionCatcher"),
.target(name: "VoiceDSP", cxxSettings: [.headerSearchPath("../../Vendor")]),
// Scripts/bundle.sh copies .build/<config>/HappyRec into the .app, so
// the executable target name must stay exactly "HappyRec".
.executableTarget(name: "HappyRec",
dependencies: ["VoiceDSP", "ObjCExceptionCatcher"]),
],
cxxLanguageStandard: .cxx17
)
The comment on the executable target is the first sign of the work ahead. SwiftPM produces a bare Mach-O executable at .build/release/HappyRec. It has no Info.plist, no icon and no entitlements. Something else has to turn it into an app, and that something depends on the executable’s name.
Step one: an app bundle is just folders
A macOS app is a directory with a known layout. Scripts/bundle.sh builds that layout by hand:
CONFIG="${1:-release}"
APP="build/HappyRec.app"
swift build -c "$CONFIG"
rm -rf "$APP"
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"
cp Resources/Info.plist "$APP/Contents/Info.plist"
cp Resources/HappyRec.icns "$APP/Contents/Resources/HappyRec.icns"
cp THIRD_PARTY_NOTICES.md "$APP/Contents/Resources/THIRD_PARTY_NOTICES.md"
cp ".build/$CONFIG/HappyRec" "$APP/Contents/MacOS/HappyRec"
That is enough for macOS to recognise it as an app. The Info.plist carries the bundle identifier (com.happycoders.happyrec), the version, the minimum system version (macOS 13, matching Package.swift), the app category and the usage descriptions for the camera and microphone. The third-party notices ship inside the bundle as well, because the vendored DSP library’s licence asks for that.
What the bundle does not yet have is a signature, and on a sandboxed app the signature is where everything interesting happens.

Step two: a development signature that keeps permissions
A screen recorder lives on privacy permissions: Screen Recording, Microphone, Camera. macOS records each grant against the app’s code signature. Ad-hoc sign the app (codesign --sign -) and every rebuild has a new identity, so macOS treats it as a new app and every grant is gone. During development that means clicking through three permission prompts, and one quit-and-reopen, after every build.
The fix is a stable local signing identity. bundle.sh looks for one called “HappyRec Dev” in the login keychain and falls back to ad-hoc only when it is missing:
# Sign with the stable local "HappyRec Dev" identity when present so the
# signature, and therefore TCC grants (screen, mic, camera), survive
# rebuilds. Falls back to ad-hoc, where every rebuild needs a re-grant.
IDENTITY="${CODESIGN_ID:-HappyRec Dev}"
if ! security find-identity -v -p codesigning | grep -q "$IDENTITY"; then
IDENTITY="-"
echo "note: no stable signing identity (permissions reset each rebuild)"
fi
Any self-signed code-signing certificate works for this. What matters is that it does not change between builds, so the grants carry over. The note printed on fallback is not decoration either: without it, a new developer spends an afternoon wondering why the app forgets its permissions every time.
Screen Recording has one more quirk worth knowing during development: macOS applies the grant only to a freshly launched process, so the app has to be quit and reopened once after it is granted. We tried three different automatic “relaunch for you” approaches inside the app. All three proved unreliable in real testing, mostly by leaving stray extra copies of the app running, so the permission screen simply tells the user to quit and reopen. It is less clever and it always works.
Step three: the same entitlements, minus two keys
Local builds use the same entitlements file as the App Store build, so development runs under the same sandbox as the shipped app. Here it is, without its plist header:
<dict>
<key>com.apple.application-identifier</key>
<string>Q4BS2SZ43J.com.happycoders.happyrec</string>
<key>com.apple.developer.team-identifier</key>
<string>Q4BS2SZ43J</string>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>
<key>com.apple.security.device.microphone</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
</dict>
The first two keys tie the app to our Apple team. They are required for the App Store submission. They are also poison for a local build. A self-signed identity has no authority to claim someone else’s team ID, and a sandboxed app whose signature claims it anyway fails the kernel’s code-signature validation at launch. The process is killed with SIGKILL. There is no crash report, nothing on standard error, and no dialog. The app simply does not open.
So bundle.sh makes a copy of the entitlements for development and deletes those two keys from it before signing:
# The entitlements file hardcodes the real Apple Team ID for App Store
# signing. A self-signed or ad-hoc identity has no authority to claim that
# team: embedding it makes the sandboxed app fail kernel code-signature
# validation and get silently SIGKILL'd at launch. Strip both keys for
# local dev signing only.
DEV_ENTITLEMENTS="build/HappyRec.dev.entitlements"
cp Resources/HappyRec.entitlements "$DEV_ENTITLEMENTS"
/usr/libexec/PlistBuddy -c "Delete :com.apple.application-identifier" "$DEV_ENTITLEMENTS" 2>/dev/null || true
/usr/libexec/PlistBuddy -c "Delete :com.apple.developer.team-identifier" "$DEV_ENTITLEMENTS" 2>/dev/null || true
codesign --force --sign "$IDENTITY" --entitlements "$DEV_ENTITLEMENTS" "$APP"
One file is the source of truth; the development variant is derived from it on every build. Keeping two hand-edited entitlement files in sync is exactly the kind of chore that drifts, and a drift here produces an app that is sandboxed differently in development from how it ships.
Never comment an entitlements file
The entitlements plist is parsed by AMFI, the kernel’s code-signing policy component, and its XML parser is stricter than the rest of macOS. An ordinary XML comment, <!-- like this -->, makes signing fail with:
Failed to parse entitlements: AMFIUnserializeXML: syntax error near line N
The trap is that only the App Store script hits it. The development script survives by accident, because PlistBuddy rewrites the file to delete the two team keys and drops the comments on the way through. So a comment can sit in the file for weeks, every local build working, until release day. The rule we follow is simple: the reasons for each entitlement are written in the project notes, never in the plist.
Step four: the App Store package
The App Store build needs three things from the developer account, all for the same team as the App Store Connect record: an Apple Distribution certificate to sign the app, a Mac Installer Distribution certificate to sign the package, and a Mac App Store provisioning profile for the bundle identifier. With those in the keychain and the profile downloaded, Scripts/appstore-package.sh does the rest. Trimmed, the steps are:
# 1. Build release binary and wrap it
swift build -c release
rm -rf build/HappyRec.app
Scripts/bundle.sh
# 2. Embed the Mac App Store provisioning profile
cp "$PROFILE" build/HappyRec.app/Contents/embedded.provisionprofile
# Files downloaded through a browser (the profile almost always is) carry
# com.apple.quarantine. cp preserves it, and App Store Connect rejects any
# quarantined file inside the package (error 91109). Strip it before signing.
xattr -cr build/HappyRec.app
# 3. Sign the app, then build the signed installer package
codesign --force --options runtime \
--entitlements Resources/HappyRec.entitlements \
--sign "$DIST_ID" build/HappyRec.app
productbuild --component build/HappyRec.app /Applications \
--sign "$INST_ID" build/HappyRec.pkg
The script takes the provisioning profile’s path as its only argument and stops with a usage message if it is missing, rather than guessing. Our repository keeps the current App Store profile in the Resources folder next to the entitlements, so the release command is the same every time. Profiles expire and are reissued, so keeping the path an argument means a renewed profile needs no edit to the script itself.
Each step has a reason.
- The profile goes in as
embedded.provisionprofileat the top ofContents. That name and place are what App Store processing looks for. xattr -crbefore signing. The provisioning profile is downloaded from the developer website through a browser, so it arrives carryingcom.apple.quarantine. Copying it into the bundle keeps the attribute, and App Store Connect rejects a package with any quarantined file inside it, with error 91109. The error does not name the file. Clearing every extended attribute in the bundle removes the profile’s quarantine flag and anything else that crept in. It has to happen before signing, because the signature is computed over the finished bundle.--options runtimeturns on the Hardened Runtime. It is also the reason the microphone needs two entitlement keys,device.microphonefor the sandbox anddevice.audio-inputfor the Hardened Runtime, which we wrote about separately. Development signing does not pass this flag, which is one more reason to test the packaged build, not only the local one.- The app is signed with the real entitlements file, team keys included, because now the identity is entitled to claim the team.
productbuild --component ... /Applicationswraps the signed app in an installer package with an install location, signed with the installer certificate. The resulting.pkgis what you upload with Apple’s Transporter app.
Choosing the signing identities
Our script pins both identities by their SHA-1 hash rather than by name. A name such as “Apple Distribution” matches every distribution certificate in the keychain, and a Mac that has certificates for more than one team will sign with whichever one codesign finds first. Pinning the hash removes the guesswork. The cost is that the script must be edited when a certificate is renewed. If you share the script across machines, a check that compares the certificate’s team ID with the profile’s team ID before signing, and stops if they differ, is a worthwhile addition.

Versions: two numbers, and only one is for people
Xcode bumps build numbers for you if you ask it to. A hand-made bundle does not, and App Store Connect is strict about it. The Info.plist carries two version keys. CFBundleShortVersionString is the version people see in the App Store and in the About box; ours is currently 1.0.4. CFBundleVersion is the build number, and ours is currently 20. Every upload must carry a build number higher than the last one you uploaded for that version, or the upload is refused before anyone looks at it.
That number is the right thing to tie your own records to. When a review note comes back, or a user reports a problem, “build 20” is unambiguous in a way that “the version from Tuesday” is not. Because the plist is a plain file in the repository, the bump shows up in the commit that made the release, which is where you want it when you are trying to work out what changed.
A small habit that helps: bump the build number in the same commit as the change you are shipping, not as a separate step on release day. Then the number in the plist always matches a commit, and a package built from any commit says which one it came from.
When the app dies at launch and says nothing
Of all the failures in this post, the team-ID one is the hardest to recognise, because there is nothing to recognise. Double-click the app, the Dock icon bounces once, and it is gone. No crash report appears, because the process never ran any of its own code; it was stopped by the system while the executable was being checked.
When an app vanishes like that, start from the signature rather than the code. Print the entitlements the bundle was actually signed with, using the codesign -d --entitlements - line from the next section, and look for keys that tie the app to a team. If they are there and the identity is a local one, that is your answer. The system log usually records the refusal as well, which you can find by streaming the log while launching the app and filtering for code-signing or AMFI messages, but the entitlements check is quicker and does not depend on knowing what to search for.
The same approach works for the other silent failures. A microphone prompt that never appears is an entitlements question. Permissions that keep resetting is a signing-identity question. An upload refused with a bare error code is a question about what is inside the bundle. In each case, ask the bundle what it is before reading any Swift.
Is skipping Xcode worth it?
It is a fair question, since everything above is something Xcode does for free. For us the answer was yes, for three reasons.
First, the build is plain text from start to finish. The manifest, the two scripts, the plist and the entitlements are all short files that read cleanly in a code review and diff cleanly in history. A project file is neither.
Second, every step is visible. When a release fails, we can see which line did what. The comments in the scripts are the record of why each line exists, and most of them were written the day that line saved us from a failure.
Third, the build runs the same way everywhere a Swift toolchain is installed, with no project settings hidden in a user’s local state.
The cost is real, though. You own every detail Xcode would have handled: the bundle layout, the signing order, the profile, the quarantine flag, the build number. If your app needs storyboards, asset catalogues, app extensions or anything else Xcode compiles specially, the hand-built route becomes much more work. For a single SwiftUI app with a few resources, it is two scripts and an afternoon.
Step five: check what you built, not what you meant
Every failure above is invisible until something downstream complains: a launch that silently dies, an upload refused with an error code, a reviewer who cannot record audio. So the last step is to ask the bundle itself what it is:
# What did we actually ship? Ask the bundle, not the build settings.
codesign -dv --verbose=2 build/HappyRec.app # identity, team, runtime flag
codesign -d --entitlements - build/HappyRec.app # entitlements as signed
xattr -lr build/HappyRec.app # nothing quarantined inside
lipo -archs build/HappyRec.app/Contents/MacOS/HappyRec
pkgutil --check-signature build/HappyRec.pkg # installer signature
The architecture line is there for a reason. The packaging script runs a plain swift build -c release, which builds for the Mac it runs on. On an Apple silicon Mac that produces an arm64-only app, which is what our App Store build is. Our separate direct download is a universal build. If your store page or website promises Intel support, lipo -archs on the binary inside the package is the only honest answer.
What we would tell ourselves at the start
- Derive, do not duplicate. One entitlements file, one Info.plist; development variants are generated from them on every build.
- Give development a stable signature on day one. It saves dozens of permission prompts a day and makes development behave like the real app.
- Assume every failure is silent. A killed process, a rejected upload code, a missing prompt. Print a note whenever the script falls back to something weaker.
- Keep explanations out of the plists. Comments belong in the project’s notes, where no parser will choke on them.
- Test the package, not the folder. The Hardened Runtime and the team keys only exist in the App Store build, so only the App Store build can prove they are right.
Two scripts and about sixty lines replace the Archive button. In exchange, every step is visible, diffable and explained by a comment, which is more than the Archive button ever told us.
HappyRec is our free screen, camera and voice recorder for Mac and Windows, with a browser extension for Chrome and Edge. See what it does.



