mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.55k stars 1.1k forks source link

🐛 Cannot read property '__callAsync' of undefined only on iOS production #1384

Closed johanmic closed 1 year ago

johanmic commented 1 year ago

What were you trying to do?

spent over a week deep diving on this. Can’t figure out this issue.

Cannot read property '__callAsync' of undefined

TypeError: Cannot read property '__callAsync' of undefined
    at _f (/[path]/app/node_modules/react-native-vision-camera/src/hooks/useFrameProcessor.ts (28:21):1:183)
    at _f (native)

Apps work fine on Android, development and production.

Works fine on iOS on devices in development but frame processors do not work on iOS archived production / testflight. Having tried react-native 0.66.4, 0.69.6, 0.70.6 Tried react-native-reanimated from 2.5 to 2.13 (crashed before 2.8)

Tried Xcode 14 and 13.4 With and without hermes.

react-native-vision-camera 2.14 with patch and latest 2.15 Ensured CLANG_CXX_LANGUAGE_STANDARD to match between reanimated, vision camera and Hermes.

{
    "react-native": "0.70.6",
    "react-native-reanimated": "2.13.0",
    "react-native-vision-camera": "2.15.2",
    "vision-camera-code-scanner": "^0.2.0",
    "vision-camera-ocr": "^1.0.0",
    "@react-native-firebase”: 14.11.0

}

Podfile

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
ENV['SWIFT_VERSION'] = '5.2'
$iOSMinimumDeployVersion = '13.0'
$flipperkit_version = '0.161.0'
install! 'cocoapods', :deterministic_uuids => false
$RNFirebaseAnalyticsWithoutAdIdSupport=true
platform :ios, '13.0'

def sharedPods
  config = use_native_modules!
  production = ENV["PRODUCTION"] == "1"
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    :production => production,
    :hermes_enabled => true,
    :fabric_enabled => flags[:fabric_enabled],
    :flipper_configuration => FlipperConfiguration.enabled(["Debug"], { 'Flipper' => $flipperkit_version }),
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  permissions_path = '../node_modules/react-native-permissions/ios'
  rn_maps_path = '../node_modules/react-native-maps'
  pod 'React', :path => '../node_modules/react-native/'
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
  pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts"
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
  pod 'react-native-google-maps', :path => rn_maps_path
  pod 'GoogleMaps', '7.0.0'
  pod 'Google-Maps-iOS-Utils'
  pod 'VisionCamera', :path => '../node_modules/react-native-vision-camera'

  # flipper_configuration!({'Flipper' => $flipperkit_version}) # should match the version of your Flipper client app
end

target 'app' do
  sharedPods
end
target 'app development' do
  sharedPods
end
# end
post_install do |installer|
  flipper_post_install(installer)
  react_native_post_install(
    installer,
    :mac_catalyst_enabled => false
  )
  __apply_Xcode_12_5_M1_post_install_workaround(installer)

   installer.pods_project.targets.each do |target|
     target.build_configurations.each do |config|
       config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12'
       config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = "arm64"
       config.build_settings['SWIFT_VERSION'] = '5.2'
     end
   end

   installer.pods_project.build_configurations.each do |config|
     config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12'
   end

   installer.generated_projects.each do |project|
    project.targets.each do |target|
      target.build_configurations.each do |config|
          config.build_settings["DEVELOPMENT_TEAM"] = "TEAMID"
        end
    end
  end

    installer.target_installation_results.pod_target_installation_results
      .each do |pod_name, target_installation_result|
      target_installation_result.resource_bundle_targets.each do |resource_bundle_target|
        resource_bundle_target.build_configurations.each do |config|
          config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
        end
      end
    end
  `sed -i -e  $'s/__IPHONE_10_0/__IPHONE_14_0/' Pods/RCT-Folly/folly/portability/Time.h`   
 end

.podspec

 Pod::Spec.new do |spec|
    spec.compiler_flags = '-fno-modules'
    s.swift_version = "5.2"
  end

Considering writing the frame processors ourselves but feels like this is close and have a hunch its a build Issue solved from Podfile.

Using multiple frame processors (OCR / QR) reader but get the same results building with either or.

Suggestions?

Reproduceable Code

<Camera
              audio={false}
              device={device}
              isActive={isFocused}
              frameProcessorFps={1}
              frameProcessor={frameProcessorQR}
              photo
              zoom={1}
              onLayout={(event: LayoutChangeEvent) => {
                setPixelRatio(
                  event.nativeEvent.layout.width /
                    PixelRatio.getPixelSizeForLayoutSize(event.nativeEvent.layout.width)
                )
              }}
              preset="hd-1280x720"
              orientation="portrait"
              ref={cameraRef}
              style={StyleSheet.absoluteFill}
            />

What happened instead?

no frameprocessors loading and or crash depending on reanimated / vision camera versions.

Relevant log output

default 10:45:54.432471+0100    app FrameProcessorBindings: Setting new frame processor...
default 10:45:54.432498+0100    app FrameProcessorBindings: Adapting Shareable value from function (conversion to worklet)...
default 10:45:54.432604+0100    app FrameProcessorBindings: Successfully created worklet!
default 10:45:54.432652+0100    app FrameProcessorBindings: Converting worklet to Objective-C callback...
default 10:45:54.433259+0100    app FrameProcessorBindings: Frame processor set!
Cannot read property '__callAsync' of undefined

error   10:45:55.849438+0100    app Cannot read property '__callAsync' of undefined

TypeError: Cannot read property '__callAsync' of undefined
    at _f (/[path]/app/node_modules/react-native-vision-camera/src/hooks/useFrameProcessor.ts (28:21):1:183)
    at _f (native)

Device

iPhone 11, iPhone 14, moto e7

VisionCamera Version

2.15.2

Additional information

myselfuser1 commented 1 year ago

Try this https://www.youtube.com/playlist?list=PLQhQEGkwKZUrempLnmxjt7ZCZJu1W3p2i

mrousavy commented 1 year ago

Closing as this is a stale issue - this might have been fixed with the full rewrite in VisionCamera V3 (🥳) - if not, please create a new issue.

If your issue has been fixed, consider sponsoring me on GitHub to say thanks 💖

mrousavy commented 1 year ago

Hey!

JFYI; VisionCamera V3 now includes a QR/Barcode Scanner! 😍 Check out the CodeScanner Documentation 🚀

Try upgrading to V3 if you can, it has a much more stable yet flexible foundation.