37

Suddenly it stops building application in device. In simulator its working but when I connect the device and try to run it in device it gives me an error:

Could not build module UIKit

I tries a lot but couldn't solve it.

Yurii
  • 4,811
  • 7
  • 32
  • 41
Hardik Shah
  • 1,683
  • 1
  • 11
  • 20
  • 3
    Sounds a bit as if your iOS SDK (device part) got fried. First thing that comes to mind is reinstalling Xcode. – Till Nov 23 '13 at 15:24
  • 2
    @Till yes you are right, i reinstall the xcode and now it works thanks – Hardik Shah Nov 25 '13 at 04:40
  • 1
    Reinstalling the Xcode worked – Jassi Mar 10 '15 at 11:05
  • Tried everything, can't seem to resolve it in XCode7.3beta. Any ideas? – Yogesh Maheshwari Feb 23 '16 at 12:16
  • Just a tip: This occurred when I accidentally typed something in `UICollectionView.h`, replacing the particular file physically inside sdk folder with another fresh copy of this header from my friend's sdk solved this. You could also replace the entire sdk folder. This will save you from re-installing. – Adil Soomro Feb 17 '17 at 12:27
  • You can copy the `UIKit` framework from other xcode (same version) and replace your `UIKit`... it will work. – TheTiger Apr 04 '17 at 13:46

25 Answers25

24

A full clean + deleting the derived data worked for me.

Be sure to fix any code that may be broken because UIKit cannot be installed, before the clean and build.

So, for example, if you are trying to reference UICollectionViewController, and need UIKit to reference it, comment out the code that is using UICollectionViewController, comment out the import for UIKit.

Then clean, build. Now uncomment import UIKIt, build. NOW uncomment UICollectionViewController code, build again.

Raphael Oliveira
  • 7,751
  • 5
  • 47
  • 55
24

Please don't make the same mistake like I did. In my case, I accidentally typed some words into Foundation framework file.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
chinnawatp
  • 1,430
  • 16
  • 15
  • 1
    Haha. LOL. That's what I did. – Rishab Sep 10 '16 at 14:17
  • 2
    Bizarre, same problem. Why are those files even editable? – zeroimpl Oct 10 '16 at 00:59
  • 1
    Oh man... That's exactly what I did! Thanks so much. I'm just surprised because my XCode 8 doesn’t show that alert when I accidentaly edit a system header file... – cicerocamargo Oct 19 '16 at 17:18
  • 1
    just remove what you accidentally typed from foundation framework file. – chinnawatp Oct 24 '16 at 03:25
  • 1
    Same issue here. Insane how fast my build went FUBAR. The errors should point you to the altered file. Fixed it by copying the same header file, but from the "normal" iOS framework instead of the simulator (or vice versa). Use the breadcrumb above the code to navigate, copy-paste and voilá. – CloakedEddy Oct 27 '16 at 15:30
  • I accidentally command-clicked a UIKit header name, then inadvertently pasted into the file that opened and closed it before I realized what was happening. (Working too many hours I guess!) I restored the file as in the previous comment, but pulled the file from a hard drive backup rather than from the simulator framework. – arlomedia Dec 06 '16 at 21:03
  • I'm wondering why Foundation framework can be changed by us.they should be locked.I just run into this mistake. – Randall Wang Aug 04 '17 at 06:26
  • I never type in UIKit headers. Xcode crashed because of git, then I restart Xcode, which report the error when building some project; however, other projects compiles OK. – DawnSong Sep 17 '19 at 16:12
12

Something that might help would be to set the Derived Data location to "Relative" in XCode preferences, then Clean & Build

XCode derived data location

