0
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とFirebaseの連携時の問題

Last updated at Posted at 2025-06-11

はじめに

現在、僕はFlutterの勉強がてら簡易的なSNSを作っています。(勉強に使用している教材は最後の記載しておきます。)
その際、FlutterとFirebaseの連携時にエラーが出てきたのでその解決策を共有しておこうと思います。

目次

・問題発生
・エラーの背景
・解決策
・まとめ
・使用教材

問題発生

FirebaseのAndroidアプリ追加の手順に従い、
android/build.gradle.kts
android/app/build.gradle.kts
を編集し、

flutter run

を実行してみると以下のようなエラーが出てきた。

PS C:\Users\---\Documents\Flutter\minisns> flutter run 
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
e: file:///C:/Users/---/.gradle/caches/8.10.2/transforms/9b018e3170113d6fc57578a6d48cd669/transformed/jetified-play-services-measurement-impl-22.4.0-api.jar!/META-INF/java.com.google.android.gms.libs.filecompliance.proto_file_access_api_type_kt_proto_lite.kotlin_moduleModule was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.1.0, expected version is 1.8.0.
e: file:///C:/Users/---/.gradle/caches/8.10.2/transforms/9b018e3170113d6fc57578a6d48cd669/transformed/jetified-play-services-measurement-impl-22.4.0-api.jar!/META-INF/third_party.kotlin.protobuf.src.commonMain.kotlin.com.google.protobuf.kotlin_only_for_use_in_proto_generated_code_its_generator_and_tests.kotlin_moduleModule was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.1.0, expected version is 1.8.0.
e: file:///C:/Users/---/.gradle/caches/8.10.2/transforms/9b018e3170113d6fc57578a6d48cd669/transformed/jetified-play-services-measurement-impl-22.4.0-api.jar!/META-INF/third_party.kotlin.protobuf.src.commonMain.kotlin.com.google.protobuf.kotlin_shared_runtime.kotlin_moduleModule was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.1.0, expected version is 1.8.0.
e: file:///C:/Users/---/.gradle/caches/8.10.2/transforms/d46efa473af2ff731cfae5ea2010b3f1/transformed/jetified-play-services-measurement-api-22.4.0-api.jar!/META-INF/java.com.google.android.gmscore.integ.client.measurement_api_measurement_api.kotlin_moduleModule was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.1.0, expected version is 1.8.0.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 23s
Running Gradle task 'assembleDebug'...                             23.9s

┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin.                       │ 
│ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then   │ 
│ update the                                                                                   │ 
│ version number of the plugin with id "org.jetbrains.kotlin.android" in the plugins block of  │ 
│ C:\Users\---\Documents\Flutter\minisns\android\settings.gradle.                              │ 
│                                                                                              │ 
│ Alternatively (if your project was created before Flutter 3.19), update                      │ 
│ C:\Users\---\Documents\Flutter\minisns\android\build.gradle                                  │ 
│ ext.kotlin_version = '<latest-version>'                                                      │ 
└──────────────────────────────────────────────────────────────────────────────────────────────┘ 
Error: Gradle task assembleDebug failed with exit code 1

ChatGPTくんに原因を聞いてみると、Flutterのプロジェクト内で使われている一部のライブラリがKotlin 2.1.0でコンパイルされているが、僕のFlutterプロジェクトはまだKotlin 1.8.0用のビルド設定になっているらしく、Kotlinコンパイラが

The binary version of its metadata is 2.1.0, expected version is 1.8.0.

「このバイナリのメタデータのバージョンが新しすぎる!!」
と怒っているとのこと。

エラーの背景

Flutter 3.19以降(Flutter 3.22など)からは、デフォルトのKotlin Gradle Pluginも2.x系になりつつあります。しかし,プロジェクトが古めに作られていた場合や、Flutter SDKがアップデートされてもプロジェクトのandroid/build.gradleなどのKotlinバージョンは自動では上がらないので、このズレが起きます。

解決策

android/settings.gradle.ktsの

settings.gradle.kts
pulgins {
    // ...他のプラグイン...
    id("org.jetbrains.kotlin.android") version "1.8.22" apply false
    // ...他のプラグイン...
}

を以下のように、バージョンを修正します。(僕の場合は元が1.8.22だったので2.1.0に変更)

settings.gradle.kts
pulgins {
    // ...他のプラグイン...
    id("org.jetbrains.kotlin.android") version "2.1.0" apply false
    // ...他のプラグイン...
}

バージョン修正後、一旦キャッシュを削除し

flutter clean

パッケージを再取得し

flutter pub get

再ビルドします。

flutter run

そうするとエラーが出ず、画面が表示されるはずです。

まとめ

以上の方法でFlutterとFirebaseの連携時に起こるバージョンの不整合を解消することができます。もし、不備等あれば質問してください。

使用教材

Flutter × FirebaseでTwitterみたいなSNSアプリを作成する【ログイン機能】【画像保存】

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