Counts the Clouds

Flutter+FirebaseのWebアプリにiOSアプリを追加する
2021.08.17

Flutter
Firebase

piotr-chrobot-M0WbGFRTXqU-unsplash.jpg

Flutter+FirebaseのウェブアプリにiOSアプリを追加するとき成功した手順。

WebのチュートリアルにiOSアプリを追加しようとしたが、最初から盛大に間違っていた。

FirebaseコンソールにiOSアプリを追加

バンドルID(Bundler identifier)はXCodeで調べる。勝手に命名してハマった。

XCode 内で開いたプロジェクトからバンドル ID を見つけます。プロジェクト ナビゲータで最上位のアプリを選択し、[全般] タブにアクセスします。[バンドル ID] の値が iOS バンドル ID です(例: com.yourcompany.ios-app-name)。

GoogleService-Info.plistを配置

GoogleService-Info.plistもXcodeで配置する必要がある。ダイアログが表示されるが項目は変更なし。

Xcode を使用して、Flutter アプリの Runner/Runner ディレクトリにファイルを移動します。

Podfileのインストール

下記をPodfileに追記。

# add pods for desired Firebase products
# https://firebase.google.com/docs/ios/setup#available-pods

iosディレクトリでインストールを実行。

$ cd ios
% pod install
Analyzing dependencies
cloud_firestore: Using Firebase SDK version '8.3.0' defined in 'firebase_core'
firebase_auth: Using Firebase SDK version '8.3.0' defined in 'firebase_core'
firebase_core: Using Firebase SDK version '8.3.0' defined in 'firebase_core'
Downloading dependencies
# ...
Generating Pods project
Integrating client project
Pod installation complete! There are 4 dependencies from the Podfile and 19 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`).

CocoaPods could not find compatible versions for pod “cloud_firestore”

これはハマっている最中のできごとだったかも。デフォルトではコメントアウトされているので、コメントを解除して10.6を指定。

platform :ios, '10.6'

[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set.

インストール自体は成功しているが、warningが出ている。

メッセージをよく読むと、Flutter/Release.xcconfigTarget Support Files/Pods-Runner/Pods-Runner.profile.xcconfigをセットしろ、と言っている。

  #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
+ #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"
  #include "Generated.xcconfig"

Flutter/Release.xcconfigFlutter/Debug.xcconfigに追記したところ、warningはなくなった。

Flutterを起動

元のWebアプリでFlutterFireプラグインはすでにインストール済み。

プロジェクトルートでFlutterを起動。

$ cd ..
% flutter run
Launching lib/main.dart on iPhone 12 in debug mode...
# ...

💪 Running with sound null safety 💪

An Observatory debugger and profiler on iPhone 12 is available at: http://127.0.0.1:65019/e39lRmtyhcw=/
The Flutter DevTools debugger and profiler on iPhone 12 is available at:
http://127.0.0.1:9101?uri=http://127.0.0.1:65019/e39lRmtyhcw=/

アプリの起動に成功した。

反省点:公式を探してちゃんと読む。