もっぺんプログラミング(´・ω・`)

もっぺん頑張って副業プログラマを目指してます。

100日後にFlutter生活:15日目:Firebase Auth API 呼び出しで、iOSビルドエラー

Flutterで、Firebaseのauthentication を使おうとして、iOS ビルドエラーになった状況を解決までを書いておきます。
いろいろ試したので、決定的な解決方法が曖昧ですが、おそらく Podfile の ios ターゲットが低かったせいかなと…

環境

Flutter のバージョンは、こんな感じ。

flutter % flutter --version
Flutter 1.22.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 9b2d32b605 (8 days ago) • 2021-01-22 14:36:39 -0800
Engine • revision 2f0af37152
Tools • Dart 2.10.5
flutter % 

Mac OS Big Sur 11.1 XCode Version 12.4 (12D4e)

で、やってます。
以下、ハマりポイントまでの操作手順。

プロジェクトを作る

flutter create でプロジェクトを作成。
サンプルが動くところまで進める。

flutter % flutter create firefire
Creating project firefire...
  firefire/ios/Runner.xcworkspace/contents.xcworkspacedata (created)
…

All done!

[✓] Flutter: is fully installed. (Channel stable, 1.22.6, on macOS 11.1 20C69 darwin-x64, locale ja-JP)
[✓] Android toolchain - develop for Android devices: is fully installed. (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS: is fully installed. (Xcode 12.4)
[✓] Android Studio: is fully installed. (version 4.1)
[✓] VS Code: is fully installed. (version 1.52.1)
[✓] Connected device: is fully installed. (1 available)

In order to run your application, type:

  $ cd firefire
  $ flutter run

Your application code is in firefire/lib/main.dart.

flutter % 

VS Code で開いて、Debug!

flutter % cd firefire
firefire % code .

ここまでは、サンプルコードが動いてる。
問題なし。

firebase_auth をインストール

ここから、おかしくなる(´・ω・`)

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  firebase_auth: ^0.21.0-nullsafety.0

で、flutter pub get すると…

firefire % flutter pub get
The current Dart SDK version is 2.10.5.                                 
                                                                        
Because firefire depends on firebase_auth >=0.21.0-1.0.nullsafety.0 which requires SDK version >=2.12.0-0 <3.0.0, version solving failed.
Running "flutter pub get" in firefire...                                
pub get failed (1; Because firefire depends on firebase_auth >=0.21.0-1.0.nullsafety.0 which requires SDK version >=2.12.0-0 <3.0.0,
version solving failed.)
firefire % 

あかんぽい。
Dart SDKのバージョンをアップしないとダメ?

でも、Dartのページだと 2.10.5 が Stable となってるから、悪くないと思うんだけどなぁ。(2021/01/30 時点)
Get the Dart SDK | Dart

どうやるのか…

firebase_authのバージョンを変えてみる。

dependencies:
  flutter:
    sdk: flutter
  firebase_auth: ^0.20.0+1

しかし、やはり以下のエラーでダメ

Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
 lib/main.dart
CocoaPods' output:
↳
      Preparing
    Analyzing dependencies
    Inspecting targets to integrate
      Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)
    Fetching external sources
    -> Fetching podspec for `Flutter` from `Flutter`
    -> Fetching podspec for `firebase_auth` from `.symlinks/plugins/firebase_auth/ios`
    firebase_auth: Using Firebase SDK version '7.3.0' defined in 'firebase_core'
    -> Fetching podspec for `firebase_core` from `.symlinks/plugins/firebase_core/ios`
    firebase_core: Using Firebase SDK version '7.3.0' defined in 'firebase_core'
    Resolving dependencies of `Podfile`
      CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only perfomed in repo update
    [!] CocoaPods could not find compatible versions for pod "firebase_auth":
      In Podfile:
        firebase_auth (from `.symlinks/plugins/firebase_auth/ios`)
    Specs satisfying the `firebase_auth (from `.symlinks/plugins/firebase_auth/ios`)` dependency were found, but they required a higher minimum deployment target.
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:328:in `raise_error_unless_state'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:310:in `block in unwind_for_conflict'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:308:in `tap'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:308:in `unwind_for_conflict'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:684:in `attempt_to_activate'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:254:in `process_topmost_state'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:182:in `resolve'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/molinillo-0.6.6/lib/molinillo/resolver.rb:43:in `resolve'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/resolver.rb:94:in `resolve'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer/analyzer.rb:1074:in `block in resolve_dependencies'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/user_interface.rb:64:in `section'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer/analyzer.rb:1072:in `resolve_dependencies'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer/analyzer.rb:124:in `analyze'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:414:in `analyze'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:239:in `block in resolve_dependencies'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/user_interface.rb:64:in `section'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:238:in `resolve_dependencies'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:160:in `install!'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/command/install.rb:52:in `run'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/command.rb:52:in `run'
    /Users/xxxx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/cocoapods-1.10.1/bin/pod:55:in `<top (required)>'
    /Users/xxxx/.rbenv/versions/2.6.6/bin/pod:23:in `load'
    /Users/xxxx/.rbenv/versions/2.6.6/bin/pod:23:in `<main>'
Error output from CocoaPods:
↳
    [!] Automatically assigning platform `iOS` with version `9.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
Error running pod install
Error launching application on iPhone 12 Pro Max.
Exited (sigterm)

うーん。このエラーなのかな〜

[!] CocoaPods could not find compatible versions for pod "firebase_auth":
In Podfile:
firebase_auth (from .symlinks/plugins/firebase_auth/ios)

類似のエラーで、StackOverflow 見てみたけど、良くわからん… ios - CocoaPods could not find compatible versions for pod "Firebase/CoreOnly" - Stack Overflow

flutter clean
pod repo update

を、やってみたけど解決せず。

Firebaseのドキュメントを見てみる

手がかりを求めて、Firebaseのドキュメントへ…

Add Firebase to your iOS project

platform :ios, ‘10.0’

Podfileのplatform は、10.0 じゃないとダメなのかな?
上記エラーメッセージで、「[!] Automatically assigning platform iOS with version 9.0」とあり
iOSのバージョンが低すぎたのかもしれない。

Podfile に上記を追加して、シュミレーターとVS Code も念の為再起動。(VS Codeは、関係なさそうだけど…) ビルドは通った!

ドキュメントに記載されていた、「pod 'Firebase/Auth'」も、一応、Podfileに追記
書いた場所は、なんとなく。
やはり、Swiftの開発知識がないと、XCodeの作法がわからないな〜・・・

target 'Runner' do
  pod 'Firebase/Auth'

とりあえず、アプリが起動したので、明日はコードを書いていきます。