Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Install Xcodeproj For NativeScript iOS Development On Mac OS

TwitterFacebookRedditLinkedInHacker News

I’ve been developing Android applications for quite some time, but with all the various cross platform or hybrid web frameworks available, I’ve slowly been drawn into developing iOS applications as well. I’ve touched iOS here and there, whether it be with Ionic Framework or Telerik NativeScript, but never really did much with it or learned how it ticked. This story is around the Xcodeproj tool for managing Xcode projects with Ruby.

Recently Telerik NativeScript, a framework I’ve been using heavily, decided to start requiring Xcodeproj, something it didn’t require at the beginning. This prevented me from being able to build or run for iOS until I got it installed. We’re going to take a look at what needs to be done to install Xcodeproj on Mac OS.

Let’s be clear, Xcodeproj is not specific to NativeScript. It is a pretty standard thing in the iOS development world and is a valuable item to have installed.

Before we get too deep into things, let’s get a definition of what Xcodeproj is. Per the project page on GitHub:

Xcodeproj lets you create and modify Xcode projects from Ruby. Script boring management tasks or build Xcode-friendly libraries. Also includes support for Xcode workspaces (.xcworkspace) and configuration files (.xcconfig).

Most of what comes next is going to be based around my short NativeScript story, but it should hold true under any scenario. When I tried to build for iOS, I encountered the following error in my Terminal:

Command failed: ruby -e "require 'xcodeproj'; Xcodeproj::Config.new('/Users/nraboy/Desktop/test/platforms/ios/plugins-debug.xcconfig').merge(Xcodeproj::Config.new('/Users/nraboy/Desktop/test/app/App_Resources/iOS/build.xcconfig')).save_as(Pathname.new('/Users/nraboy/Desktop/test/platforms/ios/plugins-debug.xcconfig'))"
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- xcodeproj (LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

Right from the start, I could tell that something was going on with xcodeproj and it included Ruby. Well, Xcodeproj requires Ruby and I can only assume that the NativeScript CLI was using Ruby to generate iOS projects.

Fixing this error was not difficult to do. We want to do is install this xcodeproj Gem. Your Mac should come with Ruby installed out of the box, so no need to install it. To install the xcodeproj Gem, execute the following from your Terminal:

sudo gem install xcodeproj

Notice you will need to use sudo since administrator privileges are required.

When I went to try to build my project again, it worked without issue. The error seemed a bit nasty, but it only required a single line to fix it.

Conclusion

We just saw how to install Xcodeproj, a tool that allows you to create and manage Xcode projects from Ruby. Now my scenario was specific to NativeScript, but it is certainly not the only scenario where this tool would be useful. I assume that NativeScript was using Ruby to generate iOS projects, something probably pretty common with a lot of frameworks.

Nic Raboy

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in C#, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Unity. Nic writes about his development experiences related to making web and mobile development easier to understand.