Skip to content

It seems that build_runner crashes while using "flutter_localizations". #3946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FrancescoJo opened this issue Jun 19, 2023 · 5 comments · Fixed by #3949
Closed

It seems that build_runner crashes while using "flutter_localizations". #3946

FrancescoJo opened this issue Jun 19, 2023 · 5 comments · Fixed by #3949
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@FrancescoJo
Copy link

FrancescoJo commented Jun 19, 2023

It seems that build_runner crashes while using flutter_localizations.

Thanks for reading and we hope to see this error is fixed soon.

Environment

  • Dart version (run dart --version): 3.0.5 (stable)
  • OS kind and version (e.g. "Windows 10, version 1809" or "macOS 12.4"): Linux 5.19.0-43-generic on x86_64
  • Are you using the Chinese community mirror or a corporate firewall? nope

Problem

Error happens like below if we apply Internationalizing Flutter apps in our project.

$ flutter pub run build_runner build --delete-conflicting-outputs
Deprecated. Use `dart run` instead.
Null check operator used on a null value


package:pub/src/entrypoint.dart 562:48   Entrypoint.resolveExecutable
package:pub/src/executable.dart 79:35    runExecutable
package:pub/src/command/run.dart 100:26  RunCommand.runProtected

This is an unexpected error. The full log and other details are collected in:

    /home/USER/.pub-cache/log/pub_log.txt

Consider creating an issue on https://github.com/dart-lang/pub/issues/new
and attaching the relevant parts of that log file.

Expected behavior

Build should be successful and various files dependes on builld_runner are created.

Actual behavior

Cannot continue build unless we comment out build_runner.

--trace output

The pub_log.txt file:

Information about the latest pub run.

If you believe something is not working right, you can go to
https://github.com/dart-lang/pub/issues/new to post a new issue and attach this file.

Before making this file public, make sure to remove any sensitive information!

Pub version: 3.0.5
Created: 2023-06-19T09:43:09+09:00
FLUTTER_ROOT: /home/USER/snap/flutter/common/flutter
PUB_HOSTED_URL: <not set>
PUB_CACHE: "<not set>"
Command: dart pub --suppress-analytics run build_runner build --delete-conflicting-outputs
Platform: linux

---- /home/USER/documents/my_project/app/pubspec.yaml ----
name: my_project
description: My flutter project.
publish_to: none
version: 1.0.0+1

environment:
  sdk: ^3.0.5
  flutter: ^3.10.5

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  core:
    path: ../core/
  data:
    path: ../data/
  util:
    path: ../util/

  android_id: ^0.1.3+1
  flutter_bloc: ^8.1.1
  firebase_core: ^2.4.1
  firebase_messaging: ^14.2.1
  flutter_local_notifications: ^13.0.0
  firebase_analytics: ^10.1.0
  html: ^0.15.1
  intl: any
  rxdart: ^0.27.7
  tap_debouncer: ^2.0.2
  url_launcher: ^6.1.8
  webview_flutter: ^4.0.2
  webview_flutter_android: ^3.2.1
  webview_flutter_wkwebview: ^3.0.2
  shared_preferences: ^2.0.20
  go_router: 7.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  # Error occurs if we uncomment this dependency upon build. It seems that flutter l10n causes problems with dart build_runner. Read https://github.com/dart-lang/build/issues/2835 for further information.
  # 2023-06-01: Error still happens with version 2.3.3!!
  # build_runner: ^1.10.3
  bloc_test: ^9.1.1
  mockito: ^5.3.2
  network_image_mock: ^2.1.1
  flutter_lints: ^2.0.1
  faker: ^2.1.0


flutter:
  generate: true
  uses-material-design: true
  assets:
    - assets/images/
  fonts:
    - family: NotoSans
      fonts:
        - asset: assets/fonts/noto_sans/NotoSans-Regular.otf
          weight: 400
flutter_intl:
  enabled: true

---- End pubspec.yaml ----

