3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

build runner実行時の依存パッケージ関連エラーを、Issue化してClaudeに数分で片付けてもらった

Last updated at Posted at 2025-07-06

build_runnerコマンド実行時にエラー発生

個人的にFlutterで開発をしているアプリケーションがありまして、
2、3週間ぶりに、CI/CDパイプライン実行時にエラーが発生しました。

パイプライン内で以下を実行しています。(環境変数ファイル出力等で使用)

dart run build_runner build --delete-conflicting-outputs

実際に動かしているCI/CDパイプラインについて、詳しくはふれませんが、
yamlファイルを添付しています。

気になる方はご覧下さい。

yamlファイル

各stepの処理内容は、ファイルの後に記載しています。

name: Flutter CI/CD Pipeline Starbucks Clone App

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-24.04 

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        
      - name: Cache Gradle
        uses: actions/cache@v4
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
          restore-keys: |
            gradle-${{ runner.os }}-    

      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: '3.32.5'
          cache: true

      - name: Cache Android SDK
        uses: actions/cache@v4
        with:
          path: ~/.android
          key: ${{ runner.os }}-android-sdk-${{ hashFiles('**/build.gradle*') }}
          restore-keys: |
            ${{ runner.os }}-android-sdk-

      - name: Setup Android SDK
        uses: android-actions/setup-android@v3

      - name: 'Cache pubspec dependencies'
        uses: actions/cache@v4
        with:
          path: |
            ${{ env.FLUTTER_HOME }}/.pub-cache
            **/.packages
            **/.flutter-plugins
            **/.flutter-plugin-dependencies
            **/.dart_tool/package_config.json
          key: build-pubspec-${{ hashFiles('**/pubspec.lock') }}
          restore-keys: |
            build-pubspec-   

      - name: Load Google Service file
        run: |
          echo "${{ secrets.GOOGLE_SERVICES_JSON }}" | base64 -d > android/app/google-services.json
        
      - name: Create Keystore
        run: |
          echo "${{ secrets.RELEASE_KEYSTORE }}" | base64 -d > android/app/release.keystore

      - name: Create key.properties
        run: |
          echo "storePassword=${{ secrets.KEYSTORE_PASSWORD }}" >> android/key.properties
          echo "keyPassword=${{ secrets.KEY_PASSWORD }}" >> android/key.properties
          echo "keyAlias=${{ secrets.KEY_ALIAS }}" >> android/key.properties
          echo "storeFile=release.keystore" >> android/key.properties

      - name: Create secrets.properties
        run: |
          echo "MAPS_API_KEY=${{ secrets.MAPS_API_KEY }}" >> android/secrets.properties
          echo "FIREBASE_APP_ID=${{ secrets.FIREBASE_APP_ID }}" >> android/secrets.properties
          echo "FIREBASE_HOSTING_DOMAIN=${{ secrets.FIREBASE_HOSTING_DOMAIN }}" >> android/secrets.properties


      - name: Clean Flutter
        run: |
          flutter pub get

      - name: Optimize Flutter
        run: |
          flutter config --no-analytics
        
      - name: Create and verify .env file
        run: |
          touch .env
          chmod 644 .env
          
          echo "SUPABASE_URL=${{ secrets.SUPABASE_URL }}" >> .env
          echo "SUPABASE_ANON_KEY=${{ secrets.SUPABASE_ANON_KEY }}" >> .env
          echo "GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}" >> .env
          echo "GOOGLE_WEB_SERVER_CLIENT_ID=${{ secrets.GOOGLE_WEB_SERVER_CLIENT_ID }}" >> .env

      - name: Cache build runner
        uses: actions/cache@v4
        with:
          path: |
            **/.dart_tool/build
          key: build-runner-${{ hashFiles('**/asset_graph.json') }}-${{ hashFiles('**/pubspec.lock') }}
          restore-keys: |
            build-runner-

      - name: build runner
        run: dart run build_runner build --delete-conflicting-outputs

      - name: Run tests
        run: flutter test

      - name: Build APK
        run: flutter build apk --split-per-abi

       - name: Upload APK
         uses: actions/upload-artifact@v4
         with:
           name: release-apk
           path: build/app/outputs/flutter-apk/app-arm64-v8a-release.apk
           retention-days: 3

       - name: Deploy to Firebase App Distribution
         uses: wzieba/Firebase-Distribution-Github-Action@v1
         with:
           appId: ${{ secrets.FIREBASE_APP_ID }}
           serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }}
           groups: testers
           file: build/app/outputs/flutter-apk/app-arm64-v8a-release.apk

