firebase / quickstart-ios

Firebase Quickstart Samples for iOS
https://firebase.google.com
Apache License 2.0
2.78k stars 1.47k forks source link

MLVisionTextModel duplicate symbols with React Native #487

Closed zsajjad closed 5 years ago

zsajjad commented 6 years ago

I'm building an app with React Native that I've already "ejected" into its own native app project for iOS. I'm interested in using the new Firebase ML Kit Vision Text Detector for recognizing text in images using the on-device model, and I'm willing to write my own NativeModule wrapper for it (since it's so new, I don't see any existing wrappers in projects like react-native-firebase).

So, I used Cocoapods to bring in the Firebase dependencies, but when I try to compile the new workspace, I get the following linker error:

duplicate symbol __ZN3fLB28FLAGS_nosymbolize_stacktraceE in:
    /Users/zainsajjad/Desktop/development/ios/Pods/GoogleMobileVision/TextDetector/Frameworks/TextDetector.framework/TextDetector(examine_stack_b03c119c7358b452600b1afd20ca186c.o)
    /Users/zainsajjad/Library/Developer/Xcode/DerivedData/app-hfkgohktkkwcwocawuqzpgjzslrk/Build/Products/Debug-iphonesimulator/libReact.a(utilities.o)
duplicate symbol __ZN3fLB26FLAGS_symbolize_stacktraceE in:
    /Users/zainsajjad/Desktop/development/ios/Pods/GoogleMobileVision/TextDetector/Frameworks/TextDetector.framework/TextDetector(examine_stack_b03c119c7358b452600b1afd20ca186c.o)
    /Users/zainsajjad/Library/Developer/Xcode/DerivedData/app-hfkgohktkkwcwocawuqzpgjzslrk/Build/Products/Debug-iphonesimulator/libReact.a(utilities.o)
duplicate symbol __ZN3fLB18FLAGS_nolog_prefixE in:
    /Users/zainsajjad/Desktop/development/ios/Pods/GoogleMobileVision/TextDetector/Frameworks/TextDetector.framework/TextDetector(logging_2072041cb58f7b92d4eb8dae33e75a0d.o)
    /Users/zainsajjad/Library/Developer/Xcode/DerivedData/app-hfkgohktkkwcwocawuqzpgjzslrk/Build/Products/Debug-iphonesimulator/libReact.a(logging.o)
duplicate symbol __ZN3fLB16FLAGS_log_prefixE in:
    /Users/zainsajjad/Desktop/development/ios/Pods/GoogleMobileVision/TextDetector/Frameworks/TextDetector.framework/TextDetector(logging_2072041cb58f7b92d4eb8dae33e75a0d.o)
    /Users/zainsajjad/Library/Developer/Xcode/DerivedData/app-hfkgohktkkwcwocawuqzpgjzslrk/Build/Products/Debug-iphonesimulator/libReact.a(logging.o)
duplicate symbol __ZN3fLI9FLAGS_novE in:
    /Users/zainsajjad/Library/Developer/Xcode/DerivedData/app-hfkgohktkkwcwocawuqzpgjzslrk/Build/Products/Debug-iphonesimulator/libReact.a(vlog_is_on.o)
    /Users/zainsajjad/Desktop/development/ios/Pods/GoogleMobileVision/TextDetector/Frameworks/TextDetector.framework/TextDetector(vlog_is_on_ec23571a5409c45b7e2ca681c18af4cb.o)
duplicate symbol __ZN3fLI7FLAGS_vE in:
    /Users/zainsajjad/Library/Developer/Xcode/DerivedData/app-hfkgohktkkwcwocawuqzpgjzslrk/Build/Products/Debug-iphonesimulator/libReact.a(vlog_is_on.o)
    /Users/zainsajjad/Desktop/development/ios/Pods/GoogleMobileVision/TextDetector/Frameworks/TextDetector.framework/TextDetector(vlog_is_on_ec23571a5409c45b7e2ca681c18af4cb.o)
