mobile_scanner icon indicating copy to clipboard operation
mobile_scanner copied to clipboard

Doesn't work with `flutter build --ios-framework`

Open dJani97 opened this issue 1 year ago • 6 comments

Description

I've built a Flutter module that relies on this package, and running it standalone (with flutter run) works perfectly on my iPhone.

I'm following the guide Adding Flutter to iOS -> Option B - Embed frameworks in Xcode to embed my Flutter module into an existing native iOS application.

But after completing the steps in the guide, I ran into the following error when building the iOS app:

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_MLKBarcode", referenced from:
      objc-class-ref in mobile_scanner(SwiftMobileScannerPlugin.o)
      objc-class-ref in mobile_scanner(MobileScanner.o)
  "_OBJC_CLASS_$_MLKBarcodeAddress", referenced from:
      objc-class-ref in mobile_scanner(MobileScanner.o)
      objc-class-ref in mobile_scanner(MobileScannerUtilities.o)
  "_OBJC_CLASS_$_MLKBarcodeEmail", referenced from:
      objc-class-ref in mobile_scanner(MobileScanner.o)
      objc-class-ref in mobile_scanner(MobileScannerUtilities.o)
  "_OBJC_CLASS_$_MLKBarcodePhone", referenced from:
      objc-class-ref in mobile_scanner(MobileScanner.o)
      objc-class-ref in mobile_scanner(MobileScannerUtilities.o)
  "_OBJC_CLASS_$_MLKBarcodeScanner", referenced from:
      objc-class-ref in mobile_scanner(MobileScanner.o)
  "_OBJC_CLASS_$_MLKBarcodeScannerOptions", referenced from:
      objc-class-ref in mobile_scanner(SwiftMobileScannerPlugin.o)
  "_OBJC_CLASS_$_MLKVisionImage", referenced from:
      objc-class-ref in mobile_scanner(MobileScanner.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Suspected cause

Running flutter build --ios-framework generates the following frameworks:

$ ls Flutter/Debug:

App.xcframework
FBLPromises.xcframework
Flutter.xcframework
FlutterPluginRegistrant.xcframework
GTMSessionFetcher.xcframework
GoogleDataTransport.xcframework
GoogleToolboxForMac.xcframework
GoogleUtilities.xcframework
GoogleUtilitiesComponents.xcframework
Protobuf.xcframework
mobile_scanner.xcframework
nanopb.xcframework
permission_handler_apple.xcframework

So I've linked these frameworks with the existing native iOS app in Xcode, carefuly following the steps in the guide. But among these frameworks, I can't see any of the MLKit frameworks that the above error message refers to.

Looking at the .ios folder of my Flutter project (not the existing native iOS app that I'm trying to extend with Flutter), I can see what frameworks are used by it:

Screenshot 2023-03-14 at 0 56 23

Here I can see 4 frameworks that are not included by the flutter build --ios-framework command:

  • MLImage
  • MLKitBarcodeScanning
  • MLKitCommon
  • MLKitVision

So my suspicion is that for some reason, these frameworks are not generated properly by the flutter build --ios-framework command, and that's why the build fails. But I'm not sure, it's just speculation from my part.

Any ideas on how I could fix this problem?

I'm using Flutter 3.7.7, and I've tried a couple different versions of mobile_scanner: 3.0.0, 2.1.0, 1.1.1

dJani97 avatar Mar 14 '23 00:03 dJani97

Any solution?

abhayam17 avatar Apr 27 '23 08:04 abhayam17

A possible workaround is to use the older qr_code_scanner library for iOS builds. But this isn't ideal, as that library is maintenance-only.

dJani97 avatar Apr 27 '23 09:04 dJani97

any update on this issue ?

diabloo avatar Jun 16 '23 14:06 diabloo

As the OP says, it's due the missing xcframework for the MLKit. So, I copied those from Pods folder and manually created the xcframeworks . Just download this package and place it wherever you need. In OP's case, that would be Flutter/Debug.

MLKit_xcframework.zip

I will update again once I have found a better way to fix it.

NOTE: only ios-arm64 supported and dSYM not included. You might not be able to run on simulator.

Screenshot 2023-06-21 at 7 42 27 PM

thet-pi avatar Jun 21 '23 12:06 thet-pi

@thet-pi Do you have xcframworks for all architectures? It would be greatly appreciated.

fr-zhangduanfang avatar Dec 12 '23 10:12 fr-zhangduanfang

As the OP says, it's due the missing xcframework for the MLKit. So, I copied those from Pods folder and manually created the xcframeworks . Just download this package and place it wherever you need. In OP's case, that would be Flutter/Debug.

MLKit_xcframework.zip

I will update again once I have found a better way to fix it.

NOTE: only ios-arm64 supported and dSYM not included. You might not be able to run on simulator.

Screenshot 2023-06-21 at 7 42 27 PM

Hi! I have tried to do the same and the ios host app was compiled fine. But when the ui was drawn on the screen, an error appeared and when you click on the button to go to the Flutter application, nothing happens...

[ERROR:flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.mm(42)] Using the Impeller rendering backend. 2024-03-29 15:30:00.998411+0300 IOSQrHost[1160:44020] Initialized TensorFlow Lite runtime. INFO: Initialized TensorFlow Lite runtime. 2024-03-29 15:30:01.000370+0300 IOSQrHost[1160:44020] Created TensorFlow Lite XNNPACK delegate for CPU. INFO: Created TensorFlow Lite XNNPACK delegate for CPU. 2024-03-29 15:30:01.232346+0300 IOSQrHost[1160:44253] -[MLKITx_CCTLogContext hashForFilePath]: unrecognized selector sent to instance 0x2831b5dc0 2024-03-29 15:30:01.233288+0300 IOSQrHost[1160:44253] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MLKITx_CCTLogContext hashForFilePath]: unrecognized selector sent to instance 0x2831b5dc0' *** First throw call stack: (0x180e5fc60 0x19868fee4 0x180f306e8 0x180df954c 0x180df875c 0x1032fe3d8 0x1032fc044 0x1032fbf64 0x1032fb8fc 0x1032fb19c 0x104048700 0x104049fc8 0x104051150 0x104051e10 0x10405d63c 0x1dc284e00 0x1dc28492c) libc++abi: terminating with uncaught exception of type NSException

MaksimKischenko avatar Mar 29 '24 12:03 MaksimKischenko