Capacitor 9 on Linux: generating the iOS project without a Mac (and two traps)
Capacitor 9.0.0 shipped on November 30. Since Capacitor 8, new iOS projects use Swift Package Manager instead of CocoaPods, and that quietly changed what you can do from a Linux or Windows machine.
I checked it on Linux with Capacitor 9.0.0 and then compiled the result on a real Mac. Here is where the line is now.
What works on Linux
npm i @capacitor/core @capacitor/ios @capacitor/haptics @capacitor/share
npm i -D @capacitor/cli
npx cap init "My App" com.example.myapp --web-dir dist
npm run build
npx cap add ios
npx cap sync ios
cap add ios finishes with [success] ios platform added! and creates:
ios/App/App.xcodeprojios/App/CapApp-SPM/Package.swift, which lists every Capacitor plugin as a local Swift package
The CLI only asks for CocoaPods when it runs on macOS, so none of this needs a Mac. You can commit ios/, edit Info.plist (usage descriptions, display name) and keep cap sync in your normal web build loop.
The project compiled unchanged on a Mac with Xcode afterwards (** BUILD SUCCEEDED **, simulator, Debug).
Trap 1: two plugins with the same Swift target name
I installed both capacitor-secure-storage-plugin and @aparajita/capacitor-secure-storage while comparing them. cap sync was happy. Xcode was not:
xcodebuild: error: Could not resolve package dependencies: multiple similar targets 'SecureStoragePlugin' appear in package 'capacitor-secure-storage-plugin' and 'capacitor-secure-storage'
With SPM, every plugin's target names share one namespace. CocoaPods never complained about this, so it is new with the switch.
If a tool runs xcodebuild -list and hides stderr, you only see "no scheme found", which sends you looking in the wrong place. Keep one plugin per job, and run npm ls before blaming Xcode.
A plugin built for Capacitor 8 (@aparajita/capacitor-secure-storage 8.0.1, @capacitor-community/keep-awake 8.0.1) prints is built for Capacitor 8, it might cause issues on sync, but both linked and compiled with 9.0.0.
Trap 2: pnpm writes store paths into Package.swift
With pnpm's default symlinked node_modules, the core package path is clean, but plugins resolve into the store:
.package(name: "capacitor-ios", path: "../../../node_modules/@capacitor/ios"),
.package(name: "CapacitorPreferences", path: "../../../node_modules/.pnpm/@capacitor+preferences@9.0.2_@capacitor+core@9.0.0/node_modules/@capacitor/preferences")
That path contains the plugin and core versions, so every dependency bump changes a committed file in ios/. If you commit ios/ and check for drift in CI, expect those diffs, or always run cap sync before the drift check.
What still needs macOS
- Compiling and running the Simulator (
xcodebuild,simctl) - Signing, archiving and uploading to TestFlight
For that last mile I use XenoCI Box, a CLI we build that runs xcodebuild and the iOS Simulator on a real Mac from Linux or Windows: box build for the compile above, box screenshot for a Simulator picture. Signing in with GitHub gives a $10 credit (about 200 Mac minutes), no card: https://docs.xenoci.com/quickstart?ref=devto
Comments
No comments yet. Start the discussion.