---- /home/USER/documents/my_project/app/pubspec.lock ----
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
  _fe_analyzer_shared:
    dependency: transitive
    description:
      name: _fe_analyzer_shared
      sha256: "98d1d33ed129b372846e862de23a0fc365745f4d7b5e786ce667fcbbb7ac5c07"
      url: "https://pub.dev"
    source: hosted
    version: "55.0.0"
  _flutterfire_internals:
    dependency: transitive
    description:
      name: _flutterfire_internals
      sha256: "330d7fcbb72624f5b6d374af8b059b0ef4ba96ba5b8987f874964a1287eb617d"
      url: "https://pub.dev"
    source: hosted
    version: "1.0.18"
  analyzer:
    dependency: transitive
    description:
      name: analyzer
      sha256: "881348aed9b0b425882c97732629a6a31093c8ff20fc4b3b03fb9d3d50a3a126"
      url: "https://pub.dev"
    source: hosted
    version: "5.7.1"
  android_id:
    dependency: "direct main"
    description:
      name: android_id
      sha256: e60b3c96bf256014d6c1d0a03e2712ef49d717817c13cbdb4c72b939199a4993
      url: "https://pub.dev"
    source: hosted
    version: "0.1.3+1"
  args:
    dependency: transitive
    description:
      name: args
      sha256: "4cab82a83ffef80b262ddedf47a0a8e56ee6fbf7fe21e6e768b02792034dd440"
      url: "https://pub.dev"
    source: hosted
    version: "2.4.0"
  asn1lib:
    dependency: transitive
    description:
      name: asn1lib
      sha256: ab96a1cb3beeccf8145c52e449233fe68364c9641623acd3adad66f8184f1039
      url: "https://pub.dev"
    source: hosted
    version: "1.4.0"
  async:
    dependency: transitive
    description:
      name: async
      sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
      url: "https://pub.dev"
    source: hosted
    version: "2.11.0"
  bloc:
    dependency: transitive
    description:
      name: bloc
      sha256: "658a5ae59edcf1e58aac98b000a71c762ad8f46f1394c34a52050cafb3e11a80"
      url: "https://pub.dev"
    source: hosted
    version: "8.1.1"
  bloc_test:
    dependency: "direct dev"
    description:
      name: bloc_test
      sha256: ffbb60c17ee3d8e3784cb78071088e353199057233665541e8ac6cd438dca8ad
      url: "https://pub.dev"
    source: hosted
    version: "9.1.1"
  webkit_inspection_protocol:
    dependency: transitive
    description:
      name: webkit_inspection_protocol
      sha256: "67d3a8b6c79e1987d19d848b0892e582dbb0c66c57cc1fef58a177dd2aa2823d"
      url: "https://pub.dev"
    source: hosted
    version: "1.2.0"
  webview_flutter:
    dependency: "direct main"
    description:
      name: webview_flutter
      sha256: b6cd42db3ced5411f3d01599906156885b18e4188f7065a8a351eb84bee347e0
      url: "https://pub.dev"
    source: hosted
    version: "4.0.6"
  webview_flutter_android:
    dependency: "direct main"
    description:
      name: webview_flutter_android
      sha256: c849dcb6bf7367f696869006fb9575c15bdc6a1d624ae13f12de5a147a740b12
      url: "https://pub.dev"
    source: hosted
    version: "3.4.2"
  webview_flutter_platform_interface:
    dependency: transitive
    description:
      name: webview_flutter_platform_interface
      sha256: "1939c39e2150fb4d30fd3cc59a891a49fed9935db53007df633ed83581b6117b"
      url: "https://pub.dev"
    source: hosted
    version: "2.1.0"
  webview_flutter_wkwebview:
    dependency: "direct main"
    description:
      name: webview_flutter_wkwebview
      sha256: ab12479f7a0cf112b9420c36aaf206a1ca47cd60cd42de74a4be2e97a697587b
      url: "https://pub.dev"
    source: hosted
    version: "3.2.1"
  win32:
    dependency: transitive
    description:
      name: win32
      sha256: c9ebe7ee4ab0c2194e65d3a07d8c54c5d00bb001b76081c4a04cdb8448b59e46
      url: "https://pub.dev"
    source: hosted
    version: "3.1.3"
  xdg_directories:
    dependency: transitive
    description:
      name: xdg_directories
      sha256: bd512f03919aac5f1313eb8249f223bacf4927031bf60b02601f81f687689e86
      url: "https://pub.dev"
    source: hosted
    version: "0.2.0+3"
  xml:
    dependency: transitive
    description:
      name: xml
      sha256: "979ee37d622dec6365e2efa4d906c37470995871fe9ae080d967e192d88286b5"
      url: "https://pub.dev"
    source: hosted
    version: "6.2.2"
  yaml:
    dependency: transitive
    description:
      name: yaml
      sha256: "23812a9b125b48d4007117254bca50abb6c712352927eece9e155207b1db2370"
      url: "https://pub.dev"
    source: hosted
    version: "3.1.1"
