본문 바로가기

Android

KMM - Kdoctor의 cocoapods-generate 가 설치되지 않을 때

Kotlin Multiplatform Mobile - KMM 이 이제 Beta가 되었습니다.

 

"Kotlin Multiplatform Mobile has reached Beta and is on track to becoming Stable!"

https://twitter.com/kotlin/status/1579496189619503105?cxt=HHwWgoDUpc_av-srAAAA 

 

설치는 해 보아야 겠다 싶어 한 번 깔아보았는데요, (참고로 저는 Mac 환경입니다)

https://kotlinlang.org/docs/multiplatform-mobile-setup.html

 

1. 안드로이드 스튜디오 설치 (Android Studio Dolphin 2021.3.1 Patch 1 for Mac)

https://developer.android.com/studio

 

2. XCode 설치: App store에서 설치

https://apps.apple.com/kr/app/xcode/id497799835?mt=12 

 

3. JDK 설치:

https://www.oracle.com/java/technologies/downloads/

 

여기까지는 큰 문제 없이 설치되었습니다. 그 다음이 문제였는데,

"Cocoapods" 설치에서 에러가 나오네요...

https://github.com/square/cocoapods-generate#installation 여기에서 설치하라고 해서 스크립트를 

gem install cocoapods-generate

에러가 나옵니다.

Ignoring ffi-1.13.1 because its extensions are not built. Try: gem pristine ffi --version 1.13.1
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

 

----- 2023/04/18 업데이트 -----

 

 

https://stackoverflow.com/a/66556339/850347

에러 메시지에서 아예 위 답변을 따라하라는 가이드가 나옵니다.

 

  • Execute brew install ruby
  • Add export PATH=/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.0.0/bin:$PATH to your .zshrc (you can find your Homebrew installation directory with $(brew --prefix) if needed)
  • Execute source ~/.zshrc or restart your shell
  • Make sure you are using the correct ruby binary by executing which ruby (should be $(brew --prefix)/opt/ruby/bin/ruby)
  • Install CocoaPods with sudo gem install cocoapods
  • Make sure you are using the correct pod binary by executing which pod (should be $(brew --prefix)/lib/ruby/gems/3.0.0/bin/pod)
  • Make sure ethon is version 0.13.0 or more with gem info ethon, otherwise run sudo gem install ethon
  • Run pod install

 

 

 

----- 아래 내용은 오래된 내용으로, 2023/04/18에 다시 시도해 봤지만 동작하지 않았습니다 -----

 

 

에러를 해결하려면 Ruby를 설치하고, 이를 통해 cocoapods를 설치해야 하나봅니다. (왜?!)

https://stackoverflow.com/questions/51126403/you-dont-have-write-permissions-for-the-library-ruby-gems-2-3-0-directory-ma

 

아무튼 설치를 해봅니다. (brew는 이미 설치되어 있었고, 혹시 설치되어 있지 않으면 여기서 설치: https://brew.sh/)

brew install chruby ruby-install

ruby-install ruby 2.7.2

chruby 2.7.2

 

"뭘 이렇게 까지 많이 설치하나" 싶은 수많은 관련된 라이브러리가 설치되고, 결국 루비도 설치됩니다. (현재 최신버전 3.1.2이지만, cocoapods와 호환이 안되기 때문에 2.7.2을 설치해야 합니다)

 

 만약 3.0 이상을 설치하면 아래 에러가 뜨게되니 꼭 3.0 미만 버전을 설치하시기 바랍니다.

 More details: https://github.com/rubygems/rubygems/issues/4338
          Downgrade ruby to version < 3.0.0

 

그런데 "chruby" 이 명령어가 또 실행안됩니다. 찾아보니,

https://github.com/postmodern/chruby/issues/131

# Add the following to the ~/.bash_profile or ~/.zshrc file:
source $(brew --prefix)/opt/chruby/share/chruby/chruby.sh

현재 쓰고 있는 터미널 쉘의 종료에 따라, bash를 쓰고 있다면 bash_profile의 마지막 라인에, zsh을 쓰고 있다면 zshrc의 마지막 라인에 위 코드를 추가하고, 터미널을 재시작하라고 합니다.

 

재시작 후, 다시 "chruby 3.0.0" 을 실행하니 동작합니다. 그럼 다시 cocoapods를 설치 해 봅시다.

"gem install cocoapods-generate"

 

잘 설치됩니다. 그래서 다시 kdoctor를 실행해 보니, 이번에는 이런 에러가 나옵니다.

    * Cocoapods are installed via Homebrew but not linked to /usr/local/bin
          Execute 'brew link --overwrite cocoapods'

실행 해 보니, 경고가 나오네요.

> brew link --overwrite cocoapods

 

Warning: Already linked: /usr/local/Cellar/cocoapods/1.11.3
To relink, run:
  brew unlink cocoapods && brew link cocoapods

다시 가이드대로 실행 해 봅니다.

> brew unlink cocoapods && brew link cocoapods

 

이후에도 잘 안됩니다. 그래서 터미널을 껐다 켜 보았더니...

 

됩니다?

왜 되는지 모르겠지만 일단 됩니다. "System ruby is currently used" 메시지가 좀 마음에 걸리고, 루비 버전을 바꾸면 (chruby 2.7.2) 또 다시 cocoapods-generate에 오류가 있다고 나오지만.... 일단은 이상 없다고 나옵니다.

 

 

성공인지 잘 모르겠네요. 아무튼 체크박스는 모두 채웠습니다.

 

 

----- 위 내용은 오래된 내용으로, 2023/04/18에 다시 시도해 봤지만 동작하지 않았습니다 -----