ios React Native 构建失败:找不到“React/RCTBridge.h”文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50453883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:42:25  来源:igfitidea点击:

React Native build failed: 'React/RCTBridge.h' file not found

iosobjective-creactjsreact-native

提问by Kurt Peek

I'm trying to build a React Native app with the following file structure:

我正在尝试使用以下文件结构构建一个 React Native 应用程序:

Kurts-MacBook-Pro-2:lucy-app kurtpeek$ tree -L 1
.
├── README.md
├── __tests__
├── android
├── app.json
├── assets
├── index.js
├── ios
├── node_modules
├── package.json
├── src
└── yarn.lock

The package.jsonis

package.json

{
    "name": "app",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "android": "concurrently 'emulator @Nexus_5X_API_27_x86' 'yarn android-noavd'",
        "android-noavd": "react-native run-android",
        "android-px": "concurrently 'emulator @Pixel_2_API_27' 'yarn android-noavd'",
        "android:release": "cross-env ENVFILE=.env.release yarn run android",
        "android:staging": "cross-env ENVFILE=.env.staging yarn run android",
        "build:android:dev": "cross-env ENVFILE=.env ./android/gradlew assembleRelease -p ./android/",
        "build:android:release": "cross-env ENVFILE=.env.release ./android/gradlew assembleRelease -p ./android/",
        "build:android:staging": "cross-env ENVFILE=.env.staging ./android/gradlew assembleRelease -p ./android/",
        "clean": "concurrently 'rimraf ./android/build/' 'rimraf ./ios/build/' 'rimraf node_modules/' 'yarn cache clean'",
        "codepush": "yarn codepush:ios; yarn codepush:android",
        "codepush:android": "code-push release-react Lucy-Eng/LucyApp-Android android",
        "codepush:ios": "code-push release-react Lucy-Eng/LucyApp-iOS ios --plistFile ios/LucyApp/Info.plist",
        "codepush:ls:apps": "code-push app ls",
        "codepush:ls:deploys": "echo iOS && code-push deployment ls Lucy-Eng/LucyApp-iOS; echo ANDROID && code-push deployment ls Lucy-Eng/LucyApp-Android",
        "codepush:promote:android": "code-push promote Lucy-Eng/LucyApp-Android Staging Production",
        "codepush:promote:ios": "code-push promote Lucy-Eng/LucyApp-iOS Staging Production",
        "ios": "react-native run-ios --simulator='iPhone 7'",
        "ios8": "react-native run-ios --simulator='iPhone 8'",
        "ios:release": "cross-env ENVFILE=.env.release yarn run ios",
        "ios:staging": "cross-env ENVFILE=.env.staging yarn run ios",
        "iosx": "react-native run-ios --simulator='iPhone X'",
        "lint": "eslint .",
        "log:android": "react-native log-android",
        "log:ios": "react-native log-ios",
        "react-devtools": "react-devtools",
        "start": "./node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
    },
    "dependencies": {
        "analytics-react-native": "^1.2.0",
        "immutability-helper": "^2.5.0",
        "libphonenumber-js": "^1.1.10",
        "lodash": "^4.17.4",
        "moment": "^2.19.0",
        "moment-timezone": "^0.5.14",
        "prop-types": "^15.6.0",
        "querystring": "^0.2.0",
        "raven-for-redux": "^1.3.0",
        "react": "^16.2.0",
        "react-native": "^0.53.3",
        "react-native-android-keyboard-adjust": "^1.1.1",
        "react-native-code-push": "^5.3.2",
        "react-native-config": "^0.11.5",
        "react-native-country-picker-modal": "^0.5.1",
        "react-native-datepicker": "^1.6.0",
        "react-native-intercom": "^8.0.0",
        "react-native-keyboard-aware-scroll-view": "^0.4.4",
        "react-native-markdown-renderer": "^3.1.0",
        "react-native-material-kit": "git://github.com/xinthink/react-native-material-kit#95b0980",
        "react-native-material-menu": "^0.2.3",
        "react-native-modal": "^4.1.1",
        "react-native-onesignal": "^3.0.6",
        "react-native-phone-input": "^0.2.1",
        "react-native-router-flux": "4.0.0-beta.27",
        "react-native-sentry": "^0.35.3",
        "react-native-smart-splash-screen": "^2.3.5",
        "react-native-snackbar": "^0.4.3",
        "react-native-swiper": "^1.5.13",
        "react-native-vector-icons": "^4.4.0",
        "react-navigation": "^1.5.11",
        "react-redux": "^5.0.6",
        "redux": "^3.7.2",
        "redux-devtools-extension": "^2.13.2",
        "redux-form": "^7.3.0",
        "redux-logger": "^3.0.6",
        "redux-persist": "^4.10.1",
        "redux-thunk": "^2.2.0",
        "reselect": "^3.0.1",
        "validator": "^10.2.0"
    },
    "devDependencies": {
        "babel-core": "^6.26.3",
        "babel-eslint": "^8.0.1",
        "babel-jest": "21.2.0",
        "babel-preset-react-native": "4.0.0",
        "code-push-cli": "^2.1.6",
        "concurrently": "^3.5.1",
        "cross-env": "^5.1.4",
        "enzyme": "^3.1.1",
        "enzyme-adapter-react-16": "^1.0.4",
        "eslint": "^4.8.0",
        "eslint-config-airbnb": "^15.1.0",
        "eslint-import-resolver-reactnative": "^1.0.2",
        "eslint-plugin-import": "^2.7.0",
        "eslint-plugin-jsx-a11y": "^5.1.1",
        "eslint-plugin-react": "^7.4.0",
        "eslint-plugin-react-native": "^3.1.0",
        "jest": "21.2.1",
        "react-devtools": "^3.1.0",
        "react-dom": "^16.0.0",
        "react-test-renderer": "16.0.0-beta.5",
        "rimraf": "^2.6.2"
    },
    "jest": {
        "preset": "react-native",
        "setupTestFrameworkScriptFile": "<rootDir>src/test-config/enzyme-config.js"
    },
    "rnpm": {
        "assets": [
            "./assets/fonts/"
        ]
    }
}

