プログラマーのメモ書き

伊勢在住のプログラマーが気になることを気ままにメモったブログです

Mac mini (2018) を修理しました

3年ほど前に iPhone 向けアプリ開発のために購入した Mac mini (2018) ですが、アプリ開発で使っているだけなので、使う機会はなかなか少ないです。最近、この Mac mini を修理して、使えるように復旧することになったので、その顛末をメモっておきます。

症状

先月ぐらいから久しぶりに触っていたのですが、どうも調子がおかしい。

  • 時々、電源が落ちている
  • 果ては、使っているときにいきなり落ちる

ということが結構頻繁に起きるようになってきました。

一度、 Apple のサポートに電話すると、電源コンセントを抜いて 10 秒ほど待ってから再度電源を入れてみてください。と言われて、その通りにしたところ、なんと、問題なく起動しました。今まで自分で同じこと何度かやっても駄目だったんだけどなー。

まあ、症状がその場で治ってしまったので、その時はそのまま終わりです。

ですが、その後1週間程度は普通に使えてたんですが、また同じ現象で起動できなくなりました。やっぱりね。

諦めて、 Appleのサポートに連絡したところ、

  • セーフモード
  • OS 再インストール

を試そうとしたのですが、どちらも起動できずに結局ハードウェア修理となりました。

修理を依頼

今住んでいるところの最寄りの修理店だと、津市にあるカメラのキタムラになります。 自宅からだと車で1時間弱程度かかるのですが、まあ致し方ないということで、その日のうちに予約を入れて、現物を持参しました。

幸か不幸か店頭でも同じ現象が再現できたので、 Apple に修理という運びとなりました。

結局、メモリのハードウェア故障だったようで、メモリを交換して修理から帰ってきました。期間は思ったよりも早くて1週間もかかりませんでした。金額も当初の見積もりよりは安く済んだので、ちょっとだけ助かりました。

バックアップ

一応、修理に持ち込む前、前述した起動したタイミングでバックアップを取っておきました。

といっても、ソースコードのリポジトリは Bitbucket で管理しているし、 Mac 上で作成したデータもほとんどない状態です。

念のため、アプリ配布の際に必要になる(はずの) Xcode の証明書だけバックアップとっておきます。このバックアップは、

Export signing certificates and provisioning profiles

を参考に取得して、仕事場の NAS に保存しておきました。

復旧作業

メモリの交換だけかな?と思ってましたが、残念ながら、 OS も再セットアップされていました。まあ、致し方ないですね。

ということで、ハードが治ったはずなので、開発に使えるように復旧作業をしました。

開発機なので、ソフトはそんなに入れてなくて、下記のものぐらいを再インストールしておきます。

  • SourceTree
  • Xcode
  • Flutter SDK

SourceTree のセットアップ

作業時の最新版 4.2.2 をインストールします。

こちらの記事に書いたように、 Bitbucket のリポジトリにアクセスできるようにアカウントをセットアップしました。

セットアップが無事に済んだら、 Bitbucket のリポジトリからクローンしておきます。なお、以下の画面出力等のプロジェクト名などは適宜変更していますのであしからず。

Xcode のセットアップ

次に、作業時の最新版の Xcode 14.3 をインストールします。

で、 SourceTree でクローンした flutter プロジェクトの ios フォルダにある Runner.xcodeproj を開いてみます。 問題なく開くことができたので、とりあえずOKとします。

あと、ビルドに必要となるアカウントをインポートしておきます。

アカウント(証明書)のインポート

修理前に取得した証明書をインポートします。

左側のナビゲーターエリアで Runner を選択して、 Signing & Capabilities を選択し、 Team を見ると未入力になっています。ここで、ドロップダウンリストを表示して、『Add an Account...』を選択します。

(上記の画面はインポート後のものなので、表示される内容がちょっと違ってます)

この時、下記の画面が表示されますが、

『Cancel』を押して無視します。