abinop
  • 3,153
  • 5
  • 32
  • 46
  • But the application size is increasing. Its create a Derived data folder in Application and its size is 67 MB. :( – Soumya Ranjan Oct 30 '14 at 12:42
  • Should you need to set this value using a script, you can read/write it using plutil: `plutil -extract IDECustomDerivedDataLocation xml1 -o - ~/Library/Preferences/com.apple.dt.Xcode.plist` – ZeWaren May 16 '18 at 07:30
9

For some reason your UIKit.framework is corrupted, either copy a working UIKit.framework from somewhere else into

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks

Or reinstall Xcode the fix the issue.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
tamir007
  • 178
  • 2
  • 7
  • Correct, This occurred when I accidentally typed something in `UICollectionView.h`. Instead of reinstalling xcode, replacing the particular file physically inside sdk folder with another fresh copy of this header from my friend's sdk solved this. – Adil Soomro Feb 17 '17 at 12:29
  • Thanks mate! I was working on a pod for tvOS and didn't pass validation spec because I had UIKit.framework corrupted. Just update UIKit.framework on `/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator10.1.sdk/System/Library/Frameworks ` folder and every thing works like a charm. – AlbertoMDF May 18 '17 at 11:12
  • Replacing UICollectionView.h with https://raw.githubusercontent.com/PeqNP/ObjC-Stub/master/bin/UIKit.framework/Headers/UICollectionViewLayout.h Helped me, just locate UICollectionView with Shift+CMD+O – Oleh Kudinov Jul 14 '17 at 17:13
  • Or from here https://github.com/theos/sdks/blob/master/iPhoneOS10.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UICollectionView.h – Oleh Kudinov Jul 14 '17 at 17:20
7

I accidentally edited the Foundation framework file so UIKit.framework got corrupted. The only solution is recover the original.

You have two ways to achieve the same:

  • Just reinstall Xcode. OR

  • copy the Framework from another machine with the same XCode version and paste into yours.

Location:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks
Lal Krishna
  • 15,485
  • 6
  • 64
  • 84
4

If you have two Xcode then uninstall both and again install Xcode. It worked for me.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
vikas prajapati
  • 1,868
  • 2
  • 18
  • 26
3

If cleaning the project and deleting the 'derived data' doesn't work, try to change the 'Deployment target' (at 'General' tab) from 7.0 to 7.1

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Yedidya Reiss
  • 5,316
  • 2
  • 17
  • 19
3

Check whether the appropriate target is selected or not from the "active scheme selector". Selecting "Generic iOS Device" solved my problem.

Click to select simulator

enter image description here

Select "Generic iOS Device":

enter image description here

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
2

Make sure none of the files are edited in the UIKit framework located inside Xcode.

psobko
  • 1,548
  • 1
  • 14
  • 24
1

Cleaning Derived data worked for me

hsafarya
  • 1,043
  • 1
  • 10
  • 21
1

Check the tool chains installed and select the right xcode tool chain. In my case i changed it from Swift 4.0 to xcode 9.2 and it worked.

Max
  • 5,380
  • 6
  • 42
  • 66
1

In my case, after cleaning the project, only restarting my Mac helps.

Ely
  • 8,259
  • 1
  • 54
  • 67
0

Cleaning the project and restart xCode worked for me.

svvoff
  • 289
  • 2
  • 14
0

I am also facing this issue for very long time and after trying all the suggestions given in the different portals, i came to know that the issue is with the device you want to run the application. Device have latest iOS and your Xcode is not supporting that iOS.

For example you have Xcode 7.2 and want to run the application on device which have iOS 9.2.1. So you only need to update your Xcode.

And one more thing Base Sdk in Build Settings is always greater or equal to the software version number on your development device.

Waris Shams
  • 1,606
  • 1
  • 15
  • 27
0

Already tried all the solutions above. I still could not solve my problem. So I uninstall the Xcode and reinstall it. It worked magically.hope this helps.

0

Suppose you have changed or deleted anything in the UIKit framework, then shows this error.

If you are able to find that class or .h file to be changed or deleted, then replace that whole file content in that .h file from other system's Xcode (confirm that should be similar Xcode version).

For example, In UIView.h file - I have deleted a method and closed and opened the Xcode. Then I couldn't reverted that code.

Dsh
  • 228
  • 4
  • 12
0

I tried with delete derived data,delete application from project list but when i delete xcode and install new one its working so its best way just delete xcode and install new xcode.

saurabh rathod
  • 1,090
  • 7
  • 7
0

This error happened to me when I accidentally modified the uikit framework. Removing and re-adding the uikit framework in link binary with library, cleaning derived data and restarting xcode didn't work. I don't want to uninstall my xcode so I tried to copy codes of the class that I might have modified from other pc with xcode that works fine and paste it to mine. It worked!

0

If your project builds for another target (e.g. it builds for simulator and NOT your device), then it's confirmed you accidentally edited one of the header files of the frameworks for that target. The affected framework is the one you are receiving compiling errors for.

Thomas Elliot
  • 659
  • 8
  • 12
0

It worked for me after remove all folders in DerivedData folder.

jawad
  • 775
  • 6
  • 16
0

My Issue causing this same error was due to working in a workspace created by coco pods, somehow the link to the UiKit Framework had been lost from the original project.

To solve this i just reopened the xCode project not the workspace and re added the missing UIKit framework, saved the project and closed it, re opened my workspace for the project and the annoying nag messages caused by this were fixed. Hopefully this helps someone else.

0

I had this issue, and I set Device on Generic iOS Device, clean project, make build. Then I switched device to my real device and run project. The error does not appear.

Fa.Shapouri
  • 988
  • 2
  • 12
  • 30
0

Cleaning some unnecessary Xcode data using DevCleaner for Xcode app worked for me.

Nazariy Vlizlo
  • 778
  • 7
  • 16
0

My error was a wrong version of command line tools - go to Preferences->Locations and change the command line tools version - quit xcode and try again.

Declan Land
  • 639
  • 2
  • 11
  • 27
0

I had the same problem when my Mac's storage was full. You should check your available storage.

Rémi B.
  • 2,410
  • 11
  • 17