1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Flutterでの依存関係のある複数ライブラリーのバージョン管理の仕方

Last updated at Posted at 2025-01-10

初めに

Flutterでのプロジェクト開発中に、GoogleMlKitとfirebase_messagingを使用する必要があり、それらのライブラリを追加したところ、checkDebugDuplicateClassesの競合エラーが発生しました。

バージョンを下げて対応しようと考えましたが、firebase_messagingはfirebase_coreライブラリを必要とします。そのため、firebase_messagingのバージョンを下げるにはfirebase_coreも調整する必要がありました。

さらに、他のFirebase関連ライブラリ(例: firebase_analytics)を使用している場合、それらのバージョン調整も必要となり、大変手間がかかる状況でした。

このような問題を解決するために方法を探していたところ、以下の記事を参考にして修正を行いました。
pubspec.yamlのバージョンは空欄でよさそう

環境

  • Window11
  • Flutter 3.24.3

本題

  1. 競合エラーが出たpubspec.yaml
    以下のような設定を使用していたところ、競合エラーが発生しました。

        google_ml_kit: ^0.18.1 
        firebase_core: ^3.3.0
        firebase_messaging: ^15.0.4
        firebase_analytics: ^11.3.4
    
  2. 修正内容
    記事によると、「バージョンを空欄(もしくはany)にすると、インストール可能な最新のバージョンがインストールされる」とのこと。また、「flutter pub upgradeを実行すれば、依存関係を考慮して最新のパッケージを自動でインストールしてくれる」と記載されていました。

    これを受けて、以下のようにpubspec.yamlを修正しました:

        google_ml_kit: ^0.18.1
        firebase_core: 2.32.0
        firebase_messaging:
        firebase_analytics:
    

    その後、flutter pub upgradeを実行した結果、firebase_coreのバージョンに適合するfirebase_messagingのバージョンが自動的にインストールされました。

    アプリも問題なく起動し、Firebaseからの通知も正常に受信できました。

最後に

anyまたは空白を使うことで、依存関係のあるライブラリのバージョンを自動的に解決できるのは非常に便利でした。同様の競合エラーで困っている方の参考になれば幸いです。

参照

pubspec.yamlのバージョンは空欄でよさそう

1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?