简体   繁体   中英

Pod init error tool 'xcodebuild' requires Xcode

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>'
```

It needs to set your CocoaPod and command line tool version, in your Xcode:

Reset (Uninstall & install) cocoa pod:
Execute the following on your terminal to get the latest stable version:

sudo gem install cocoapods

Use keyword --pre to get the latest pre-release:

sudo gem install cocoapods --pre

How to set/reset Command Line Tool:
You can download latest command line tool from Apple Download Portal , if you have paid apple developer account/id.


Here are current beta and stable Xcode Tool and supporting command line tool download link. (Ensure you'are logged in using premium developer account on Apple Developer Account to access these links)

Xcode 10


Once you've latest command line tool installed in your system, set it from Xcode Menu.

(Xcode Menu Items) Xcode ▶ Preferences ▶ Location ▶ Command Line Tool ▶ Select appropriate command line tool

在此处输入图片说明


Try the same with Terminal App

Install Command Line Tools (using Terminal app):

xcode-select --install

Change the active directory:

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

I got this error when I updated my xcode version to 9.1. I fixed the error with the below command. In your terminal just add

Sudo gem install cocoapods --pre

and enter your mac password. Then try with

pod init

I have an another option to solved the issues. because of the issues happened in xcode 9.3, so i have create the project in xcode 9.2 , install the pod. and than after open the project in xcode 9.3 and start work on it.

I got the same issue with cocoapods. I have resolved this with -

rm -rf ~/.cocoapods/repos/trunk/

hope this may help to someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM