Pod init error tool 'xcodebuild' requires Xcode

时间:2018-04-18 18:08:46

标签: ios xcode cocoapods command-line-tool

Im trying to run pod init command on my new project. It has never happened to me before. The things I have tried to fix it are:

  • Closing Xcode
  • Creating a new project
  • Restarting my computer

The error I get in the console is:

error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance 

### Command

```
/usr/local/bin/pod init
```

### Report

* What did you do?

* What did you expect to happen?

* What happened instead?


### Stack

```
   CocoaPods : 1.3.1
        Ruby : ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]
    RubyGems : 2.5.2
        Host : Mac OS X 10.13.4 (17E199)
       Xcode :  ()
         Git : git version 2.15.1 (Apple Git-101)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ ed5bf5bee99a1909bcc8fb8ffa39fb08d1af6bc8
```

### Plugins

```
cocoapods-deintegrate : 1.0.1
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.0.0
cocoapods-trunk       : 1.3.0
cocoapods-try         : 1.1.0
```

### Error

```
RuntimeError - [Xcodeproj] Unknown object version.
/Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.4/lib/xcodeproj/project.rb:217:in `initialize_from_file'
/Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.4/lib/xcodeproj/project.rb:102:in `open'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/command/init.rb:41:in `validate!'
/Library/Ruby/Gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:333:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:22:in `load'
/usr/local/bin/pod:22:in `<main>'
```

4 个答案:

答案 0 :(得分:7)

需要在Xcode中设置CocoaPod和命令行工具版本:

重置(卸载并安装)cocoa pod:
在终端上执行以下命令以获得最新的稳定版本:

sudo gem install cocoapods

使用关键字--pre获取最新的预发布版本:

sudo gem install cocoapods --pre

如何设置/重置命令行工具
如果您已经支付了苹果开发者帐户/身份证,可以从Apple Download Portal下载最新的命令行工具。


这是目前的测试版和稳定的Xcode工具以及支持命令行工具下载链接。 (确保您使用Apple Developer帐户中的高级开发者帐户登录以访问这些链接)

  

Xcode 10

     

在系统中安装了最新的命令行工具后,请从Xcode菜单中进行设置。

  

(Xcode菜单项)Xcode▶首选项▶位置▶命令行工具▶选择合适的命令行工具

enter image description here

尝试使用终端应用

安装命令行工具(使用终端应用程序):

xcode-select --install

更改活动目录:

sudo xcode-select -switch /Library/Developer/CommandLineTools

答案 1 :(得分:0)

我将xcode版本更新为9.1时出现此错误。 我用下面的命令修复了错误。在您的终端中添加

Sudo gem install cocoapods --pre

并输入您的mac密码。然后尝试

pod init

答案 2 :(得分:0)

我还有另一个解决问题的方法。因为xcode 9.3中发生的问题,所以我在xcode 9.2中创建了项目,安装了pod。而不是在xcode 9.3中打开项目并开始工作。

答案 3 :(得分:0)

cocoapods也遇到了同样的问题。我已经用-

解决了这个问题
rm -rf ~/.cocoapods/repos/trunk/

希望这对某人有帮助。