LoginSignup
21
12

More than 1 year has passed since last update.

Flutter Firebase「fatal error: module 'cloud_firestore' not found @import cloud_firestore;」が出た時の対処法

Last updated at Posted at 2020-10-13

##背景
7月に初めてFlutterにFirebaseを追加した時には出なかったが、今回はエラーが出てしまったので、原因と解決法を忘却録として残します

##開発環境
PC:macOS Catalina
エディター:Visual Studio Code
XCode:Version 12.0.1 (12A7300)
Flutter: 1系

##内容
FlutterにFirebaseを追加しようとして、以下のようなエラーが発生
エラーはflutter runコマンドを実行して発生(VSCodeからのデバッグでも同様)

Running pod install...                                              9.8s
Running Xcode build...                             
 └─Compiling, linking and signing...                         2.0s
Xcode build done.                                           170.4s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **
Xcode's output:
↳
/Users/yourName/flutterProjectName/ios/Runner/GeneratedPluginRegistrant.m:10:9: fatal error: module
    'cloud_firestore' not found
    @import cloud_firestore;
     ~~~~~~~^~~~~~~~~~~~~~~
    1 error generated.
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Constructing build description

Could not build the application for the simulator.
Error launching application on iPhone 11.

###検索で見つけた方法
検索すると以下のような方法で解決したとあったので、試してみました
作成したflutterのプロジェクトディレクトリで実行します

flutter clean
cd ios
rm -rf Pods
pod install
cd ..
flutter run

上記の通りにやってもまた同じエラーが発生しました

##原因
flutter runする前にPodfileを作成してしまったことが原因でした

そもそもpodfileを作成してしまった原因は、
Firebase を iOS プロジェクトに追加する を見ていたこと
→本当はこっちが正しい

##解決策

まずは、検索で見つけた方法と同じようにPods関係のファイル、ディレクトリを削除

flutter clean
cd ios
rm -rf Pods
rm Podfile.lock Podfile

削除後、以下のコマンドをflutterのプロジェクトディレクトリで実行します

flutter run

Pod initコマンドとは違う内容が書かれた Podfile が作成され、シミュレーターと接続できる

##参考
https://github.com/FirebaseExtended/flutterfire/issues/1979

21
12
4

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
21
12