状況
Android StudioのAVD を起動し、flutter run コマンドを実行した際に、ビルドは正常に完了し、生成されたAPKファイルがエミュレータにインストールされたが、MethodChanneが繋がらずにエラーが出た。
環境
- Ubuntu 20.04.6 LTS
- Visual Studio Code 1.109.2
- Android StudioのAVDのMedium Phone
コマンド結果
flutter run --no-enable-impeller
E/flutter ( 9038): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)\
詳細
E/flutter ( 9038): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
- PlatformException():デバイスあるいはデバイスとの間の通信でのエラー
- channel-error:MethodChanneでのエラー
- Unable to establish connection on channel.:チャネル接続を確立できない
- null:ネイティブ側から送られる詳細データ
- null:ネイティブ側のスタックトレース
解決方法
- 全てのpubspec.yamlのfirebase_coreを最新の4.4.0にした
- pubspec.yamlのfirebase_core_platform_interfaceを削除した
- 全てのpubspec.yamlのfirebase_authを最新の6.1.4にした
- 全てのpubspec.yamlのfirebase_crashlyticsを最新の6.1.4にした
- 全てのpubspec.yamlのfirebase_messagingを最新の16.1.1にした
- 全てのpubspec.yamlのcloud_firestoreを最新の6.1.2にした
flutter clean
# 全ての変更したディレクトリ内で行う(子から親)
flutter pub get
感想
firebaseのバージョンによるエラーだったっぽいのでfirebase_coreを削除してあとは依存関係のエラーが出るパッケージを最新版にしていったら治った。