dart-lang / pub

The pub command line tool
https://dart.dev/tools/pub/cmd
BSD 3-Clause "New" or "Revised" License
1.04k stars 224 forks source link

build_runner fail when using local package inside pubspec.yaml #4016

Closed EArminjon closed 1 year ago

EArminjon commented 1 year ago

I cannot run the following command :

flutter pub run build_runner build --delete-conflicting-output
The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated, please run "flutter pub get" again.
pub finished with exit code 65

I got this error since a add a local package inside my pubspec.yaml

dependencies:
  huawei_location:
    path: forked/huawei_location

In attachment the zip of the fork (it's light) : huawei_location.zip

jakemac53 commented 1 year ago

This is an error from pub, did you try running flutter pub get as instructed?

EArminjon commented 1 year ago

Yes, issue apear only when I add a dependency using the local path.

jakemac53 commented 1 year ago

In general, build_runner definitely works with local path dependencies, it doesn't care about dependency types at all.

Pub is what is erroring here, saying that you haven't ran a flutter pub get since adding that dependency.

Do you have some other tool which is touching the pubspec.lock file?

EArminjon commented 1 year ago

Here is my pubspec.yaml dependencies, what can i provide more to help ?

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

  intl: ^0.17.0
  visibility_detector: ^0.4.0+2
  shared_preferences: ^2.0.15
  flutter_bloc: ^8.1.1
  provider: ^6.0.5
  dartx: ^1.1.0
  rxdart: ^0.27.5
  equatable: ^2.0.5
  sqflite: ^2.2.6
  path_provider: ^2.0.11
  dio: ^4.0.6
  dartz: ^0.10.1
  cupertino_icons: ^1.0.5
  speech_to_text: ^6.0.0
  package_info_plus: ^3.0.1
  flutter_secure_storage: ^5.0.2
  connectivity_plus: ^2.3.9
  another_flushbar: ^1.12.31-dev.1
  flutter_pdfview: ^1.3.1
  permission_handler: ^10.1.0
  location: ^4.4.0
  flutter_svg: ^1.1.5
  firebase_core: ^2.1.1
  firebase_analytics: ^10.0.0
  firebase_crashlytics: ^3.0.4
  firebase_performance: ^0.9.0
  firebase_remote_config: ^4.2.4
  share_plus: ^6.1.0
  flutter_beep: ^1.0.0
  vibration: ^1.7.6
  flutter_spinkit: ^5.1.0
  app_tracking_transparency: ^2.0.2+4
  launch_review: ^3.0.1
  upgrader: ^5.1.0
  fluttertoast: ^8.0.9
  in_app_review: ^2.0.6
  mask_text_input_formatter: ^2.4.0
  font_awesome_flutter: ^10.3.0
  collection: ^1.16.0
  url_launcher: ^6.1.6
  device_info_plus: ^8.0.0
  logging: ^1.1.0
  disk_space: ^0.2.1
  infinite_scroll_pagination: ^3.2.0
  local_auth: ^2.1.2
  flutter_html: ^3.0.0-alpha.6
  screenshot: ^1.2.3
  crypto: ^3.0.2
  flutter_slidable: ^2.0.0
  flutter_mute: ^0.0.4
  flutter_native_splash: ^2.2.11
  cross_file: ^0.3.3+2
  flutter_inappwebview: ^5.7.2+3
  mime: ^1.0.2
  mobile_scanner: ^3.0.0
  freezed_annotation: ^2.2.0
  json_annotation: ^4.7.0
  get_it: ^7.2.0
  shimmer: ^2.0.0
  video_player: ^2.5.3
  youtube_player_iframe: ^4.0.4
  video_thumbnail: ^0.5.3
  photo_view:
    git:
      url: https://github.com/bluefireteam/photo_view.git
      ref: d2865d36766e5882bb4cccc91c1f64b91e287289
  carousel_slider: ^4.2.1
  currency_formatter: ^2.0.0
  flutter_datawedge: ^1.2.0
  synchronized: ^3.1.0
  alice: ^0.3.2
  cached_network_image: ^3.2.3
  jwt_decoder: ^2.0.1
  worldtime: ^1.0.9
  scrolls_to_top: ^2.1.0
  huawei_location:
    path: forked/huawei_location
  google_api_availability: ^5.0.0

# Temporary solve version issue with bloc_test requesting an older version of test and analyzer libraries
# which are not compatible with more recent packages like dart_code_metrics
dependency_overrides:
  analyzer: ^5.2.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_driver:
    sdk: flutter
  test: any

  dart_code_metrics: ^4.21.0
  bloc_test: ^9.1.0
  build_runner: ^2.2.1
  alchemist: ^0.6.1
  golden_toolkit: ^0.13.0
  lint: ^2.0.1
  sqflite_common_ffi: ^2.2.3
  freezed: ^2.3.2
  json_serializable: ^6.5.4
  flutter_gen: ^5.1.0+1
  source_gen: ^1.2.6
  mocktail: ^0.3.0
flutter:
  uses-material-design: true
  generate: true
jakemac53 commented 1 year ago

I went ahead and transferred this to the pub repo

jakemac53 commented 1 year ago
flutter:
  uses-material-design: true
  generate: true

The generate: true could be part of the issue, this has historically been problematic as it would end up doing some nasty hacks with your package config.

EArminjon commented 1 year ago

I tried to remove the generate:true, despite multiple flutter pub get the issue remain :/

jakemac53 commented 1 year ago

Can you flutter pub run any other tools? For instance flutter pub run test?

EArminjon commented 1 year ago

flutter test fail because of missing file (not generated because of previous issue)

jakemac53 commented 1 year ago

Note that flutter test is not the same as flutter pub run test - please try the latter. It is fine if it fails to compile some tests - I want to know if it can even run the test binary at all (which doesn't import any of your code).

EArminjon commented 1 year ago

Oh my bad so !

$> flutter pub run test            
The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated, please run "flutter pub get" again.
pub finished with exit code 65
jakemac53 commented 1 year ago

Yeah, so that confirms this is not related to build_runner but pub in some way.

EArminjon commented 1 year ago

To bring more data : I well tested to copy & code the local repo on a github repo to use the 'git' instead of 'path' property and it well work. So yep, real issue around the path property.

sigurdm commented 1 year ago

Do you think you can narrow this down to a small example that we can use for reproduction?

EArminjon commented 1 year ago

Reproductible project : https://github.com/EArminjon/flutter-issue

flutter pub get && flutter pub run build_runner build --delete-conflicting-outputs

It seems to be related to the package flutter_gen ! You can close it if it's well out of your scope.

https://github.com/FlutterGen/flutter_gen/issues/374

sigurdm commented 1 year ago

Yeah, I think this is related to flutter_gen, see also (https://github.com/dart-lang/pub/issues/3314). I think you can use flutter_gen_runner instead.

fwiw I cannot reproduce with your example. What version of flutter are you using.

git clone https://github.com/EArminjon/flutter-issue
Cloning into 'flutter-issue'...
[...]
> cd flutter-issue/
> flutter pub get

┌─────────────────────────────────────────────────────────┐
│ A new version of Flutter is available!                  │
│                                                         │
│ To update to the latest version, run "flutter upgrade". │
└─────────────────────────────────────────────────────────┘
Resolving dependencies... (3.5s)
[...]
Changed 8 dependencies!
> flutter pub run build_runner build --delete-conflicting-outputs
[...]
[INFO] Succeeded after 126ms with 0 outputs (0 actions)
⏎                                                                                                                              
sigurdm@elevator ~/p/flutter-issue (master)> flutter --version
Flutter 3.10.5 • channel stable • https://github.com/flutter/flutter
Framework • revision 796c8ef792 (3 months ago) • 2023-06-13 15:51:02 -0700
Engine • revision 45f6e00911
Tools • Dart 3.0.5 • DevTools 2.23.1
EArminjon commented 1 year ago

I use flutter 3.7.12

EArminjon commented 1 year ago

Fixed in 3.10.5