Hi, When I try to build my kmp-project, iOS XCode ...
# multiplatform
a
Hi, When I try to build my kmp-project, iOS XCode fails with an error:
Copy code
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)
  	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
  	from /usr/local/bin/pod:25:in `<main>'
  	from /usr/local/bin/ruby_executable_hooks:22:in `eval'
  	from /usr/local/bin/ruby_executable_hooks:22:in `<main>'
I think the problem is XCode uses the wrong version of Ruby. I don't understand why because I installed ruby 3.3.5. Command "_ruby -v_"prints "_ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin23]"._ I installed cocoapods:
Copy code
sudo gem install -n /usr/local/bin cocoapods -v 1.16.2;       
sudo gem install -n /usr/local/bin cocoapods-generate -v 2.2.5
My environment: Macbook M3 Max, MacOS 14.7.3, XCode 15.2.
f
Can you run kdoctor? Check if your env PATH is correct. if you run
pod --version
, the output should be 1.16.2
a
kdoctor:
Copy code
Environment diagnose (to see all details, use -v option):
[✓] Operation System
[✓] Java
[!] Android Studio
  ! Android Studio (AI-242.23726.103.2422.13016713)
    Location: /Users/alex/Applications/Android <http://Studio.app|Studio.app>
    Bundled Java: openjdk 21.0.5 2024-10-15
    Kotlin Plugin: 242.23726.103.2422.13016713-AS
    Kotlin Multiplatform Mobile Plugin: not installed
    Install Kotlin Multiplatform Mobile plugin - <https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile>
[✓] Xcode
[✓] CocoaPods

Conclusion:
  ✓ Your operation system is ready for Kotlin Multiplatform Mobile Development!
When I run
pod --version
, the output is 1.16.2
f
Xcode should work as it uses the same env as your terminal, unless something is override inside. It’s a new project ?
a
It's not a new project. This project builds on my another macbook successfully. I compared files "zprofile", "zshrc", "bash_profile", "bashrc" on both laptops, but they are the same.
f
If you run
ruby -v
the version is > 3.x ?
a
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin23]
f
weird, and xcode still doesn’t work?
a
what does your podfile look like? it seems to me that its malformed.
Copy code
can't find gem cocoapods (>= 0.a) with executable pod
I think cocoapods doesnt like characters in version numbers, so might be that you are referencing a non semantic version number?
f
try to delete the Podfile.lock
a
@Andrew Reed I don’t think the problem is Podfile because this project builds successfully on another laptop .
a
ah i didnt read that bit, so sounds most likely an environment issue. How did you install cocoapods? via brew or gem?
a
@François I deleted the Podfile.lock, but the problem remains :(
@Andrew Reed gem
a
can you do a gem uinstall of cocoapods?
Copy code
gem uninstall cocoapods
and see then re-install
f
//Start Instant promo 😄
Tired of CocoaPods, try using my alternative <https://frankois944.github.io/spm4Kmp/>
//End Instant promo
🙂 1
Yes, something wrong in the setup environment. The
brew
method is easier if you can
a
@Andrew Reed I have done it:
Copy code
gem uninstall cocoapods
sudo gem install -n /usr/local/bin cocoapods -v 1.16.2
but it didn't help :(
I don't understand why XCode uses system Ruby. I'm going to try to install cocoapods with
brew
.
a
Make sure you fully close xcode, ensure it doesnt show in activity monitor. Then load it back up, maybe its not got the latest path
a
From my experience, although you have new ruby installed, the path variable references to an older one. You need to add/replace the old one with new @Alex
a
I restarted my laptop and ran XCode build again. The problem remains. @Andrew Reed
a
can you find the generated pod file, just to see if there is anything odd
you could even try to manually do a pod install to see if it gets pass the fetching of the pod dependancies
a
@Amit Kairon I think so too, but I don't understand where the variable is. Which path variable does Xcode use?
a
you could wipe the old ruby directory and put a symlink there instead
a
I ran
pod install
locally (in terminal) and it completed successfully.
"you could wipe the old ruby directory" - Do you mean deleting system ruby? @Andrew Reed
I installed cocoapods with brew. It didn't help.
a
yeah, or atleast moving it for now. Then creating a symlink of that folder, that points to your new ruby
apps will be none the wiser, not great though tbh
a
I can't move or delete system ruby directory, because error "Operation not permitted" occurs. I used "sudo".
a
you should be able to from the terminal and using sudo - to be honest its not the best solution to your problem and could cause other issues.
just a random though, can you open a terminal and perform:
Copy code
open -n /Applications/Xcode-16.2.0.app
does it still use the wrong ruby?
edit where xcode is either Xcode.app or whatever version you have installed
a
I performed
open -n /Applications/Xcode.app
. The Xcode build failed with another error:
Copy code
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'base64' (>= 0) among 162 total gem(s) (Gem::MissingSpecError)
After that I performed
gem list
and gem 'base64' was found. I think this gem exists for Ruby 3.5, but doesn't exist for system Ruby 2.6.
a
brew will install a mew ruby but this ruby also needs to be on path variable
a
Where should I add the path of new Ruby?
f
When installing with brew, at the end, they print what you need to do
a
You need to add it to the path in your zshrc
a
It has been already added:
Copy code
export PATH="$PATH:$HOME/.rvm/bin"
export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"
export PATH="/Users/alex/.rvm/rubies/ruby-3.3.5/bin/ruby:$PATH"
a
so you are using rvm and ruby? - that last path? not sure you need it, i thought rvm did the magic
i would take out the last one and then use rvm to set your ruby version. So
Copy code
rvm use 3
Copy code
rvm --default use 3.3.5
a
so you are using rvm and ruby? - that last path?
I use
rvm
. I added this line because I thought it would help.
`rvm list`:
Copy code
=* ruby-3.3.5 [ arm64 ]

# => - current
# =* - current && default
# * - default
a
a slightly nuclear approach would be to remove rvm, just try with brew and install just one version of ruby.
i am using rvm on my current machine with no problems, so it might be a red herring
what is odd is that xcode seems to be running from a seperate session of your terminal, because its using the system ruby
Ive got one other approach, in the build phases in xcode, there is a script that it runs the gradle command which does all the magic, you could actually adjust the script to use your desired version of ruby.
to see if this works on your machine locally
basically looks like the issue is xcode when it runs gradle from build phases, runs in a terminal seperate from your logged in terminal
a
I performed
./gradlew :shared:podInstallSyntheticIos
in my terminal and after that Xcode built my project. 🎉 I'm not sure that it resolved my problem completely. I'm going to watch it. Anyway thank you for your time.
f
FYI, the official freeze of cocoapods is programmed on December 2nd 2026 😄
💯 1
a
Millenium bug vibes incoming
f
It won’t break the currently used before the freeze, so no panic.
a
until a new version of xcode is released and it breaks, everyone using the last trunk version and then expect tonnes of stackoverflow and github issues to be raised
f
People has 2 years to move to SPM which is now the standard, even on Flutter
a
still wont stop people
Alex - it confirms one thing, xcode executes the build phase in its own context, which i guess doesnt inherit all of your user path variables.
a
I think so too. Maybe, it's just a bug of XCode 15.2.