sdks:
  dart: ">=3.0.0 <4.0.0"
  flutter: ">=3.3.0"

---- End pubspec.lock ----
---- Log transcript ----
FINE: Pub 3.0.5
MSG : Deprecated. Use `dart run` instead.
FINE: The pubspec.yaml file has changed since the pubspec.lock file was generated.
MSG : Resolving dependencies...
SLVR: fact: my_project is 1.0.0+1
SLVR: derived: my_project
ERR : Null check operator used on a null value
FINE: Exception type: _TypeError
ERR : package:pub/src/entrypoint.dart 562:48   Entrypoint.resolveExecutable
    | package:pub/src/executable.dart 79:35    runExecutable
    | package:pub/src/command/run.dart 100:26  RunCommand.runProtected
ERR : This is an unexpected error. The full log and other details are collected in:
    | 
    |     /home/USER/.pub-cache/log/pub_log.txt
    | 
    | Consider creating an issue on https://github.com/dart-lang/pub/issues/new
    | and attaching the relevant parts of that log file.
---- End log transcript ----

flutter doctor results:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.5, on Ubuntu 22.04.2 LTS 5.19.0-43-generic, locale en_GB.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2022.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.1)
[✓] IntelliJ IDEA Community Edition (version 2022.3)
[✓] VS Code (version 1.79.2)
[✓] Connected device (2 available)
[✓] Network resources
@sigurdm sigurdm added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Jun 19, 2023
@sigurdm
Copy link
Contributor

sigurdm commented Jun 20, 2023

Thanks for reporting!

So the crash in pub as reported here is a bug in pub, pub run should (after 3.0) do a dependency resolution if the pubspec.lock is out of date. We did that, but missed awaiting the result, ending up with a race-condition. All that is entirely unrelated to localization and build_runner.

The other side of the issue seems to be dart-lang/build#2835 where build_runner tries to follow the dependency graph by finding the pubspec.yaml of each package. But flutter pub get (not dart pub get) will create a synthetic package inside .dart_tool/ when flutter_gen: true is specified.
pub has special handling of this synthetic package, but build_runner doesn't and crashes.

Here is an issue about fixing this situation: flutter/flutter#102983

@FrancescoJo
Copy link
Author

@sigurdm Thanks for your rapid feedback. We're longing to see this error is fixed soon.

@FrancescoJo
Copy link
Author

@sigurdm Your comment was a great hint for us. We investigated the error situation again and changed our pubspec.yml like below:

pubspec.yml

environment:
  sdk: ^3.0.5
  flutter: ^3.10.5

dev_dependencies:
  build_runner: ^2.4.5

and did these things:

  1. dart pub cache clean
  2. delete all pubspec.lock files in modules
  3. flutter pub get && flutter pub run build_runner build
  4. IT WORKS!!

Thanks for your support. Hope this comment helps to other flutter devs.

@astronomico
Copy link

For my case - simple solution
I only have to remove flutter generate specification on pubspec.yaml with my localizations builds

#The following section is specific to Flutter packages.
flutter:
# generate: true // remove this

@WongueShin
Copy link

I'm not sure why this phenomenon occurs, but I have identified the following reproduction conditions and a solution.

Reproduction conditions:

If you run pub get even once in a Flutter package that depends on both l10n and build_runner, errors will occur in all subsequent "dart run build_runner build" operations.

Solution:

Delete the pubspec.lock file right before each "dart run build_runner build".
I have automated this process with a script that I am currently using.

I hope my case will be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants