LoginSignup
19
2

More than 1 year has passed since last update.

【Flutter】macOSのクライアントアプリを作る

Last updated at Posted at 2022-12-18

Flutter 3.0がリリースされて久しく立ちますが、stableになったmacOSのアプリをビルドしたことがなかったので、今回試しにビルドしてみました。

環境

macOS Ventura 13.0.1 (Intel)

% flutter --version
Flutter 3.3.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 4f9d92fbbd (3 months ago) • 2022-09-06 17:54:53 -0700
Engine • revision 3efdf03e73
Tools • Dart 2.18.0 • DevTools 2.15.0

とりあえずビルドしてみる

まずは適当にプロジェクトを作成します。

flutter create <project name>

いきなりビルドしてみます。

flutter run -d macos

色々エラーが出ましたが、とりあえずこの状態で動きはしました。iOS/Androidと比べてもビルド自体早い気がします:thinking:
スクリーンショット 2022-12-18 22.35.59.png

いとも簡単にビルドできてしまいました、、、本当すごいですね。

エラー対応

このままだとあまりにも内容がないので、プロジェクトを作って初期状態で発生するエラーに対応してみます。
まずは以下のエラーです。

2022-12-18 22:49:30.788 xcodebuild[45891:792148]  DVTErrorPresenter: Unable to load simulator devices.
Domain: DVTCoreSimulatorAdditionsErrorDomain
Code: 3
Failure Reason: The version of the CoreSimulator framework installed on this Mac is out-of-date and not supported by this version of Xcode.
Recovery Suggestion: Please ensure that you have installed all available updates to your Mac's software, and that you are running the most recent version of Xcode supported by macOS.
--
CoreSimulator is out of date. Current version (857.13.0) is older than build version (857.14.0).
Domain: DVTCoreSimulatorAdditionsErrorDomain
Code: 3
--
2022-12-18 22:49:30.789 xcodebuild[45891:792148]  iOSSimulator: [SimServiceContext sharedServiceContextForDeveloperDir:error:] returned nil (Error Domain=DVTCoreSimulatorAdditionsErrorDomain Code=3 "CoreSimulator is out of date. Current version (857.13.0) is older than build version (857.14.0)." UserInfo={NSLocalizedDescription=CoreSimulator is out of date. Current version (857.13.0) is older than build version (857.14.0).}). Simulator device support disabled.

これは以下の記事を参考に、XCodeを一度開いてシミュレーターを更新すると治りました。
Fixing CoreSimulator is out of date | Apple Developer Forums

次に以下のエラーに対応します。

/Users/<user name>/path/to/project/macos/Runner.xcodeproj: warning: The macOS deployment target 'MACOSX_DEPLOYMENT_TARGET' is set to 10.11, but the range of supported deployment target versions is 10.13 to 13.1.99. (in target 'Flutter Assemble' from project 'Runner')
/Users/<user name>/path/to/project/macos/Runner.xcodeproj: warning: The macOS deployment target 'MACOSX_DEPLOYMENT_TARGET' is set to 10.11, but the range of supported deployment target versions is 10.13 to 13.1.99. (in target 'Runner' from project 'Runner')

このエラーは以下の二箇所のバージョンを13.0に上げることで解消しました。
Finderでプロジェクトルートからmacosフォルダの中のRunner.xcworkspaceを開きます。

  • TARGETS->Runner->General->Minimum Deployments->macOS
    スクリーンショット 2022-12-18 22.57.54.png

  • PROJECT->Runner->Info->Deployment Target->macOS Deployment Target
    スクリーンショット 2022-12-18 22.59.30.png

最後にこちらに対応します。

warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Runner' from project 'Runner')

これはwarningなので対応しなくてもいいかもですが、一応言われたとおりにチェックを外してみることにしました。

  • TARGET->Runner->BuildPhases->Run ScriptBased on dependency analysisのチェックを外します。
    スクリーンショット 2022-12-18 23.04.48.png

これで無事エラーやワーニングなくビルドが通るようになりました :tada:

% flutter run -d macos
Launching lib/main.dart on macOS in debug mode...
Building macOS application...                                           
Syncing files to device macOS...                                    83ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

💪 Running with sound null safety 💪

An Observatory debugger and profiler on macOS is available at: http://127.0.0.1:63516/XXXXXXXX=/
The Flutter DevTools debugger and profiler on macOS is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:63516/XXXXXXXX=/

まとめ

今回初めてstableになったmacOSのビルドを行ってみましたが、iOS/Androidのアプリやwebに比べて、とても簡単に動かせた印象でした。(エラーやワーニングは無視してもとりあえず動いたので。)

参考

19
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
2