heyr
heyr

Reputation: 5794

Flutter build iOS on root of my flutter app does not work

Whenever I run this command from terminal: flutter build ios in the root of the project for my flutter app, I get back:

Cannot find "xcodebuild". Xcode 9.0 or greater is required to develop for iOS.

Encountered error while building for device. I have the lastest Xcode (Version 10.0).

Flutter doctor:

[✓] Flutter (Channel beta, v0.8.2, on Mac OS X 10.13.6 17G65, locale en-GB)
    • Flutter version 0.8.2 at /Users/h/flutter
    • Framework revision 5ab9e70727 (2 weeks ago), 2018-09-07 12:33:05 -0700
    • Engine revision 58a1894a1c
    • Dart version 2.1.0-dev.3.1.flutter-760a9690c2

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /Users/h/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[!] iOS toolchain - develop for iOS devices
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 24.2.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] Connected devices (1 available)
    • h iPhone • 77afb908fc6c490d3fca62cdde9a74ab4e45b4f0 • ios • iOS 11.4.1

! Doctor found issues in 1 category.

I assume the IOS issue is thrown as I am running Xcode from an external HD

Upvotes: 40

Views: 42613

Answers (8)

manglide
manglide

Reputation: 85

According to @matt-hamman

If your Xcode was updated to v14.1 and your Mac is running macOS 12.6, this will happen because the macOS SDK that xcodebuild is looking for happens to be MacOSX12.3.sdk while your OS has already been updated to 12.6.

Running xcode-select -p returns /Applications/Xcode.app/Contents/Developer, which is what Xcode 14 configured automatically. (Changing this via sudo xcode-select --switch /Library/Developer/CommandLineTools fixes git, but breaks other things in subtle ways (like some CocoaPods commands).)

To fix this issue, simply run:

sudo cp -R /Library/Developer/CommandLineTools/SDKs/MacOSX12* /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

Further details can be gleaned from the original answer here

Upvotes: 0

August Kimo
August Kimo

Reputation: 1771

If you already have Xcode and this error randomly appears, just run these commands, as recommended by Flutter Doctor:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

sudo xcodebuild -runFirstLaunch

Upvotes: 2

Navas Koya
Navas Koya

Reputation: 111

To fix it, go to Xcode->preferences->locations->set value for command Line tools.

Upvotes: -2

samuel samer
samuel samer

Reputation: 311

  1. Install Xcode (get it from https://developer.apple.com/xcode/) if you don't have it yet.
  2. Accept the Terms and Conditions.
  3. Ensure Xcode app is in the /Applications directory (NOT /Users/{user}/Applications).
  4. Point xcode-select to the Xcode app Developer directory using the following command:
  5. sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Reference: https://github.com/flutter/flutter/issues/6308

Upvotes: 0

Julian Re
Julian Re

Reputation: 1025

The source of my problem was that Flutter could not find the latest installed version of Xcode.

To fix it, go to Xcode->preferences->locations->set value for command Line tools.

Upvotes: 81

Mina Farid
Mina Farid

Reputation: 5887

Run the following commands in your terminal:

1- cd your_project_path

2- sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

3- sudo xcodebuild -license

4- open -a Simulator

5- flutter run

Upvotes: 16

ifteeVai
ifteeVai

Reputation: 61

If you Installed Xcode 10 manually via Apple Developer Download Center or Other Sources, then At first, RENAME your Xcode to the Version name you downloaded, like I downloaded the Xcode 10.1 version, so for me the renamed name would be Xcode10.1.app the .app extension is optional as it already has .app extension...

After that, paste this Command on your Terminal,

sudo xcode-select --switch /Applications/Xcode10.1.app/Contents/Developer

Note: the Xcode Version (i.e. Xcode10.1.app ) is Mendatory, if it's there good otherwise, Rename and add it, it's COMPLETELY SAFE and doesn't have any side effects

Upvotes: 6

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657937

The suggestion from flutter doctor -v is quite clear

✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
  Download at: https://developer.apple.com/xcode/download/
  Or install Xcode via the App Store.
  Once installed, run:
    sudo xcode-select --switch /Applications/Xcode.app/Contents/Develope

You could try starting Xcode and agree when it asks to install missing components.

Id suggest you try the dev or master channel where support for Xcode 10 should have landed. Otherwise check this suggestion https://github.com/flutter/flutter/issues/20685#issuecomment-413524718

Upvotes: 40

Related Questions