and there is an ios/Podfilelike so:

有一个ios/Podfile像这样:

target 'LucyApp' do
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'BatchedBridge',
    'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
    'RCTText',
    'RCTNetwork',
    'RCTWebSocket', # needed for debugging
    # 'RCTBridge',
    # Add any other subspecs you want to use in your project
  ]
  # Explicitly include Yoga if you are using RN >= 0.42.0
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  # Third party deps podspec link
  pod 'Intercom'
  pod 'CodePush', :path => '../node_modules/react-native-code-push'
  pod 'SentryReactNative', :path => '../node_modules/react-native-sentry'

  # Add new pods below this line

end

When I try to build this app in Xcode, I get an import error from SentryReactNative:

当我尝试在 Xcode 中构建此应用程序时,我收到来自SentryReactNative以下内容的导入错误:

enter image description here

在此处输入图片说明

Similarly, when I try to run the simulator using yarn ios, I get the following error:

同样,当我尝试使用 运行模拟器时yarn ios,出现以下错误:

In file included from /Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/react-native-sentry/ios/RNSentry.m:1:
In file included from /Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/react-native-sentry/ios/RNSentry.h:4:
/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/react-native/React/Base/RCTBridge.h:12:9: fatal error: 'React/RCTBridgeDelegate.h' file not found
#import <React/RCTBridgeDelegate.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~



** BUILD FAILED **


The following commands produced analyzer issues:

    Analyze Base/RCTModuleMethod.mm normal x86_64
(1 command with analyzer issues)

The following build commands failed:
    CompileC /Users/kurtpeek/Documents/Dev/lucy/lucy-app/ios/build/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/SentryReactNative.build/Objects-normal/x86_64/RNSentryEventEmitter.o /Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/react-native-sentry/ios/RNSentryEventEmitter.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

