LoginSignup
69
28

More than 3 years have passed since last update.

エラー:xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

Last updated at Posted at 2019-04-24

遅ればせながら、swiftのdoxygenみたいなソフトのJazzyをインストールしてみた。
いくつかエラーが発生して、他の記事みたいにすぐには動作しなかったので、そのメモ。

なお、インストールはgemで簡単にできる。

$ sudo gem install jazzy

タイトルのエラー

設定でハマって長時間ロスした(後述)が、ようやく設定ファイルが正しく書けたあと、更に、以下のエラーが表示された。(日本語部分は実際には違う)

$ jazzy
Using config file /Users/名前/Documents/プロジェクトフォルダ/.jazzy.yaml
Running xcodebuild
Checking xcodebuild -showBuildSettings
Running xcodebuild
Could not parse compiler arguments from `xcodebuild` output.
Please confirm that `xcodebuild` is building a Swift module.
Saved `xcodebuild` log file: /var/folders/pz/9mzb_mkx3v94jy0ntccyb0380000gn/T/xcodebuild-C79ABD95-5E64-4DA7-9DE0-5754328EA522.log
Failed to generate documentation
/Library/Ruby/Gems/2.3.0/gems/jazzy-0.9.6/lib/jazzy/executable.rb:36:in `execute_command': /Library/Ruby/Gems/2.3.0/gems/jazzy-0.9.6/bin/sourcekitten ["doc", "--module-name", "アプリ名", "--", "-workspace", "アプリ名.xcworkspace", "-scheme", "アプリ名"] (RuntimeError)
(以下略)

エラーメッセージにあるxcodebuildのlogファイルを表示させたところ、タイトルのエラーが記録されていた。

$ cat /var/folders/pz/9mzb_mkx3v94jy0ntccyb0380000gn/T/xcodebuild-C79ABD95-5E64-4DA7-9DE0-5754328EA522.log
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
$

最近になって、仕方なく1 Mojaveと、Xcode10.2にアップデートしたので、それが原因かと想像。
なお、アップデート後のいつものコマンドは実行済み。

$ xcode-select --install

cocoaPodsもhomebrewも動いているけど、jazzyはダメだった。

直し方

  1. Xcodeを起動する。
  2. メニューの[Xcode] → [Preferences…] を開く。
  3. [Locations]を選択。
  4. [Command line Tools:] リストボックスが空欄になっていた。これが原因なので、クリックして、表示されるXcode 10.2を選択する。 screenshot.png
  5. jazzyをプロジェクトフォルダ直下で実行。

めでたく動作した。

その他

他のツールでもこのエラーは出るらしい。直し方は同じ(多分)。

なお、最初は、xcodebuildのlogに、以下のようなエラーが記録されていた。

$ cat ログファイル名
Build settings from command line:
    CODE_SIGN_IDENTITY = 
    CODE_SIGNING_REQUIRED = NO

note: Using new build system

** CLEAN SUCCEEDED ** [0.105 sec]

note: Using new build system
note: Planning build
note: Constructing build description
Build system information
error: An empty identity is not valid when signing a binary for the product type 'App Extension'. (in target 'エクステンション名')

Build system information
error: An empty identity is not valid when signing a binary for the product type 'Application'. (in target 'アプリ名')

** BUILD FAILED **
$

そのため、xcodebuild_arguments にコードサインの指定が必要なのかと思ってしまい、いろいろ試して時間を消費する事になってしまった。
結果的にはコードサインの指定は必要なく、-workspace-schemeの指定だけで十分に動作している。同じエラーはもう再現しないので、おそらく、上記のXcodeでのコマンドツールの指定がないために発生していたものと思われる。

最終的な設定ファイルを参考に示す。(日本語の部分は実際にはアプリなどの半角名が入っている)

.jazzy.yaml
min_acl: private
clean: true
output: docs
author: "作者"
sdk: iphone
module: モジュール名
xcodebuild_arguments: [ -workspace, アプリ名.xcworkspace, -scheme, アプリ名]

Jazzyの設定について

jazzyのオプションはコマンドラインでも指定できるが、.jazzy.yamlというファイルをプロジェクトフォルダの直下に作成しておくと自動的に反映してくれる。この設定のYAML形式に馴染みがなくて、ここで結構ハマってしまった。

コロンの後ろにスペース

.jazzy.yaml
clear:true    # エラーになる

YAMLはコロンの後ろにスペースを要求する。上記のようにスペースがないと、jazzyの実行時に以下のようなエラーになる。

$ jazzy
Using config file /Users/ユーザ名/Documents/プロジェクトフォルダ/.jazzy.yaml
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/psych.rb:379:in `parse': (<unknown>): could not find expected ':' while scanning a simple key at line 6 column 1 (Psych::SyntaxError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/psych.rb:379:in `parse_stream'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/psych.rb:327:in `parse'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/psych.rb:293:in `safe_load'
    from /Library/Ruby/Gems/2.3.0/gems/jazzy-0.9.6/lib/jazzy/config.rb:476:in `read_config_file'
    from /Library/Ruby/Gems/2.3.0/gems/jazzy-0.9.6/lib/jazzy/config.rb:436:in `parse_config_file'
    from /Library/Ruby/Gems/2.3.0/gems/jazzy-0.9.6/lib/jazzy/config.rb:384:in `parse!'
    from /Library/Ruby/Gems/2.3.0/gems/jazzy-0.9.6/bin/jazzy:15:in `<top (required)>'
    from /usr/local/bin/jazzy:22:in `load'
    from /usr/local/bin/jazzy:22:in `<main>'

Using config file 〜 の次にrubyのエラーが出たら、.jazzy.yamlの記述にエラーがあると考えてよさそう。このファイルを編集中に、上記の`parse'エラー以外にもいろんなエラーが出たが、いずれも設定ファイルの構文ミスが原因だったと思われる。

同じように時間を使ってしまう人が、少しでも減りますように。


  1. iOSデバイスを12.2にしたら、Xcodeでデバッグ端末として使おうとしたときに、Xcode10.2が必要とエラーが出て使えないようになってしまった。Xcodeを10.2にしようと調べたら、Mojaveが必要だった。App StoreがXcodeのアップデートを知らせて来ないのを不思議に思っていたのだけど納得。 

69
28
7

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
69
28