React Native升级0.73未定义符号:_OBJC_CLASS_$_RCTEventDispatcher,

问题描述 投票:0回答:1

RN更新到0.73的过程中。我在应用程序中心 ios 管道上遇到了这个问题。

ld: Undefined symbols:
  _OBJC_CLASS_$_RCTEventDispatcher, referenced from:
      __OBJC_$_CATEGORY_RCTEventDispatcher_$_Reanimated in libRNReanimated.a[15](RCTEventDispatcher+Reanimated.o)
       in libreact-native-video.a[14](RCTVideoManager-4f7ca5ff0fe771e512e596f87e56773d.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The following build commands failed:
    Ld /Users/runner/Library/Developer/Xcode/DerivedData/fluzclient-giqtbliqeqmefvddlqenjaszepez/Build/Intermediates.noindex/ArchiveIntermediates/fluzclient/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/ImageNotification.appex/ImageNotification normal (in target 'ImageNotification' from project 'fluzclient')
(1 failure)
##[error]Error: /usr/bin/xcodebuild failed with return code: 65

我的 Podfile

# Resolve react_native_pods.rb with node to allow for hoisting
use_modular_headers!

def node_require(script)
  # Resolve script with node to allow for hoisting
  require Pod::Executable.execute_command('node', ['-p',
    "require.resolve(
      '#{script}',
      {paths: [process.argv[1]]},
    )", __dir__]).strip
end

node_require('react-native/scripts/react_native_pods.rb')
node_require('react-native-permissions/scripts/setup.rb')

ENV['SWIFT_VERSION'] = '5.7'

def fluz_pods
  pod 'react-native-orientation-locker', :path => '../node_modules/react-native-orientation-locker'
  pod 'react-native-branch', path: '../node_modules/react-native-branch'
  pod 'FullStory', :http => 'https://ios-releases.fullstory.com/fullstory-1.43.1-xcframework.tar.gz'
  pod 'CocoaLumberjack/Swift'
end

platform :ios, '14.0'
prepare_react_native_project!
setup_permissions([
  'AppTrackingTransparency',
  'Bluetooth',
  'Calendars',
  'CalendarsWriteOnly',
  'Camera',
  'Contacts',
  'FaceID',
  'LocationAccuracy',
  'LocationAlways',
  'LocationWhenInUse',
  'MediaLibrary',
  'Microphone',
  'Motion',
  'Notifications',
  'PhotoLibrary',
  'PhotoLibraryAddOnly',
  'Reminders',
  'SpeechRecognition',
  'StoreKit',
])

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# ```js
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled
linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

def guard_pods_deployment_target(installer)
  # implements __apply_Xcode_12_5_M1_post_install_workaround with ios 12.0
  installer.pods_project.targets.each do |target|
    if target.name != "Braintree"
      # we skip Braintree packages for target upgrade
      # "error: 'unarchiveObjectWithData:' is deprecated: first deprecated in iOS 12.0"
      target.build_configurations.each do |config|
        #  "error: thread-local storage is not supported for the current target"
        # The most reliable known workaround is to bump iOS deployment target.
        # ensure IPHONEOS_DEPLOYMENT_TARGET is at least 14
        should_upgrade = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].split('.')[0].to_i < 14
        if should_upgrade
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14'
        end
      end
    end
    if target.name == "Braintree"
      # apply only to Braintree to prevent
      # "error: 'unarchiveObjectWithData:' is deprecated: first deprecated in iOS 12.0"
      target.build_configurations.each do |config|
        #  "error: thread-local storage is not supported for the current target"
        # The most reliable known workaround is to bump iOS deployment target.
        # ensure IPHONEOS_DEPLOYMENT_TARGET is at least 14.0
        should_upgrade = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].split('.')[0].to_i < 14.0
        if should_upgrade
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
        end
      end
    end
    if target.name == 'Flipper'
      file_path = 'Pods/Flipper/xplat/Flipper/FlipperTransportTypes.h'
      contents = File.read(file_path)
      unless contents.include?('#include <functional>')
        File.open(file_path, 'w') do |file|
          file.puts('#include <functional>')
          file.puts(contents)
        end
      end
    end
  end

  # But... doing so caused another issue in Flipper:
  #   "Time.h:52:17: error: typedef redefinition with different types"
  # We need to make a patch to RCT-Folly. @0.66.3
  # See https://github.com/facebook/flipper/issues/834 for more details.
  `sed -i -e  $'s/ && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_14_0)//' Pods/RCT-Folly/folly/portability/Time.h`
end

target 'fluzclient' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  # Pods for fluzclient
  fluz_pods

  target 'fluzclientTests' do
    inherit! :complete
    # Pods for testing
  end
end



target 'fluzclient-staging' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  # Pods for fluzclient
  fluz_pods
end

config = use_native_modules!

pre_install do |installer|
  installer.pod_targets.each do |pod|
    if pod.name.eql?('RNReanimated')
      def pod.build_type
        Pod::BuildType.static_library
      end
    end
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == "React-Core.common-CoreModulesHeaders-RCTI18nStrings"
      target.remove_from_project
    end
    target.build_configurations.each do |config|
      config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
    end
  end
  # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
  react_native_post_install(
    installer,
    config[:reactNativePath],
    :mac_catalyst_enabled => false
  )
  guard_pods_deployment_target(installer)
  installer.pods_project.targets.each do |target|
     target.build_configurations.each do |config|
       config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
     end
   end
end


target 'ImageNotification' do
  platform :ios, '14.0'
  pod 'Firebase/Messaging'
  pod 'Iterable-iOS-AppExtensions'
end

很多人说它与 use_framework 有关,并且向静态库添加具有显式类型的 pre_install 可以修复它,但对我来说却没有。我很确定 RNReanimated 是我需要的目标,但我错了吗?

    pre_install do |installer|
     installer.pod_targets.each do |pod|
       if pod.name.eql?('RNReanimated')
         def pod.build_type
           Pod::BuildType.static_library
         end
       end
      end
    end
  • 我也尝试过删除
    use_modular_headers!
  • 升级react-native-video,但我最终得到了一个不同的错误。
  • 升级react-native-reanimated
  • 将 RNReanimated 添加到 ImageNotification 目标,如下所示
target 'ImageNotification' do
  platform :ios, '14.0'
  pod 'Firebase/Messaging'
  pod 'Iterable-iOS-AppExtensions'
  pod 'RNReanimated'
end

系统: 爪哇:17 节点:18 Xcode:最少 14

ios swift react-native cocoapods podfile
1个回答
0
投票

我也有类似的问题。在react-native.config.js中禁用了自动链接

'react-native-reanimated': {
      platforms: {
        ios: null,
},
}

在Podfile中链接react-native-reanimated作为主要目标

pod 'RNReanimated', :path => '../node_modules/react-native-reanimated'
© www.soinside.com 2019 - 2024. All rights reserved.