googlesamples / unity-jar-resolver

Unity plugin which resolves Android & iOS dependencies and performs version management
Other
1.21k stars 336 forks source link

[Bug] iOS Resolver: Failed to install CocoaPods for the current user #654

Open derwaldgeist opened 7 months ago

derwaldgeist commented 7 months ago

I just got my M3 MacBook Pro and am trying to get my existing Unity project up and running. After installing the Silicon version of Unity Editor, I opened my project for the first time. This resulted in an error message that Cocoapods cannot be installed

image image

I have upgraded my cocapods (1.14.2) and Ruby (3.2.2) installations, but still the problem persists. It seems as if EDM4U picks up an installation that was already pre-installed on the machine.

What's the issue repro rate? 100%

What happened? How can we make the problem occur?

Just install Unity on a fresh Apple Silicon MacBook and try to open an existing project using EDM4U.

google-oss-bot commented 7 months ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

derwaldgeist commented 7 months ago

I also found this Issue:

https://github.com/googlesamples/unity-jar-resolver/issues/589

which has been closed but without a real solution. I tried to set the UTF8 setting mentioned in the comments, but this did not work.

Plus, I tried to install cocoapods 1.10.2 as recommended in the comments as well, but this does not seem to be available for Silicon Macs, neither via sudo gem install nor via homebrew.

paulinon commented 7 months ago

Hi @derwaldgeist,

Have you installed Xcode and Xcode Command Line Tools? You'll need Xcode in order to build your app on an iOS device since Unity only generates the Xcode project. You can install Xcode Command Line Tools using this command:

xcode-select --install

I look forward to hearing from you soon.

remzisenel commented 7 months ago

I am in the same boat as the original poster.

$ xcode-select --install

xcode-select: note: Command line tools are already installed. Use "Software Update" in System Settings or the softwareupdate command line interface to install updates

osx Sonoma ships with ruby 2.6.10.210 and iOS Resolver uses the system shipped ruby version even when a newer ruby version is installed and configured in shell profile.

$ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin23]

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 3.4.10
  - RUBY VERSION: 3.2.2 (2023-03-30 patchlevel 53) [arm64-darwin23]
...
remzisenel commented 7 months ago

I confirmed my shell profile is loading correctly into Unity process by executing ruby --version and gem env through a process created within Unity runtime. I'm also using bash to make sure the shell is the same as the one being used by the iOS Resolver.

var process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = "bash";
...
process.Start();

Outputs:

'ruby --version' completed with code 0

ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin23]
'gem env' completed with code 0

RubyGems Environment:
  - RUBYGEMS VERSION: 3.4.10
  - RUBY VERSION: 3.2.2 (2023-03-30 patchlevel 53) [arm64-darwin23]
...
'echo $PATH' completed with code 0

[HOME_DIR]/.rbenv/shims:...

.rbenv/shims have symlinks to the ruby-3.2.2 environment

derwaldgeist commented 7 months ago

xcode-select --install

Yes, Xcode command line tools are already installed. But still, I cannot make it work. This did not happen on my Intel Mac, with the very same setup. Could it be that it is a Silicon Mac specific problem?

derwaldgeist commented 7 months ago

@remzisenel I guess you didn't find a solution yet, did you? This is driving me nuts... I get the same output from ruby -v and gem env as you, if I call them on the terminal. I'm using zsh, though, with the oh-my-zsh addon. This worked fine on my Intel Mac.

derwaldgeist commented 7 months ago

I've also checked my path now. It contains /opt/homebrew/opt/ruby/bin which correctly points to a ruby 3.2.2 executable, as well as a gem 3.4.22 executable.

The error dialog I am getting claims that it only finds ruby 2.6.10.210 instead. Wherever this version comes from. This is installed in /usr/bin. If I get these instructions right, this version shall not be removed because it is required by MacOS itself:

https://mac.install.guide/ruby/9.html

derwaldgeist commented 7 months ago

I tried to tell asdf to use ruby 3.2.2 inside the Unity project, but this did not help. Also tried to set Use Shell to Execute Cocoapod Tool in EDM4U to false, but this didn't have an effect either. Is there another way to tell EDM4U where to locate the right ruby version?

I've also checked bash and sh. All point to the 3.2.2 version.

derwaldgeist commented 7 months ago

I was abe to fix this using these instructions: https://forum.unity.com/threads/cocoapods-installation-failure-when-building-for-ios.1167700/#post-8793733

I guess the important part is this:

sudo arch -arm64 gem install -n /usr/local/bin cocoapods -v 1.10.2

I also tried it without the -v 1.10.2, and the more recent 1.14.2 seems to work as well.

However, this seems like a pretty odd workaround to me. Would appreciate a better solution.

remzisenel commented 7 months ago

I believe the root of the problem is that the resolvers are not using the right binaries in PATH. I couldn't figure out why yet.

I did get around the cocoapods problem by manually installing cocoapods through my own terminal, somewhat akin to what @derwaldgeist did - he installed (an older version of) cocoapods for the system ruby environment, I installed cocoapods manually for the newer rbenv installed ruby environment.

Olof-IL commented 7 months ago

I agree with @remzisenel

Spent a few hours trying to resolve this issue today, and yes, it seems no matter what I do, the iOS Resolver seems dead set on using the old outdated /usr/bin/ruby, even though I've installed 3.2.2 (tried both with homebrew and with rbenv)

It would be nice if the tool could be fixed to properly respect the path and use the correct version of ruby.

Olof-IL commented 7 months ago

I'll also share my workaround.

  1. Add /Users/YourUser/.gem/ruby/2.6.0/bin to your path, add this to your .zshrc: export PATH="$PATH:/Users/YourUser/.gem/ruby/2.6.0/bin"
  2. Manually install a version cocoapods compatible with 2.6.0 using the ruby version at /usr/bin:
    sudo /usr/bin/gem install cocoapods -v 1.12.1

Note! You must use at least 1.12.1 or it will not work to archive using XCode 14.3 or later.

But of course, the real fix is for Unity-Jar-Resolver to use the proper version of Ruby instead of only using /usr/bin/ruby, since the latest version of cocoapods is not compatible with 2.6.0

hantengx commented 6 months ago

I alse have this error. And add path to zsh is invaild. Then I foud add path to bash is ok! It seems that Unity uses the bash environment by default。

6ag commented 4 months ago

我将 .zshrc 中的相关配置拷贝到 .profile 中了一份,这样就可以使用我自己安装的 ruby 和 cocoapods 版本了。

juni1423 commented 2 months ago

I was abe to fix this using these instructions: https://forum.unity.com/threads/cocoapods-installation-failure-when-building-for-ios.1167700/#post-8793733

I guess the important part is this:

sudo arch -arm64 gem install -n /usr/local/bin cocoapods -v 1.10.2

I also tried it without the -v 1.10.2, and the more recent 1.14.2 seems to work as well.

However, this seems like a pretty odd workaround to me. Would appreciate a better solution.

yeah!!!! it save me. thanks