次に表示されたダイアログの、『Accounts』タブを選択すると、画面下部に『Import Apple Id and Code Siging Assets...』とあるので、これを選択します。

(これもアカウントインポート後の画面なので、ちょっと異なってます)

エクスポート済みのファイルを選択するダイアログが出るので、保存しておいたファイルを選びます。パスワードを求められますので、証明書を作成した際に設定したパスワードを入力します。問題がなければ、『Team』のところにアカウント名(チーム名)が表示されます。

なお、インポート直後だと、

のように、

Revoke Certificate

と証明書の再発行が必要っぽい表示が出てたので、ちょっと焦ったのですが、 Xcode を再起動したらこの表示は消えてました。

Flutter SDK のセットアップ

次に、作業時の最新版の Flutter SDK 3.7.12 をインストールします。インストールができたら、下記の記事を参考に、ターミナルで path を通しておきます。

macOS install | Flutter

mor@morijunichinoMac-mini ~ % touch .zshrc
mor@morijunichinoMac-mini ~ % cat .zshrc

# add flutter path, Junichi MORI, 2023/5/8

export PATH="$PATH:$HOME/bin:$HOME/bin/flutter/bin"

mor@morijunichinoMac-mini ~ % 

同じく、ターミナルで flutter doctor を実行しておきます。

mor@morijunichinoMac-mini ~ % flutter doctor
Running "flutter pub get" in flutter_tools...
Resolving dependencies in bin/flutter-3.7.12-stable/packages/flutter_tools... (8.4s)
  _fe_analyzer_shared 50.0.0 (59.0.0 available)
(中略)
Got dependencies in bin/flutter-3.7.12-stable/packages/flutter_tools!
Doctor summary (to see all details, run flutter doctor -v):
[] Flutter (Channel stable, 3.7.12, on macOS 13.3.1 22E772610a darwin-x64, locale ja-JP)
[] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[!] Xcode - develop for iOS and macOS (Xcode 14.3)
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[!] Android Studio (not installed)
[✓] Connected device (1 available)
[✓] HTTP Host Availability

! Doctor found issues in 4 categories.
mor@morijunichinoMac-mini ~ % 

CocoaPods のインストールが必要らしいので、インストールしておきます。

mor@morijunichinoMac-mini ~ % sudo gem install cocoapods
Password:
Fetching i18n-1.13.0.gem
(中略)
ERROR:  Error installing cocoapods:
    The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1.7.3. Try installing it with `gem install activesupport -v 6.1.7.3` and then running the current command again
    activesupport requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
mor@morijunichinoMac-mini ~ % 

最初に、セットアップした時はこんなの出たっけな? と思ったけど、出てるものは仕方ないので、ググると Stackoverflow にも解決法が載ってました。というより、画面の指示そのまま実行すればいいみたいです。

flutter - Installing "CocoaPods" - Stack Overflow

やってみます。

mor@morijunichinoMac-mini ~ % sudo gem install activesupport -v 6.1.7.3
Password:
Fetching activesupport-6.1.7.3.gem
(中略)
Done installing documentation for zeitwerk, activesupport after 1 seconds
2 gems installed
mor@morijunichinoMac-mini ~ % sudo gem install cocoapods
Successfully installed nap-1.1.0
(中略)
Installing ri documentation for cocoapods-1.12.1
Done installing documentation for nap, fuzzy_match, httpclient, algoliasearch, ffi, ethon, typhoeus, netrc, public_suffix, addressable, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-trunk, cocoapods-try, molinillo, atomos, colored2, nanaimo, rexml, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 18 seconds
29 gems installed
mor@morijunichinoMac-mini ~ % 

CocoaPods がインストールできたので、もう一度、 flutter doctor やってみます。

mor@morijunichinoMac-mini ~ % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[] Flutter (Channel stable, 3.7.12, on macOS 13.3.1 22E772610a darwin-x64, locale ja-JP)
[] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[!] Android Studio (not installed)
[] Connected device (1 available)
[] HTTP Host Availability