トリガー条件

  • mainブランチへのpush時
  • mainブランチへのプルリクエスト時

実行環境

  • Ubuntu 24.04で実行

キャッシュ設定

  • Gradleキャッシュの設定
  • Android SDKキャッシュの設定
  • Flutterの依存関係キャッシュの設定
  • Build runnerキャッシュの設定

開発環境セットアップ

  • リポジトリのチェックアウト
  • Flutter 3.32.5のセットアップ
  • Android SDKのセットアップ

設定ファイル作成

  • Google Servicesファイル(google-services.json)の作成
  • リリース用キーストアファイルの作成
  • key.propertiesファイルの作成(署名情報)
  • secrets.propertiesファイルの作成(Maps API、Firebase設定)
  • 環境変数ファイル(.env)の作成(Supabase、Google認証設定)

ビルド準備

  • Flutter依存関係の取得
  • Flutterアナリティクスの無効化
  • Build runnerの実行(コード生成)

テストとビルド

  • Flutterテストの実行
  • APKファイルのビルド(ABI別分割)

デプロイ

  • ビルドしたAPKファイルのアーティファクトアップロード(3日間保持)
  • Firebase App Distributionへのデプロイ(テスターグループ向け)

発生したエラー

image.png

エラー全体の内容(CI/CDパイプラインのログ)
[INFO] Precompiling build script......
Warning:  ../../../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:2133:32: Error: The argument type 'Element' can't be assigned to the parameter type 'Element2'.
 - 'Element' is from 'package:analyzer/dart/element/element.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.4.5/lib/dart/element/element.dart').
 - 'Element2' is from 'package:analyzer/dart/element/element2.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.4.5/lib/dart/element/element2.dart').
            .publiclyExporting(element, resultCache: resultCache) ??
                               ^
../../../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:2133:54: Error: The argument type 'Map<Element, LibraryElement?>?' can't be assigned to the parameter type 'Map<Element2, LibraryElement2?>?'.
 - 'Map' is from 'dart:core'.
 - 'Element' is from 'package:analyzer/dart/element/element.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.4.5/lib/dart/element/element.dart').
 - 'LibraryElement' is from 'package:analyzer/dart/element/element.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.4.5/lib/dart/element/element.dart').
 - 'Element2' is from 'package:analyzer/dart/element/element2.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.4.5/lib/dart/element/element2.dart').
 - 'LibraryElement2' is from 'package:analyzer/dart/element/element2.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.4.5/lib/dart/element/element2.dart').
            .publiclyExporting(element, resultCache: resultCache) ??
                                                     ^
../../../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:2137:40: Error: The getter 'source' isn't defined for the class 'Object'.
 - 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'source'.
    var uriToImport = libraryToImport?.source.uri;
                                       ^^^^^^
../../../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:2150:58: Error: The argument type 'Object?' can't be assigned to the parameter type 'LibraryElement?'.
 - 'Object' is from 'dart:core'.
 - 'LibraryElement' is from 'package:analyzer/dart/element/element.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.4.5/lib/dart/element/element.dart').
      _removeUnnecessaryPendingElementImports(newImport, libraryToImport);
                                                         ^
../../../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:2182:14: Error: The method 'publiclyExporting2' isn't defined for the class 'TopLevelDeclarations'.
 - 'TopLevelDeclarations' is from 'package:analyzer/src/services/top_level_declarations.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.4.5/lib/src/services/top_level_declarations.dart').
Try correcting the name to the name of an existing method, or defining a method named 'publiclyExporting2'.
            .publiclyExporting2(element, resultCache: resultCache) ??
             ^^^^^^^^^^^^^^^^^^
[INFO] Precompiling build script... completed, took 5.8s

