brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.14k stars 255 forks source link

Conflict in libraries image: ^4.2.0 when used with crop_your_image: ^1.0.2 #653

Open Megatronicus opened 1 month ago

Megatronicus commented 1 month ago

/C:/Users/Computer/AppData/Local/Pub/Cache/hosted/pub.dev/crop_your_image-1.0.2/lib/src/logic/cropper/image_image_cropper.dart:13:1: Error: 'ImageFormat' is imported from both 'package:crop_your_image/src/logic/format_detector/format.dart' and 'package:image/src/formats/image_format.dart'. import 'package:image/image.dart'; ^^^^^^^^^^^ /C:/Users/Computer/AppData/Local/Pub/Cache/hosted/pub.dev/crop_your_image-1.0.2/lib/src/logic/cropper/image_image_cropper.dart:24:32: Error: Not a constant expression. ImageFormat outputFormat = ImageFormat.jpeg, ^^^^^^^^^^^ /C:/Users/Computer/AppData/Local/Pub/Cache/hosted/pub.dev/crop_your_image-1.0.2/lib/src/logic/cropper/image_image_cropper.dart:24:32: Error: 'ImageFormat' is imported from both 'package:crop_your_image/src/logic/format_detector/format.dart' and 'package:image/src/formats/image_format.dart'. ImageFormat outputFormat = ImageFormat.jpeg, ^^^^^^^^^^^ Target kernel_snapshot failed: Exception

FAILURE: Build failed with an exception.

BUILD FAILED in 1m 21s Error: Gradle task assembleDebug failed with exit code 1

Error appeared when trying to get dependencies to update pubspec

when using

image: ^4.2.0

with

crop_your_image: ^1.0.2

There was no conflict in the version image: ^4.1.7

Megatronicus commented 1 month ago

Just reverted back to image: ^4.1.7 and still getting the same error. crop_your_image library didn't change from crop_your_image: ^1.0.2, I did flutter clean and flutter pub get and still getting the error, a half an hour everything was working great until I decided to update pubspec and then this started happening.

brendan-duncan commented 1 month ago

I don't know crop_your_image, but the Dart way to avoid naming conflicts is to use namespaced imports.

Megatronicus commented 1 month ago

Thank you for answering but I'm not getting any indications of errors inside the classes where they're being used and I already have namespaced imports for image specifically, but not for crop_your_image. import 'package:crop_your_image/crop_your_image.dart'; import 'package:image/image.dart' as imglib;

No class is returning errors and this error message comes up during compile not when updating pubspec as I said above. The weird thing is even after downgrading back to image: ^4.1.7 I'm still getting the error even after flutter clean and flutter pub get. I don't get it.

Megatronicus commented 1 month ago

I did flutter pub cache clean flutter clean flutter pub get

Still getting the same error even after reverting to the version that was working image: ^4.1.7 I even returned the whole pubspec from before and still getting the same error. Should I use a separate namespace for crop_your_image just like I'm using for image right now so that both have a separate namespace or is this ok?

import 'package:crop_your_image/crop_your_image.dart'; import 'package:image/image.dart' as imglib;

I don't get it why reverting back doesn't fix the error.

brendan-duncan commented 1 month ago

ImageFormat was added in 4.2.0. But the error you first posted indicated there is an import 'package:image/image.dart'; somewhere that was not namespaced.

I wish dart had code namespaces in addition to import namespaces.

brendan-duncan commented 1 month ago

I think the import is happening by crop_your_image.

Maybe I'll rename my class.

Megatronicus commented 1 month ago

"I wish dart had code namespaces in addition to import namespaces." Yeah, that would be great.

I don't know what the best course of action would be but if you could rename the class and that would solve the problem that would be great. Please before you do go through all of that just check if this same problem occurs on your end too. I can't compile my project anymore because of this which means unless I find a fix I'll have to wait until you rename the class as it's an integral part of the app and thank you for making it. I just don't understand why reverting back didn't solve the problem, so there might be more going on here?

brendan-duncan commented 1 month ago

Reverting to image < 4.2.0 should work because there is no ImageFormat enum before then. So it must be a cache ghost haunting you.

brendan-duncan commented 1 month ago

I'm surprised issues like this don't come up more often. It's not like I was super creative with my naming "Image".

To be fare, I wrote this over 10 years ago, before Dart was even 1.0. There was no Flutter back then, and only a handful of libraries on pub. And naming things is hard.

Megatronicus commented 1 month ago

"Reverting to image < 4.2.0 should work because there is no ImageFormat enum before then. So it must be a cache ghost haunting you."

I'm going to try a couple of things, will report back, must be the cache yeah

"I'm surprised issues like this don't come up more often. It's not like I was super creative with my naming "Image".

To be fare, I wrote this over 10 years ago, before Dart was even 1.0. There was no Flutter back then, and only a handful of libraries on pub. And naming things is hard."

Haha, the naming is precise and on point, great job on that =) but yeah I was surprised when I saw the name that they allowed that and they didn't take it for themselves for some official library, it's good though still that naming doesn't come up that often as a problem, I seem to have a propensity for encountering problems though so here we are, lol. Will report back soon about the cache and reverting back.

Megatronicus commented 1 month ago

Well, I tried Invalidate Caches, didn't help, then tried to delete C:\Users\Computer.gradle\caches, now I get this

Launching lib\main.dart on sdk gphone64 x86 64 in debug mode... Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

BUILD FAILED in 4s

Probably shouldn't have done that. I'll probably reinstall Android Studio and flutter and write back tomorrow.

brendan-duncan commented 1 month ago

I would think it's a pub cache thing rather than a gradle thing, but I have very minimal knowledge of gradle, or flutter. $HOME/. pub-cache (on macOS and Linux), or in %LOCALAPPDATA%\Pub\Cache (on Windows). If you haven't already, maybe go through the directories in there and delete anything that is image-4.2.0.

brendan-duncan commented 1 month ago

Or maybe change your pubspec to use a specific version of image. I only know enough about pub to be dangerous.

Megatronicus commented 1 month ago

I reinstalled Android Studio, still got the same error. I tried making a new project, imported image and crop_your_image and a class where I'm using it and there's no conflict in the new project so now I have no clue what's going on.

brendan-duncan commented 1 month ago

The easiest fix would be to fix crop_your_image. I'll file an issue over there, https://github.com/chooyan-eng/crop_your_image/issues/157. Hopefully they can put out a quick fix by namespacing the image import in their package. I could rename the enum on my end, but I would probably make other people angry.

Megatronicus commented 1 month ago

It seems crop_your_image users encountered the same conflict

[https://github.com/chooyan-eng/crop_your_image/issues/155]

the developer already published a new version 1.1.0, for some reason pubspec recommends 1.0.2, it's not until I went to pubdev that I saw there was a 1.1.0 version there. Now there's no more conflict. I'm getting another error now not connected to this library, so onto solving. Thank you for responding so fast! Best regards.

brendan-duncan commented 1 month ago

I'm glad he got a fix out, and I'm sorry you're having so many troubles. Package management is a dark art, I don't think anyone's really gotten it figured out. And I'm prone to breaking things, an unfortunate result that I haven't even done any Dart programming in years other than supporting these libraries. I do enjoy working on them though, and I'm glad people find them useful.