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 in libraries image: ^4.2.0 when used with crop_your_image: ^1.0.2 #653

Open
Megatronicus opened this issue May 29, 2024 · 17 comments

Comments

@Megatronicus
Copy link

/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.

  • What went wrong:
    Execution failed for task ':app:compileFlutterBuildDebug'.

Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

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
Copy link
Author

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
Copy link
Owner

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

@Megatronicus
Copy link
Author

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Owner

I think the import is happening by crop_your_image.

Maybe I'll rename my class.

@Megatronicus
Copy link
Author

"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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

"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
Copy link
Author

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.

  • What went wrong:
    java.util.concurrent.ExecutionException: org.gradle.api.GradleException: Failed to create Jar file C:\Users\Computer.gradle\caches\jars-9\842fa7fdff1ae2bf257faa84bc187276\gradle-1.0.0.jar.

org.gradle.api.GradleException: Failed to create Jar file C:\Users\Computer.gradle\caches\jars-9\842fa7fdff1ae2bf257faa84bc187276\gradle-1.0.0.jar.

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

BUILD FAILED in 4s

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

@brendan-duncan
Copy link
Owner

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
Copy link
Owner

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

@Megatronicus
Copy link
Author

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
Copy link
Owner

The easiest fix would be to fix crop_your_image. I'll file an issue over there, chooyan-eng/crop_your_image#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
Copy link
Author

Megatronicus commented May 29, 2024

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
Copy link
Owner

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.

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

2 participants