Skip to content
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

Conflict build process when used with build_runner #14

Closed
hiaw opened this issue Nov 27, 2019 · 11 comments
Closed

Conflict build process when used with build_runner #14

hiaw opened this issue Nov 27, 2019 · 11 comments

Comments

@hiaw
Copy link

hiaw commented Nov 27, 2019

I was trying to do JSON parsing and the recommended way uses build_runner. But after build_runner ran, the asset.dart file is deleted.

Running flutter generate again will not regenerate asset.dart.

Currently just doing JSON parsing by hand instead of the recommended way but would be great if we can solve this.

@hiaw hiaw changed the title Conflict build process with used with build_runner Conflict build process when used with build_runner Nov 27, 2019
@szotp
Copy link
Contributor

szotp commented Dec 5, 2019

I think the manual method of generation still works:

flutter packages pub run r_flutter:generate --intl-file="lib/resources/i18n/de.arb"

it would be nice to document it. Perhaps it could also use config from pubspec instead of command line arguments (intl-file, etc.).

@kuhnroyal
Copy link

Seems to work when you add it to dev_dependencies instead of builders.

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: 1.7.2
  r_flutter: 0.4.1

@hiaw
Copy link
Author

hiaw commented Dec 5, 2019

@kuhnroyal I just tried that and flutter generate no longer generate the correct files.

@szotp
Copy link
Contributor

szotp commented Dec 5, 2019

@hiaw correct, if you want to run from command line (the old method), then there is no point in calling flutter generate.

@hiaw
Copy link
Author

hiaw commented Dec 5, 2019

@hiaw correct, if you want to run from command line (the old method), then there is no point in calling flutter generate.

Sorry I must have missed something. There's a new method? Or do you mean the manual method you commented before? I only see flutter generate in the ReadMe.

@szotp
Copy link
Contributor

szotp commented Dec 5, 2019

There are multiple ways of doing code generation in flutter:

  1. Adding package to builders: - r_flutter currently uses it.
  2. build_runner, used by json_serializable.
  3. Command line utility - before r_flutter used method 1, it used this.

As you have noticed, methods 1 and 2 do not play nicely with each other, so you can switch to method 3 for r_flutter. Readme does not mention it, but it still works.

@timfreiheit
Copy link
Owner

Sorry for the late response.
For now I had no luck making the generation work with build_runner as well.
#15 will document this and align the command line usage to the normal generation process to have the same configuration step using the pubspec.yaml
I hope this helps for now.

@szotp
Copy link
Contributor

szotp commented Dec 10, 2019

One problem with manually generating the file is that people will want to commit it, and then absolute paths in asset docs do not look great.

I tried to find a solution for VSCode but found nothing. I created a feature request to support relative paths, but it may be never implemented: microsoft/vscode#86564

The same problem probably exists in Android Studio.

@maks
Copy link

maks commented Dec 20, 2019

I agree with commiting the generated file, but actually I dont see the need to have absolute paths in the comments of the generated file. For image paths VSC's Dartcode plugin will give you a gutter preview of the image using only a relative file path in the actual static's value without needing the code comment at all.

In regards to using builders need to note that that functionality is currently broken and the breakage has made it all the way into current stable channel release: flutter/flutter#42003

@maks
Copy link

maks commented Dec 20, 2019

Sorry I stand corrected, looks like the general recommendation is not to commit generated files. I do wonder then about requiring a build step for then running the code generator when building in a CI system, but perhaps thats taken care of by Flutters new builders: once the current bug is fixed.

@szotp
Copy link
Contributor

szotp commented Jan 21, 2020

Slightly offtopic, but I need 10 more upvotes for the VSCode feature request that I have posted. Otherwise they will just close it. All help appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants