3
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 3.32.0にアップデートしたら、GithubActionでflutter analyzeが動かなくなった。(解決付き)

Posted at

Flutter3.32.0がGoogle I/Oで発表されているのをみてFlutterのアップデートをした際に遭遇したエラーについてまとめておきます。
おそらくこのエラーは、リリースされた直後だから発生している事象かと思われますがとりあえず。

発生エラー

以下のエラーがGihubAction上で発生していました。

Run flutter analyze
Analyzing xxxx...                                          
Error from the analysis server: /home/runner/work/xxxx/xxxx/.pub-cache/hosted/pub.dev/analyzer_plugin-0.13.0/lib/src/utilities/change_builder/change_builder_dart.dart:1602:14: Error: The method 'publiclyExporting2' isn't defined for the class 'TopLevelDeclarations'.
 - 'TopLevelDeclarations' is from 'package:analyzer/src/services/top_level_declarations.dart' ('/home/runner/work/xxxx/xxxx/.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) ??
             ^^^^^^^^^^^^^^^^^^


Error from the analysis server: Failed to start plugins

No issues found! (ran in 53.8s)
Server error(s) occurred. (ran in 53.8s)
Error: Process completed with exit code 1.

なお、ローカル環境(Mac)で実行すると正常に機能してしまいます。
更に、別のFlutterプロジェクトではローカル環境、GithubActionどちらも成功してしまいました。
動くこともある原因はわからないですが、とりあえずエラーメッセージを見てみましょう。

エラーメッセージでも書いてある様にanalyzer_plugin:0.13.0に、publiclyExporting2の関数がないことで、エラーとなっているようでした。

事例調査

ありました。

記事を書いている現在原因はわからないようですが、とりあえずの解決方法があるので参考にしました。
()

temporary workaround that is working for our project for now, is to pin the analyzer and plugin versions to the last known working versions in pubspec:

  analyzer: 7.3.0
  analyzer_plugin: 0.12.0

解決方法

pubspec.yamlに追加

pubspec.yamlに以下追加てみました。

dependency_overrides:
  analyzer: 7.3.0
  analyzer_plugin: 0.12.0

まだエラー

おそらくプロジェクトによってはこれで、GithubActionで動作するようになると思っていましたが、今度はbuild_runnerの実行時にエラーが出てきてしまいました。

Warning:  ../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:295:50: Error: The getter 'name3' isn't defined for the class 'FormalParameterElement'.
 - 'FormalParameterElement' is from 'package:analyzer/dart/element/element2.dart' ('../.pub-cache/hosted/pub.dev/analyzer-7.3.0/lib/dart/element/element2.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'name3'.
    var parameterNames = parameters.map((e) => e.name3).nonNulls.toSet();
                                                 ^^^^^
../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:318:28: Error: The getter 'name3' isn't defined for the class 'FormalParameterElement'.

このプロジェクトでは、openapi-generatorを利用しており、どうやらopenapi-generatorが、analyzerの古いバージョンに依存しているようでした。
GithubActionで使う都合上、dependency_overridesをpubspec.yamlに直接書いてしまうと、openapi-generatorでエラーとなってしまうようです。

更に修正

そこで、pubspec.yamlにdependency_overridesを記載するのは諦めて、flutter analyzeのときだけ、dependency_overridesを追加するようにActionsを変更する形にしてみました。

      - name: flutter build_runner
        run: |
          rps generate

      - name: lint
        if: ${{ matrix.actions == 'lint' }}
        run: |
# ここから追加
          flutter pub add override:analyzer:7.3.0
          flutter pub add override:analyzer_plugin:0.12.0
# ここまで
          flutter analyze

これでanalyzeの際のみdependency_overridesを追加するように対応しました。

まだエラー

Error from the analysis server: /home/runner/work/xxxx/xxxx/.pub-cache/hosted/pub.dev/custom_lint_visitor-1.0.0+7.4.5/lib/src/node_lint_visitor.g.dart:324:36: Error: Type 'DotShorthandInvocation' not found.
  void visitDotShorthandInvocation(DotShorthandInvocation node) {
                                   ^^^^^^^^^^^^^^^^^^^^^^

custom_lint_visitor:1.0.0+7.4.5にDotShorthandInvocationがないみたいです。

更に修正

以下のように修正してみました。

      - name: flutter build_runner
        run: |
          rps generate

      - name: lint
        if: ${{ matrix.actions == 'lint' }}
        run: |
# ここから追加
          flutter pub add override:analyzer:7.3.0
          flutter pub add override:analyzer_plugin:0.12.0
          flutter pub add override:custom_lint_visitor:1.0.0+7.1.0
# ここまで
          flutter analyze

動作しました!:raised_hands:

最後に

おそらく、リリース直後なので、各種ライブラリにバグ顕在化してきている状況かとおもいます。しばらく待つと、ライブラリがアップデートされて上記の修正は不要となるでしょう。一旦解消できたよ報告でした。
参考になれば幸いです。

ついでに宣伝

AppShotというアプリをチーム内で配信するサービスをリリースしています。
よかったら、使ってみてください。

3
0
2

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