Installing build/Build/Products/Debug-iphonesimulator/LucyApp.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist

Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/LucyApp.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist


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

Following https://facebook.github.io/react-native/docs/integration-with-existing-apps.html#configuring-cocoapods-dependencies, I thought at first that I might need to add 'RCTBridge'to the subspecs of 'React', which is the reason for the commented-out line in the Podfile. However, if I uncomment that line and try to pod install, I get a "CocoaPods could not find compatible versions" error:

https://facebook.github.io/react-native/docs/integration-with-existing-apps.html#configuring-cocoapods-dependencies之后,我起初认为我可能需要添加'RCTBridge'subspecs 中'React',即中注释掉的行的原因Podfile。但是,如果我取消注释该行并尝试pod install,我会收到“CocoaPods 找不到兼容版本”错误:

enter image description here

在此处输入图片说明

How can I update the imports to make the app build?

如何更新导入以构建应用程序?

回答by Manish

Follow the below steps. It's worked for me.

请按照以下步骤操作。它对我有用。

  1. Open terminal
  2. Go to the iosfolder
  3. Quit Xcode
  4. run pod install
  5. Open .xcworkspacefile.
  6. Clean (cmd+shift+k) and build (cmd+b) the project.
  1. 打开 terminal
  2. 进入ios文件夹
  3. 退出 Xcode
  4. pod install
  5. 打开.xcworkspace文件。
  6. 清理 ( cmd+shift+k) 并构建 ( cmd+b) 项目。

That's it. Happy Coding :)

就是这样。快乐编码:)

回答by akshay gore

Try this -

尝试这个 -

  • In Xcode, go to the project scheme (Product -> Scheme -> Manage Scheme -> double click your project).
  • Click on the 'Build' option at the left pane.
  • Uncheck 'Parallelize Build' under Build Options.
  • Then in Targets section, click '+' button then search for 'React'. Select it and click 'Add'.
  • 'React' should now appear under Targets section. Click and drag it to the top so that it will be the first item in the list (before your project).
  • Clean the project and build.
  • 在 Xcode 中,转到项目方案(产品 -> 方案 -> 管理方案 -> 双击您的项目)。
  • 单击左侧窗格中的“构建”选项。
  • 取消选中构建选项下的“并行构建”。
  • 然后在 Targets 部分,单击“+”按钮,然后搜索“React”。选择它并单击“添加”。
  • “React”现在应该出现在“目标”部分下。单击并将其拖到顶部,使其成为列表中的第一项(在您的项目之前)。
  • 清理项目并构建。

For more options check the issue on RN repo - https://github.com/facebook/react-native/issues/12042

有关更多选项,请查看 RN repo 上的问题 - https://github.com/facebook/react-native/issues/12042

回答by Marcio Prudencio

Worked for me, no hack (advised only if you're not using Swift):

为我工作,没有 hack(仅当您不使用 Swift 时才建议):

  1. File > Project Settings
  2. On Built System choose > Legacy Build System (Both)
  3. In the same window, Open and Clean your DerivedData dir
  4. Clean your Built, Product > Clean Save all and restart the Xcode. Happy Coding!
  1. 文件 > 项目设置
  2. 在内置系统上选择 > Legacy Build System (Both)
  3. 在同一窗口中,打开并清理您的 DerivedData 目录
  4. 清理你的内置产品 > 清理全部保存并重新启动 Xcode。快乐编码!

回答by Ilarion Bekchyan

For me to solve the issue that was occurring was done by adding all this dependencies in Podfile:

对我来说,解决发生的问题是通过在以下位置添加所有这些依赖项来完成的Podfile

  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

After adding dependencies and running this commands:

添加依赖项并运行此命令后:

  1. cd ios
  2. rm -rf Pods
  3. pod deintegrate
  4. pod install
  1. cd ios
  2. rm -rf Pods
  3. pod deintegrate
  4. pod install

Hope this will solve someone issue too.

希望这也能解决某人的问题。