[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.

Error: Process completed with exit code 78.

Flutterを触り始めてからなんだかんだ2年ほど経ちますが、このエラーは初めてでした。

思い当たることとして、これまであるアプリの開発期間は、長くても2ヶ月でした。

今回は半年以上開発しており、パッケージ間の依存関係で問題が発生するくらいの期間続けて開発するくらい規模のアプリは作っているんだな~~、とちょっと嬉しく思っています。

エラー内容をWeb検索

Process completed with exit code 78.

検索すると、パッケージのバージョン互換性が関係するエラーと分かりました。

今回は、以下パッケージ絡みのエラーでした。(エラー内容より)

analyzer_pluginpubspec.yamlには直接記述していないので、
このパッケージに依存する他パッケージにおいて、互換性がないことでエラーが発生していることになります。

エラー解消作業

エラー解消作業を、以下順番で進めていきます。

  1. パッケージ更新
  2. 依存関係確認
  3. pubspec.yamlの修正

パッケージ更新

各パッケージを更新(可能な限り最新化)するために、以下を実行します。

flutter pub upgrade
$ flutter pub upgrade
Resolving dependencies... (4.6s)
Downloading packages...
  feanalyzer_shared 82.0.0 (85.0.0 available)
  analyzer 7.4.5 (7.5.4 available)
  analyzer_plugin 0.12.0 (0.13.4 available)
  characters 1.4.0 (1.4.1 available)
  
  ・・・中略・・・
  
  vector_math 2.1.4 (2.2.0 available)
  vm_service 15.0.0 (15.0.2 available)
  xml 6.5.0 (6.6.0 available)
No dependencies changed.
28 packages have newer versions incompatible with dependency constraints.
Try flutter pub outdated for more information.

analyzer_plugin 0.12.0 (0.13.4 available)

  • 利用可能な最新バージョン:0.13.4
  • 現在利用しているバージョン0.12.0

No dependencies changed.

更新可能な依存関係がなかったことになります。

依存関係確認

最新バージョンになっていない(更新できていない)のは、
analyzer_pluginが依存している他パッケージのいずれかに原因があります。

どのパッケージが依存しているか確認します。
この後結果をClaude Desktop(他、chatGPTなど)に解析してもらう関係で、ファイル出力します。

flutter pub deps > deps.txt
出力したファイル(一部)
  • 1行目:Dartのバージョン情報
  • 2行目:Flutterのバージョン情報
  • 3行目:作成アプリ名 バージョン
  • 4行目以降:依存関係に関する情報
    階層が深いほど依存パッケージが多いといった見方ができます。
Dart SDK 3.8.1
Flutter SDK 3.32.5
testingapp 1.0.0+1
├── animated_bottom_navigation_bar 1.4.0
│   └── flutter...
├── app_links 6.4.0
│   ├── app_links_linux 1.0.3
│   │   ├── app_links_platform_interface...
│   │   ├── flutter...
│   │   └── gtk 2.1.0
│   │       ├── ffi...
│   │       ├── flutter...
│   │       └── meta...
│   ├── app_links_platform_interface 2.0.2
│   │   ├── flutter...
│   │   └── plugin_platform_interface...
│   ├── app_links_web 1.0.4
│   │   ├── app_links_platform_interface...
│   │   ├── flutter...
│   │   ├── flutter_web_plugins...
│   │   └── web...
│   └── flutter...

ファイルをClaude Dekstopに渡して依存パッケージを確認してもらいました。
依存しているパッケージは以下の7つだそうです。

build_runner 2.5.4
custom_lint 0.7.3
envied_generator 1.1.1
mockito 5.4.6
riverpod_generator 2.6.4
riverpod_lint 2.6.4
test 1.25.15

pubspec.yamlの修正

従来のやり方(生成AIによる開発が普及していない時代)

次のセクションで、claudeを用いたイマドキの方法を記載しています。

上述したライブラリについて、
他の依存関係でエラーが出ない範囲でライブラリのバージョンを上げて、analyzer_pluginのバージョンがより新しいものに調整を行ったりしながら、エラー解消作業にあたります。
作業中には、以下のようなエラーが発生します。(キーワード:incompatible

Because test >=1.26.1 depends on test_api 0.7.6 and every version of integration_test from sdk depends on test_api 0.7.4, test >=1.26.1 is incompatible with integration_test from sdk.
So, because testingapp depends on both integration_test from sdk and test ^1.26.2, version solving failed.
Failed to update packages.
exit code 1

イマドキのやり方(Github Issue上でClaudeに解決策を質問できる時代)

「イマドキ」と記載するのは少し気が引けますが、実際そうだと思ってます。

このやり方を実施するためには、
以下サイトに沿った事前の準備が必要です。(30分もあれば十分終わります)

従来のやり方を否定するものではありません。
従来のやり方による解決方法も知った上で、作業効率化を目的にこの方法で進めます。

1.Issue作成
現在の状況と発生したエラーで添付したエラー全文を記載したissueを作成します。

image.png

2.claudeにメンション
以下画像のように、@claudeと依頼内容を記載します。

image.png

3.出力してくれた内容を確認し、PR作成
画像内に、Solution Applied:とあるように、pubspec.yamlから不要なパッケージを削除する対応が解決案として提示されました。

出力内容(Markdown)
### Fixing CI/CD Pipeline Failure ✅

I successfully analyzed and fixed the CI/CD pipeline failure caused by dependency version conflicts.

**Todo List:**
- [x] Analyze current pubspec.yaml and dependency configuration
- [x] Identify the root cause of analyzer plugin compatibility issue
- [x] Research and implement fix for dependency version conflicts
- [x] Test the fix locally
- [x] Commit changes and create PR

**Analysis:**
The error showed that `analyzer_plugin-0.12.0` was incompatible with `analyzer-7.4.5` due to API changes where `Element` was replaced with `Element2`. This is a common issue when analyzer versions are updated without corresponding plugin updates.

**Root Cause Identified:**
- `analyzer: 7.4.5` was incompatible with `analyzer_plugin: 0.12.0`
- `custom_lint: 0.7.3` and `riverpod_lint: 2.6.4` were pulling in the incompatible `analyzer_plugin`
- The issue was in the transitive dependencies chain

**Solution Applied:**
Temporarily commented out the problematic linting packages in pubspec.yaml:
- `custom_lint: ^0.7.0` → commented out
- `riverpod_lint: ^2.6.4` → commented out

This removes the dependency on the incompatible `analyzer_plugin` while maintaining all core functionality. The analysis_options.yaml only uses `flutter_lints` which doesn't have this compatibility issue.

**Changes Committed:**
- Updated `pubspec.yaml` to comment out incompatible linting packages
- Commit: `e89bb6d98f3ebe0fba653f6cb456dae8497001a8`

image.png

4.PR作成・マージ
以下の通り、pubspec.yamlを修正したブランチが作成されているので、このブランチをmainブランチにマージします。
(実際のプロジェクトであれば、作成されたブランチをローカルにcheckoutしdart run build_runner buildを実行して結果確認すると思いますが、自分のプロジェクトなので直接パイプライン回します)
image.png

5.結果確認
手順4でマージすると、CI/CDパイプラインが再度実行されるので、待ちます。

後続の工程で別のパッケージが関係するビルドエラーにより、最後までは成功していないですが、build_runner関係のエラーは解消することができました。

バージョン最新化の大切さ

2、3週間ぶりに、CI/CDパイプライン実行時にエラーが発生しました。

これくらい期間が開けばそれだけパッケージのバージョンが上がっている可能性があります。

VsCodeの拡張機能、Version Lensを入れておくだけでも違いますが、
動作に影響する可能性もあるので、定期的にバージョンアップする時間も確保した方がいいかもしれない、と感じました。

こんな風に表示してくれます。

image.png

まとめ

今回はFlutterのパッケージ絡みの不具合を解消するまでの流れについて、まとめてみました。
実際に解消するための実装修正においては、Github Issueとclaudeを組みわせたイマドキの不具合解消方法も利用してみました。

また、以下手順で不具合解消を実施すると記載しました。
今回は最後の手順だけclaudeにサポートしてもらいましたが、流れが分かったので一通り、依頼する仕組みも作れそうです。

パッケージ更新
依存関係確認
pubspec.yamlの修正

Flutterのエラーとして、
今回新たなパターンの不具合に出会えたので、今後の開発でも生かせる部分もあると思いました。

今後もFlutter開発しつつ、生成AI関連の技術もさわっていければと思います。
ありがとうございました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?