Kotlin Multiplatformの環境セットアップ覚え書き

こんにちは、トリです。
Kotlin Multiplatformを使ってみようと思い立ち、ひとまず環境のセットアップまで終えました。

サクサク終わるかと思ったらスムーズに進まなかったので、環境設定を備忘録として残しておこうと思います。

公式ドキュメントを参考に進めました。

インストールが必要なツール

  • Android Studio

  • Xcode

  • Kotlin Multiplatform plugin(Android Studioでインストール)

  • Kotlin plugin(Android Studioでインストール)

インストールすると便利なツール

macOSの場合、「KDoctor」という環境チェックツールが使用できます。
Homebrewでインストールしました。

% brew install kdoctor

KDoctorで環境の確認

さっそくKotlin Multiplatformが使用できる状態かKDoctorで確認してみます。

% kdoctor
Environment diagnose (to see all details, use -v option):
[✓] Operation System
[✖] Java
  ✖ Java not found
    Get JDK from https://www.oracle.com/java/technologies/javase-downloads.html
[✓] Android Studio
[✓] Xcode
[!] CocoaPods
  ! CocoaPods configuration is not required, but highly recommended for full-fledged development
  ✖ System ruby is currently used
    CocoaPods is not compatible with system ruby installation on Apple M1 computers.
    Please install ruby via Homebrew, rvm, rbenv or other tool and make it default
    Detailed information: https://stackoverflow.com/questions/64901180/how-to-run-cocoapods-on-apple-silicon-m1/66556339#66556339
  ✖ CocoaPods requires your terminal to be using UTF-8 encoding.
    Consider adding the following to ~/.zprofile
    export LANG=en_US.UTF-8
    export LC_ALL=en_US.UTF-8

JavaCocoaPodで引っかかりました。
Javaのエラーを解消すれば使用できそうですが、せっかくなのでCocoaPodも含めて直します。

Java not foundの解消

URLからJDKをGETする指示がありますが、Android StudioをインストールしたときにJDKも付いているので、既存JDKをJAVA_HOMEに設定します。

export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home
pathはAndroid StudioのSettingsから確認

Java not foundが解消されました。

% kdoctor
Environment diagnose (to see all details, use -v option):
[✓] Operation System
[✓] Java
[✓] Android Studio
[✓] Xcode
[!] CocoaPods
  ! CocoaPods configuration is not required, but highly recommended for full-fledged development
  ✖ System ruby is currently used
    CocoaPods is not compatible with system ruby installation on Apple M1 computers.
    Please install ruby via Homebrew, rvm, rbenv or other tool and make it default
    Detailed information: https://stackoverflow.com/questions/64901180/how-to-run-cocoapods-on-apple-silicon-m1/66556339#66556339
  ✖ CocoaPods requires your terminal to be using UTF-8 encoding.
    Consider adding the following to ~/.zprofile
    export LANG=en_US.UTF-8
    export LC_ALL=en_US.UTF-8

System ruby is currently usedの解消

Apple M1のMacを使用している場合、CocoaPodsとシステムRubyに互換性がないエラーになります。
メッセージにもある通り、別途Rubyをインストールしましょう。
今回はHomebrewでrbenvを入れて、Rubyをインストールしました。

% rbenv install 3.3.3
% rbenv global 3.3.3

% which ruby
/Users/ユーザー名/.rbenv/shims/ruby
% ruby -v
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [arm64-darwin23]

System ruby is currently usedが解消されました。

% kdoctor
Environment diagnose (to see all details, use -v option):
[✓] Operation System
[✓] Java
[✓] Android Studio
[✓] Xcode
[!] CocoaPods
  ! CocoaPods configuration is not required, but highly recommended for full-fledged development
  ✖ CocoaPods requires your terminal to be using UTF-8 encoding.
    Consider adding the following to ~/.zprofile
    export LANG=en_US.UTF-8
    export LC_ALL=en_US.UTF-8

CocoaPods requires your terminal to be using UTF-8 encodingの解消

下記のUTF-8設定を .zprofileに追加すれば解消されます。

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
% kdoctor 
Environment diagnose (to see all details, use -v option):
[✓] Operation System
[✓] Java
[✓] Android Studio
[✓] Xcode
[✓] CocoaPods

Conclusion:
  ✓ Your operation system is ready for Kotlin Multiplatform Mobile Development!

これでエラーがなくなりました!
さっそく楽しいKotlin Multiplatformライフを送ろうと思います。

この記事が気に入ったらサポートをしてみませんか?