duplicate symbol __ZN3fLS13FLAGS_vmoduleE in:
    /Users/zainsajjad/Library/Developer/Xcode/DerivedData/app-hfkgohktkkwcwocawuqzpgjzslrk/Build/Products/Debug-iphonesimulator/libReact.a(vlog_is_on.o)
    /Users/zainsajjad/Desktop/development/ios/Pods/GoogleMobileVision/TextDetector/Frameworks/TextDetector.framework/TextDetector(vlog_is_on_ec23571a5409c45b7e2ca681c18af4cb.o)
ld: 7 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This issue appears when I add 'Firebase/MLVisionTextModel' in podspecs. In case I don't add this as a dependency, it returns an empty array on the images having a good amount of text!

morganchen12 commented 6 years ago

By podspec do you mean Podfile? Can you share your Podfile? TextDetector is a static dependency and it looks like it's being linked twice into your project.

morganchen12 commented 6 years ago

Update: it looks like GMV and React Native have a shared c++ dependency that's causing these symbol collisions. It's unlikely that there are good workarounds for this on your end, so you'll probably have to wait for a Firebase (or RN) fix.

I'll keep this issue updated.

zsajjad commented 6 years ago

I am trying to publish a wrapper for MLKit Vision for React Native. Here is the podspec.

I also tried

  s.dependency     'Firebase/Core'
  s.dependency     'Firebase/MLVision'
  s.dependency     'Firebase/MLVisionTextModel'

My Project's Podfile looks like this:

platform :ios, '11.3'

target 'myApp' do
  rn_path = '../node_modules/react-native'
  rn_maps_path = '../node_modules/react-native-maps'

  # See http://facebook.github.io/react-native/docs/integration-with-existing-apps.html#configuring-cocoapods-dependencies
  pod 'yoga', path: "#{rn_path}/ReactCommon/yoga/yoga.podspec"
  pod 'React', path: rn_path, subspecs: [
    'Core',
    'CxxBridge',
    'DevSupport',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
  ]

  pod 'RNTextDetector', path: '../node_modules/react-native-text-detector/ios'
  pod 'react-native-camera', path: '../node_modules/react-native-camera'
  pod 'lottie-ios', :path => '../node_modules/lottie-ios'
  pod 'lottie-react-native', :path => '../node_modules/lottie-react-native'
  pod 'react-native-maps', path: rn_maps_path
  pod 'react-native-google-maps', path: rn_maps_path 

  # React Native third party dependencies podspecs
  pod 'DoubleConversion', :podspec => "#{rn_path}/third-party-podspecs/DoubleConversion.podspec"
  pod 'glog', :podspec => "#{rn_path}/third-party-podspecs/glog.podspec"
  pod 'Folly', :podspec => "#{rn_path}/third-party-podspecs/Folly.podspec"

  # react-native-maps dependencies
  pod 'GoogleMaps'
  pod 'Google-Maps-iOS-Utils'
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'react-native-google-maps'
      target.build_configurations.each do |config|
        config.build_settings['CLANG_ENABLE_MODULES'] = 'No'
      end
    end
    if target.name == "React"
      target.remove_from_project
    end
  end
end
rmusetti81 commented 6 years ago

Sorry any news on problem? I have the same problem with nativa app ios in swift. Any idea?

morganchen12 commented 6 years ago

@rmusetti81 you should not be running into this issue when developing a native app in Swift. Please open a new issue with all of your build information (Podfile, Podfile.lock, CocoaPods version, Xcode version).

joan-domingo commented 6 years ago

Hi @zsajjad ! I had the exact same issue using react native and I solved enabling the dead code stripping in xcode for debug. You can enable it in Target > Build Settings > search for "Dead code stripping". For now seems to work fine.

zsajjad commented 6 years ago

I made my own package that uses firebase ml vision on android and CoreML+TesseractOCR on ios!

zsajjad commented 5 years ago

@joan-domingo's solution works fine. For people looking here, you can use react-native-text-detector firebase branch as a wrapper around firebase ML Kit Vision.