💪

flutterのバージョンアップ(v3.32.2 -> v3.35.7) ※Gradleビルドエラー解決

に公開

ref: 以前のバージョンアップの記事 (v3.29.3 -> v3.32.2)

(fvm利用)Flutterのアップグレード

  • stableチャンネル利用中で、利用中のstableのFlutterバージョンを上げる対応

  • upgradeコマンド実施

fvm flutter upgrade

動作確認

iOSは、ビルド・動作確認OK.
Androidがハマった。。。

Android(Gradle ビルドエラー)の修正

原因

Flutter のアップデートによって、Gradle の構成ルールが新方式に変更。

  • repositories 定義の場所が変更build.gradlesettings.gradle に集約
  • Flutter 独自の Maven リポジトリhttps://storage.googleapis.com/download.flutter.io)が必須になった
  • Firebase BoM の適用範囲が厳密化:variant(debug/release)ごとに BoM が届かない構成が発生
  • 古いキャッシュや旧構文が残ると、依存解決が失敗

結果

  • firebase-analytics-ktx:.(空バージョン)という依存解決エラーが発生
  • io.flutter:flutter_embedding_debug などの依存が見つからない
  • repositories の衝突警告(FAIL_ON_PROJECT_REPOS)が頻発

対応

android/build.gradle

  • 削除
- allprojects {
-     repositories {
-         google()
-         jcenter()
-     }
- }

android/settings.gradle

  • 追記
+ dependencyResolutionManagement {
+     // Flutter の Gradle プラグインがプロジェクト側で maven を足すため、PREFER_SETTINGS が実務的
+     repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
+     repositories {
+         google()
+         mavenCentral()
+         // これが不足していると io.flutter:... が解決不能になります
+         maven { url = uri("https://storage.googleapis.com/download.flutter.io") }
+     }
+ }

android/app/build.gradle

  • 変更
 
 android {
-    compileSdkVersion 35
+    compileSdkVersion 36

...

-        targetSdkVersion 35
+        targetSdkVersion 36

...

dependencies {
-    implementation platform('com.google.firebase:firebase-bom:28.4.0')
+    implementation(enforcedPlatform("com.google.firebase:firebase-bom:33.5.1"))    


最後に、キャッシュをクリアして再ビルド

flutter clean
flutter pub get
flutter run

enforcedPlatform で解決

こちらの対応がなかなかわからず、ビルドNGな状態が続いた。

  • 通常は以下のように書けば十分。
implementation(platform("com.google.firebase:firebase-bom:33.5.1"))
implementation("com.google.firebase:firebase-analytics-ktx")

しかし、構成や依存関係の順序によっては BoM が届かず、
バージョン未解決 → エラー、となる。

この場合、BoM を「推奨」ではなく「強制」する enforcedPlatform を使うことで、解決。

implementation(enforcedPlatform("com.google.firebase:firebase-bom:33.5.1"))
implementation("com.google.firebase:firebase-analytics-ktx")

// エラーログ

Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve all dependencies for configuration ':app:debugRuntimeClasspath'.
      > Could not find com.google.firebase:firebase-analytics-ktx:.
        Required by:
            project :app

* Try:
> The project declares repositories, effectively ignoring the repositories you have declared in the settings.
   To determine how project repositories are declared, configure your build to fail on project repositories.
   For more information, please refer to https://docs.gradle.org/8.13/userguide/declaring_repositories.html#sub:fail_build_on_project_repositories in the Gradle documentation.

Discussion