! Doctor found issues in 3 categories.
mor@morijunichinoMac-mini ~ % 

Xcode の環境が問題ないのでとりあえずセットアップは良さそうですね。

プロジェクトのビルドと実行

さて、必要な道具がインストールできたはずなので、プロジェクトをビルドして、実行してみます。

Xcode を立ち上げて、ビルドを実行すると

xcode could not find included file 'Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig

というような感じのエラーメッセージが表示されてビルドに失敗します。

なんだろうな、これ?と思いつつググってみると、

Flutter iOSのシミュレーターで実行エラーになるときの対処法 | halzo appdev blog

とあるので flutter のプロジェクトの iOS フォルダで pod install をやってみます。

mor@morijunichinoMac-mini ios % pod install

[!] Invalid `Podfile` file: /Users/mor/work/repos/example_project/ios/Flutter/Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first.

 #  from /Users/mor/work/repos/example_project/ios/Podfile:16
 #  -------------------------------------------
 #    unless File.exist?(generated_xcode_build_settings_path)
 >      raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
 #    end
 #  -------------------------------------------
mor@morijunichinoMac-mini ios % 

flutter pub get を先にやれ、と言われるので試します。

mor@morijunichinoMac-mini ios % cd ..
mor@morijunichinoMac-mini example_project % flutter pub get
Running "flutter pub get" in example_project...
Resolving dependencies... (6.9s)
  _flutterfire_internals 1.1.0 (1.2.0 available)
(中略)
Got dependencies!
The plugins `esys_flutter_share, nfc_in_flutter, path_provider` use a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them since a future release of
Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.
mor@morijunichinoMac-mini example_project % 

問題なさそうです。なので、再度実行します。

mor@morijunichinoMac-mini example_project % cd ios
mor@morijunichinoMac-mini ios % pod install
Analyzing dependencies
cloud_firestore: Using Firebase SDK version '10.7.0' defined in 'firebase_core'
(中略)
Installing url_launcher_ios (0.0.1)
Generating Pods project
Integrating client project
Pod installation complete! There are 19 dependencies from the Podfile and 46 total pods installed.

[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `Runner` to `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` or include the `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` in your build configuration (`Flutter/Release.xcconfig`).
mor@morijunichinoMac-mini ios % 

よさげですね。

それではと気を取り直して、 XCode でもう一度、ビルドを実行します。

ビルド通ったかな?と思いきや、 GoogleMaps がないとエラーが出ます。

ビルド関連のフォルダを clean したり、いろいろと試したのですが、何をやっても、変わらずエラーになります。 エラー内容でググってみても、今一つうまくいきません。

どうしたものかと困っていると、ふと、下記の記事を見つけました。

iOSアプリ開発初心者はXcodeでプロジェクトを開く方法が分からない | DevelopersIO

あれ?最初に開いていたファイルって Runner.xcodeproj の奴だったよな? これか!?

ということで、 Runner.xcworkspace の方を開いて、改めてビルドしてみると問題なくビルドできました!

Xcodeややこしすぎまず。。。というか OS とかの環境が違うと変なところではまってしまうという典型例ですね。

改めて調べてみると、こちらとかの記事にもバッチリ書かれてましたね・・・

Flutterプロジェクト準備

そういや、 Runner.xcodeproj で開いたときのナビゲーションエリアは

こんな感じで Runner だけでしたが、 Runner.xcworkspace を開いたときは、

のように Runner と Pods の2つになってました。以前の開発環境の時は、後者の2つのほうだったのを思い出しました。

結局、整理すると次の手順でやればよかったようです。

  1. flutter pub get
  2. pod install
  3. Xcode を起動して、 Runner.xcodeworkspace を開く
  4. ビルド

その後

ハードウェアが原因だったためか、その後は快調に動作しています。まあ、めったに起こらないことなんでしょうが、ちょっと苦労しました。