前提条件
開発環境 Xcode 16.0
やろうとしたこと
XcodeでFrameworkプロジェクトを作成してそのFrameworkを下記のスクリプトでアーカイブしようとするとエラーになる。
アーカイブ作成の実行スクリプト
xcodebuild archive \
-project BarcodeScan/BarcodeScan.xcodeproj \
-scheme BarcodeScan \
-destination "generic/platform=iOS" \
-archivePath "archives/BarcodeScan-device" \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
SKIP_INSTALL=NO
エラー内容
2025-10-04 13:29:56.660 xcodebuild[92307:30504777] didn't find classname for 'isa' key
2025-10-04 13:29:56.661 xcodebuild[92307:30504777] Writing error result bundle to /var/folders/y1/_ngw1b9j6l7618vtgc9ttxtm0000gn/T/ResultBundle_2025-04-10_13-29-0056.xcresult
xcodebuild: error: Unable to read project 'BarcodeScan.xcodeproj' from folder '/Users/{ユーザー名}/Developments/SwiftUI/barcode_scan_project/barcode_scan/BarcodeScan'.
Reason: The project ‘BarcodeScan’ is damaged and cannot be opened. Examine the project file for invalid edits or unresolved source control conflicts.
Path: /Users/{ユーザー名}/Developments/SwiftUI/barcode_scan_project/barcode_scan/BarcodeScan/BarcodeScan.xcodeproj
Exception: didn't find classname for 'isa' key
解決手順
1.インストールしているXcodeの中のどのXcodeのxcodebuildを使用しているかの確認する。
実行コマンド
xcode-select -p
出力結果
/Applications/Xcode15.2.app/Contents/Developer
開発に使用しているXcodeは16.0ですが、この結果のように使用されているxcodebuildコマンドは Xcode15.2.appの Developerディレクトリ配下のものになります。
(Xcode15.2.appというのは古いバージョンのXcodeのため自分で変更したXcode名になります。)
2.開発に使用しているXcode.app配下のxcodebuildが使用されるように変更する。
sudo xcode-select -s /Applications/Xcode.app
3.変更されたことを確認するため再度下記のコマンドを実行する。
実行コマンド
xcode-select -p
出力結果
/Applications/Xcode.app/Contents/Developer
Xcode.appは開発で使用している16.0のバージョンのXcodeになります。
これで開発で使用しているXcodeのバージョンと、xcodebuildを参照しているXcodeのバージョンが一致したので、再度アーカイブを試したところエラーが改善されました。