NO_FLIPPER导致RN编译失败

问题描述

Xcode构建RN报错:

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_FlipperClient", referenced from:
      objc-class-ref in libreact-native-flipper.a(FlipperReactNativeJavaScriptPluginManager.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

问题分析

NO_FLIPPER没有设置成功导致react-native-flipper编译时没有被排除
React Native 0.71.1 当 NO_FLIPPER=1 时排除 react-native-flipper 以防止 iOS 构建失败

# 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 } } } : {}),
 # ```

问题解决

通过设置NO_FLIPPER=1把Flipper从pods中排除后再构建RN
Disable Flipper for iOS

NO_FLIPPER=1 pod install --project-directory=ios

node版本过低导致RN编译失败

问题描述

Xcode编译RN项目失败:

Node found at: /usr/local/bin/node
/Users/couldhll/Desktop/Jesus/node_modules/yargs/node_modules/yargs-parser/build/index.cjs:1015
        throw Error(`yargs parser supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`);
        ^

Error: yargs parser supports a minimum Node.js version of 12. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions
    at Object.<anonymous> (/Users/couldhll/Desktop/Jesus/node_modules/yargs/node_modules/yargs-parser/build/index.cjs:1015:15)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/couldhll/Desktop/Jesus/node_modules/yargs/build/index.cjs:1:60637)
    at Module._compile (module.js:652:30)
Command PhaseScriptExecution failed with a nonzero exit code

问题分析

查了一下node的版本是8.11.3,需要的版本是12以上

/usr/local/bin/node -v
v8.11.3

问题解决

node(nvm安装)link到/usr/local/bin/node

ln -s $(which node) /usr/local/bin/node

Multiple commands produce报错

问题描述

iOS Build 报错:


Showing Recent Messages

Prepare build
note: Building targets in dependency order
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/AntDesign.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/AntDesign.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/AntDesign.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Entypo.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/Entypo.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Entypo.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/EvilIcons.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/EvilIcons.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/EvilIcons.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Feather.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/Feather.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Feather.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/FontAwesome.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome5_Brands.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/FontAwesome5_Brands.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome5_Brands.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome5_Regular.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/FontAwesome5_Regular.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome5_Regular.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome5_Solid.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/FontAwesome5_Solid.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome5_Solid.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Fontisto.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/Fontisto.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Fontisto.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Foundation.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/Foundation.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Foundation.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Ionicons.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/Ionicons.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Ionicons.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/MaterialCommunityIcons.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/MaterialCommunityIcons.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/MaterialCommunityIcons.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/MaterialIcons.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/MaterialIcons.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/MaterialIcons.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Octicons.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/Octicons.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Octicons.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/SimpleLineIcons.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/SimpleLineIcons.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/SimpleLineIcons.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”
error: Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Zocial.ttf'
    note: Target 'Jesus' (project 'Jesus') has copy command from '/Users/couldhll/Desktop/Jesus/node_modules/react-native-vector-icons/Fonts/Zocial.ttf' to '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Zocial.ttf'
    note: That command depends on command in Target 'Jesus' (project 'Jesus'): script phase “[CP] Copy Pods Resources”

Building targets in dependency order

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/AntDesign.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Entypo.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/EvilIcons.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Feather.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome5_Brands.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome5_Regular.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/FontAwesome5_Solid.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Fontisto.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Foundation.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Ionicons.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/MaterialCommunityIcons.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/MaterialIcons.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Octicons.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/SimpleLineIcons.ttf'

Multiple commands produce '/Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Products/Debug-iphoneos/Jesus.app/Zocial.ttf'

Computing target dependency graph and provisioning inputs

Create build description
Build description signature: e34cffb17530f18e248a8120033bffe3
Build description path: /Users/couldhll/Library/Developer/Xcode/DerivedData/Jesus-bixlpkqqeqxklgenquwktceekdsp/Build/Intermediates.noindex/XCBuildData/e34cffb17530f18e248a8120033bffe3-desc.xcbuild

问题分析

原因是react-native-vector-icons所使用的ttf字体文件被导入了两次:
一次是手动导入:通过项目导入
一次是自动导入:Pods-Jesus-resources.sh

问题解决

方法一:移除手动导入

移除项目中手动导入的字体文件

方法二:取消自动导入

react-native.config.js文件中加入如下代码:

module.exports = {
  dependencies: {
    'react-native-vector-icons': {
      platforms: {
        ios: null,
      },
    },
  },
};

React Native的Metro启动不了

问题描述

今天yarn start出现如下错误

metro-file-map: Watchman crawl failed. Retrying once with node crawler.
  Usually this happens when watchman isn't running. Create an empty `.watchmanconfig` file in your project's root folder or initialize a git or hg repository in your project.
  Error: Watchman error: std::__1::system_error: open: /Users/couldhll/Desktop/Jesus: Operation not permitted. Make sure watchman is running for this project. See https://facebook.github.io/watchman/docs/troubleshooting.
node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: std::__1::system_error: open: /Users/couldhll/Desktop/Jesus: Operation not permitted
    at BunserBuf.<anonymous> (/Users/couldhll/Desktop/Jesus/node_modules/fb-watchman/index.js:99:23)
    at BunserBuf.emit (node:events:513:28)
    at BunserBuf.process (/Users/couldhll/Desktop/Jesus/node_modules/bser/index.js:292:10)
    at /Users/couldhll/Desktop/Jesus/node_modules/bser/index.js:247:12
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
Emitted 'error' event on WatchmanWatcher instance at:
    at Client.<anonymous> (/Users/couldhll/Desktop/Jesus/node_modules/metro-file-map/src/watchers/WatchmanWatcher.js:107:12)
    at Client.emit (node:events:513:28)
    at BunserBuf.<anonymous> (/Users/couldhll/Desktop/Jesus/node_modules/fb-watchman/index.js:111:12)
    at BunserBuf.emit (node:events:513:28)
    at /Users/couldhll/Desktop/Jesus/node_modules/bser/index.js:249:12
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
  watchmanResponse: {
    error: 'std::__1::system_error: open: /Users/couldhll/Desktop/Jesus: Operation not permitted',
    version: '2022.11.14.00'
  }
}

Node.js v18.12.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

问题解决

在终端使用如下命令:

步骤一

watchman watch-del-all

步骤二

watchman shutdown-server