fluttercandies/flutter_image_compress

Undefined symbol: _SDImageCoderEncodeCompressionQuality

Closed this issue ยท 18 comments

This is not working for me. pod update & pod install > flutter clean > restart. ๐Ÿ™

Undefined symbols for architecture x86_64:
  "_SDImageCoderEncodeCompressionQuality", referenced from:
      +[CompressHandler compressDataWithImage:quality:format:] in CompressHandler.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Undefined symbol: _SDImageCoderEncodeCompressionQuality



flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[โœ“] Flutter (Channel stable, 1.22.1, on Mac OS X 10.15.7 19H2, locale en-GB)
 
[โœ“] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[โœ“] Xcode - develop for iOS and macOS (Xcode 12.0.1)
[โœ“] Android Studio (version 4.0)
[โœ“] IntelliJ IDEA Ultimate Edition (version 2020.1.1)
[โœ“] Connected device (1 available)

I can't reproduce it.

Try updating ruby to latest version.

ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]

This is a bug on the webp conversion. I had the same problem. Since I do not need the webp, I just went to the problematic code and commented it out:

File: CompressHandler.m

(NSData *)compressDataWithImage:(UIImage *)image quality:(float)quality format:(int)format  {
    NSData *data;
    if (format == 2) { // heic
        CIImage *ciImage = [CIImage imageWithCGImage:image.CGImage];
        CIContext *ciContext = [[CIContext alloc]initWithOptions:nil];
        NSString *tmpDir = NSTemporaryDirectory();
        double time = [[NSDate alloc]init].timeIntervalSince1970;
        NSString *target = [NSString stringWithFormat:@"%@%.0f.heic",tmpDir, time * 1000];
        NSURL *url = [NSURL fileURLWithPath:target];
        
        NSMutableDictionary *options = [NSMutableDictionary new];
        NSString *qualityKey = (__bridge NSString *)kCGImageDestinationLossyCompressionQuality;
//        CIImageRepresentationOption
        [options setObject:@(quality / 100) forKey: qualityKey];
        
        if (@available(iOS 11.0, *)) {
            [ciContext writeHEIFRepresentationOfImage:ciImage toURL:url format: kCIFormatARGB8 colorSpace: ciImage.colorSpace options:options error:nil];
            data = [NSData dataWithContentsOfURL:url];
        } else {
            // Fallback on earlier versions
            data = nil;
        }
    } else if(format == 3){ // webp I COMMENTED ALL OF THIS OUT
        //SDImageCoderOptions *option = @{SDImageCoderEncodeCompressionQuality: @(quality / 100)};
        //data = [[SDImageWebPCoder sharedCoder]encodedDataWithImage:image format:SDImageFormatWebP options:option];
    } else if(format == 1){ // png
        data = UIImagePNGRepresentation(image);
    }else { // 0 or other is jpeg
        data = UIImageJPEGRepresentation(image, (CGFloat) quality / 100);
    }

    return data;
}

it works.
I honestly tried figuring out what that code meant, and I do know a lot of C++/C, js, dart, java.
But Objective-C is the most cryptographic language I know, I can't understand what the @ means, or the ":" - it is really hieroglyphs for me... (I did not spend that much time though, on a tight deadline now)
Best!

I am also having this issue when trying to build for iOS.

Updating deployment target fixes it.

image

The error is shown because somewhere the deployment target is below 9.0
This might happen even if YOU have the deployment target set to 9.0, or check if any other plugin was set to target < 9.0.

In my case the plugin http_certificate_pinning wasn't updated in a while &
therefore it's target was set to 8.0 which led to this issue.

This is a bug on the webp conversion. I had the same problem. Since I do not need the webp, I just went to the problematic code and commented it out:
...

Comment code is not a fix (not even a workaround) >.<

I am also having this issue when trying to build for iOS, it doesn't happen with the solution proposed by @diver2

In my case, executing XCode clean build folder, with option button, is working for me

Deplying past 9.0. This error has returned in Flutter 2.0.

I experienced the issue and decided to use version 0.6.4 that doesn't support webp for iOS

issue fixed by changing the deployment target from 8 to 11
thanks @humazed

issue still present on 12.0 and 12.1

SDImageCoderEncodeCompressionQuality come from SDWebImage, So in flutter_image_compress.podspec should add s.dependency 'SDWebImage'

try change your build target, then go to xcode > product > clean build folder > run app

This is a bug on the webp conversion. I had the same problem. Since I do not need the webp, I just went to the problematic code and commented it out:

File: CompressHandler.m

(NSData *)compressDataWithImage:(UIImage *)image quality:(float)quality format:(int)format  {
    NSData *data;
    if (format == 2) { // heic
        CIImage *ciImage = [CIImage imageWithCGImage:image.CGImage];
        CIContext *ciContext = [[CIContext alloc]initWithOptions:nil];
        NSString *tmpDir = NSTemporaryDirectory();
        double time = [[NSDate alloc]init].timeIntervalSince1970;
        NSString *target = [NSString stringWithFormat:@"%@%.0f.heic",tmpDir, time * 1000];
        NSURL *url = [NSURL fileURLWithPath:target];
        
        NSMutableDictionary *options = [NSMutableDictionary new];
        NSString *qualityKey = (__bridge NSString *)kCGImageDestinationLossyCompressionQuality;
//        CIImageRepresentationOption
        [options setObject:@(quality / 100) forKey: qualityKey];
        
        if (@available(iOS 11.0, *)) {
            [ciContext writeHEIFRepresentationOfImage:ciImage toURL:url format: kCIFormatARGB8 colorSpace: ciImage.colorSpace options:options error:nil];
            data = [NSData dataWithContentsOfURL:url];
        } else {
            // Fallback on earlier versions
            data = nil;
        }
    } else if(format == 3){ // webp I COMMENTED ALL OF THIS OUT
        //SDImageCoderOptions *option = @{SDImageCoderEncodeCompressionQuality: @(quality / 100)};
        //data = [[SDImageWebPCoder sharedCoder]encodedDataWithImage:image format:SDImageFormatWebP options:option];
    } else if(format == 1){ // png
        data = UIImagePNGRepresentation(image);
    }else { // 0 or other is jpeg
        data = UIImageJPEGRepresentation(image, (CGFloat) quality / 100);
    }

    return data;
}

it works.
I honestly tried figuring out what that code meant, and I do know a lot of C++/C, js, dart, java.
But Objective-C is the most cryptographic language I know, I can't understand what the @ means, or the ":" - it is really hieroglyphs for me... (I did not spend that much time though, on a tight deadline now)
Best!

worst advice

try change your build target, then go to xcode > product > clean build folder > run app

this worked for me.

Why the need to dunk on someone else? From the feedback, this supposedly helped some people 9 months ago.
Yes, changing build target now works as well.

Should be fixed by #182 .