【问题标题】:When attempting to run React-Native app on ios device, why are all RCT... references "undefined symbol" errors?尝试在 ios 设备上运行 React-Native 应用程序时,为什么所有 RCT... 引用“未定义符号”错误?
【发布时间】:2019-11-08 10:02:33
【问题描述】:

我正在尝试在设备上运行我的第一个 React-Native 应用程序,但构建总是失败并出现以下错误:

ld: warning: directory not found for option '-L/Users/XXXX/Library/Developer/Xcode/DerivedData/nigh-hktjvygosupgnoaafsvgyowhzsqi/Build/Products/Debug-iphoneos/React'

ld: warning: directory not found for option '-L/Users/XXXX/Library/Developer/Xcode/DerivedData/nigh-hktjvygosupgnoaafsvgyowhzsqi/Build/Products/Debug-iphoneos/React'

ld: warning: directory not found for option '-L/Users/XXXX/Library/Developer/Xcode/DerivedData/nigh-hktjvygosupgnoaafsvgyowhzsqi/Build/Products/Debug-iphoneos/React'

ld: warning: ignoring file /Users/XXXX/Nigh/ReactNativeNigh/Nigh/ios/build/nigh/Build/Products/Debug-iphonesimulator/React/libReact.a, file was built for archive which is not the architecture being linked (arm64): /Users/XXXX/Nigh/ReactNativeNigh/Nigh/ios/build/nigh/Build/Products/Debug-iphonesimulator/React/libReact.a

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_RCTBridge", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_RCTBundleURLProvider", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_RCTConvert", referenced from:
      objc-class-ref in libRNGestureHandler.a(RNFlingHandler.o)
      objc-class-ref in libRNGestureHandler.a(RNForceTouchHandler.o)
      objc-class-ref in libRNGestureHandler.a(RNLongPressHandler.o)
      objc-class-ref in libRNGestureHandler.a(RNNativeViewHandler.o)
      objc-class-ref in libRNGestureHandler.a(RNPanHandler.o)
      objc-class-ref in libRNGestureHandler.a(RNGestureHandlerModule.o)
      objc-class-ref in libRNGestureHandler.a(RNGestureHandler.o)
      ...

React directory not found error

前面有几件事:

项目在 XCode 模拟器上运行良好。

我正在使用 cocoapods 并尝试从 xcWorkspace 而不是项目运行构建(尽管目标的完整路径是 /Users/XXXX/Nigh/ReactNativeNigh/Nigh/ios/nigh.xcodeproj 这让我有点困惑)。

我已经删除并重新安装了节点模块、链接并完成了新的 pod 安装。

看起来我所要做的就是将 React 添加到 Debug-iphoneos 文件夹,但我不知道该怎么做,或者这是否是解决方案。我的第一次尝试是确保 React 在 Scheme 的构建目标中。它是列表中第一个选中所有框的,除了出于某种原因它说 React(missing)。根据React Native / Xcode Upgrade and now RCTConvert.h not found,我从 Targets 列表中删除了 React(missing) 并尝试再次添加 React,但 React 甚至没有出现在列表中。此外,Pods/Products 文件夹显示 libReact.a 与其他 .a 文件不同,没有 Archive(?) 图标:

List of Pod/Products

这是 pod 文件:


require_relative '../node_modules/react-native-unimodules/cocoapods'

target 'nigh' do
  # Pods for nigh
  use_frameworks!

    # pod 'AWSCore', '~> 2.12.0'
    pod 'AWSCore', '~> 2.10.2'
    pod 'AWSAppSync', '~> 2.14.2'

  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge',
    'DevSupport',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTBlob',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
  ]

  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
  pod 'RNGestureHandler', :podspec => '../node_modules/react-native-gesture-handler/RNGestureHandler.podspec'
  pod 'RNReanimated', :podspec => '../node_modules/react-native-reanimated/RNReanimated.podspec'
  pod 'react-native-google-maps', path: '../node_modules/react-native-maps'  # Uncomment this line if you want to support GoogleMaps on iOS
  pod 'GoogleMaps'  # Uncomment this line if you want to support GoogleMaps on iOS
  pod 'Google-Maps-iOS-Utils' # Uncomment this line if you want to support GoogleMaps on iOS

  use_unimodules!


  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'

  pod 'react-native-maps', :path => '../node_modules/react-native-maps'

  pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'

  pod 'react-native-slider', :path => '../node_modules/@react-native-community/slider'

  pod 'react-native-notifications', :path => '../node_modules/react-native-notifications'

  pod 'react-native-cameraroll', :path => '../node_modules/@react-native-community/cameraroll'

  pod 'react-native-image-picker', :path => '../node_modules/react-native-image-picker'

  pod 'RNFS', :path => '../node_modules/react-native-fs'

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

我注释掉了 if target.name == "React" 块,但无论哪种方式都会出现错误。

我是否正确地假设问题在于 React 不在方案的构建目标中,如果是这样,有人知道如何包含它吗?如果没有,有谁知道真正的原因可能是什么/如何解决/解决它?

【问题讨论】:

    标签: ios xcode react-native cocoapods build-target


    【解决方案1】:

    我相信您的问题来自 use_frameworks!,请尝试删除该行,再次删除 DerivedData、Pods、xcworkspace、Podfile.lock 和 pod install

    我上个月升级我的 RN 版本时遇到了这个问题。这个愚蠢的事情让我花了 1 周的时间才知道这个问题,并花了 20 分钟来解决。

    希望有帮助

    【讨论】:

    • 好吧,坏消息是它爆炸得相当厉害,但好消息是我将 git 重置为一个较早的提交,其中使用了 use_frameworks!不包含在 podfile 中,现在我在构建时遇到了一个不同但类似的错误:ld: warning: directory not found for option '-L/Users/XXXX/Library/Developer/Xcode/DerivedData/nigh-hktjvygosupgnoaafsvgyowhzsqi/Build/Products/Debug-iphoneos/React' ld: library not found for -lReact clang: error: linker command failed with exit code 1 (use -v to see invocation) React 也回到了目标中,但仍然(缺失)
    • 是的,我也得到了这个,不记得我是如何解决它的,但我做了一些事情,比如从 Linked frameworks and libraries 中删除 libReact.a 并再次添加它。其他库会出现更多类似的错误,但您可以通过相同的方式解决它。注意 XCode 中的 Frameworks 文件夹,可能会有一些重复的 *.framework,如果不是这样也没关系
    • libReact.a 不会作为添加到链接框架和库的选项出现,除非我单击添加其他按钮并从 Build/Products/Debug-iphonesimulator/React/libReact.a 中选择它这似乎很奇怪。这样做给了我同样的错误,再加上一句话:忽略文件/Users/XXXX/Nigh/ReactNativeNigh/Nigh/ios/build/nigh/Build/Products/Debug-iphonesimulator/React/libReact.a,文件是为存档而构建的这不是被链接的架构(arm64):/Users/XXXX/Nigh/ReactNativeNigh/Nigh/ios/build/nigh/Build/Products/Debug-iphonesimulator/React/libReact.a
    • 如果 libReact.a 没有作为选项出现很奇怪,检查你是否已经在列表中,我将它添加到 linked libraries and framewoksFramework 文件夹中
    猜你喜欢
    • 2020-03-09
    • 2016-05-21
    • 2021-11-26
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 2018-05-20
    • 2021-10-20
    • 2018-09-11
    相关资源
    最近更新 更多