Ankush
Ankush

Reputation: 2555

Xcode ruby runscript can not find gem

Xcode: 9.3.1

OS: macOS High Sierra 10.13.4

I am and iOS developer and I am not familiar with ruby at all.

I am using a run-script in my Xcode project which uses a ruby gem called 'xcodeproj'. Before everything was working, But I updated my macOS and now this runscript is not able to find gem 'xcodeproj'

When I try to build my project it shows following error

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- xcodeproj (LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' 

I went to the path which is shown in the above error, and there was no xcodeproj gem files, even after that I installed gem install xcodeproj it is being installed somewhere else. This is the output on my terminal

xxx-MacBook-Pro:~ user$ gem list

*** LOCAL GEMS ***

atomos (0.1.2)
bigdecimal (default: 1.3.4)
bundler (default: 1.16.1)
CFPropertyList (3.0.0)
claide (1.0.2)
cmath (default: 1.0.0)
colored2 (3.1.2)
csv (default: 1.0.0)
date (default: 1.0.0)
dbm (default: 1.0.0)
etc (default: 1.0.0)
fcntl (default: 1.0.0)
fiddle (default: 1.0.0)
fileutils (default: 1.0.2)
io-console (default: 0.4.6)
ipaddr (default: 1.2.0)
json (default: 2.1.0)
nanaimo (0.2.5)
openssl (default: 2.1.0)
psych (default: 3.0.2)
rdoc (default: 6.0.1)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
stringio (default: 0.0.1)
strscan (default: 1.0.0)
webrick (default: 1.4.2)
xcodeproj (1.5.9)
zlib (default: 1.0.0)

Moreover, when I try to execute my ruby runscript via terminal it shows no error (And via xcode it fails).

Apparently, gem xcodeproj has been installed in my macOS but it is not under Ruby.framwork and I think that's why my xcode's runscript is failing at build time. Hese is my runscript enter image description here

The screenshot of error in Xcode enter image description here

Any help is highly appreciated, guys :)

Upvotes: 1

Views: 2431

Answers (1)

Ankush
Ankush

Reputation: 2555

Okay I found the bug in my code.

There were two ruby versions one for the system i.e /System/Library/Frameworks/Ruby.framework/Versions/2.3 (this is for the root system, which comes with macOS) and other was /usr/local/Cellar/ruby/2.5.1/lib/ruby (Not sure what is this for, My guess is that it is separate ruby environment for new version 2.5.1, I might have installed it in past)

In my runscript's shell, I had /usr/bin/ruby which has ruby executable file for system's ruby /System/Library/Frameworks/Ruby.framework

I checked the ruby environment by command gem environment, And it gave the output

RubyGems Environment:
  - RUBYGEMS VERSION: 2.7.6
  - RUBY VERSION: 2.5.1 (2018-03-29 patchlevel 57) [x86_64-darwin17]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.5.0
  - USER INSTALLATION DIRECTORY: /Users/xxx/.gem/ruby/2.5.0
  - RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - SPEC CACHE DIRECTORY: /Users/xxx/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /usr/local/Cellar/ruby/2.5.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-17

Here EXECUTABLE DIRECTORY: /usr/local/bin and I had a different path for my ruby executable which I specified in my runscript's shell (/usr/bin/ruby) so I changed /usr/bin/ruby to /usr/local/bin/ruby and it is working.

As my gem was being installed in updated version of ruby(2.5) /usr/local/Cellar/ruby/2.5.1/lib/ruby instead of old system's ruby (2.3)/System/Library/Frameworks/Ruby.framework so now as I provided the executable ruby path of the latest ruby version, in which gem was installed, it is working fine.

Upvotes: 1

Related Questions