leancodepl / flutter_webp

Asset transformer for converting images into WebP files.
https://pub.dev/packages/webp
Apache License 2.0
3 stars 0 forks source link

Transformer doesn't work for assets with resolution-aware variants #13

Open Albert221 opened 1 month ago

Albert221 commented 1 month ago

For assets that have their corresponding 2.0x/ variant, the transformer fails.

This may have something to do with the fact, that input and output paths is the same for all the resolution-aware variant files, command was ran with these params for logo_dark.png, 2.0x/logo_dark.png, and 3.0x/logo_dark.png:

input: /var/folders/mh/n8gr4_w94sndpqg3619xhxxh0000gn/T/flutter_tools.sUFfrh/logo_dark.png-transformOutput0.png output: /var/folders/mh/n8gr4_w94sndpqg3619xhxxh0000gn/T/flutter_tools.sUFfrh/logo_dark.png-transformOutput1.png
input: /var/folders/mh/n8gr4_w94sndpqg3619xhxxh0000gn/T/flutter_tools.sUFfrh/logo_dark.png-transformOutput0.png output: /var/folders/mh/n8gr4_w94sndpqg3619xhxxh0000gn/T/flutter_tools.sUFfrh/logo_dark.png-transformOutput1.png
input: /var/folders/mh/n8gr4_w94sndpqg3619xhxxh0000gn/T/flutter_tools.sUFfrh/logo_dark.png-transformOutput0.png output: /var/folders/mh/n8gr4_w94sndpqg3619xhxxh0000gn/T/flutter_tools.sUFfrh/logo_dark.png-transformOutput1.png

Reproduce

Change transformer args in example/pubspec.yaml to '--z=9', '--from_path' (so that the transformation takes enough time for the bug to occur.

When created an 2.0x/example_image.png in the example project inside this repository and building Web, this is the error output:

Target web_release_bundle failed: PathNotFoundException: Cannot copy file to 'build/web/assets/assets/images/2.0x/example_image.png', path = '/var/folders/mh/n8gr4_w94sndpqg3619xhxxh0000gn/T/flutter_tools.81PVsJ/example_image.png-transformOutput1.png' (OS Error: No such file or
directory, errno = 2)

So because the source and output files are the same, Flutter CLI also tries to copy the same file more than once which fails for all attempts except for the first one.

Albert221 commented 1 month ago

Bug report in Flutter repository created - https://github.com/flutter/flutter/issues/151813