简体   繁体   English

将 react-native 版本 0.62.2 集成到现有 IOs 应用程序错误

[英]Integrate react-native version 0.62.2 into existing IOs app error

Following react-native document to integrate react-native to existing IOs app.按照 react-native 文档将 react-native 集成到现有的 IOs 应用程序。 The structure of directory as document to integrate is作为要集成的文档的目录结构是

android/
ios/
   Podfile
   #...other ios file
node_modules/
  react-native
  react
  @react-native-community  
package.json
.... 

So that when run pod install from Podfile can call function use_native_modules这样当从 Podfile 运行 pod install 时,可以调用 function use_native_modules

require_relative './libs/react-native-libs/node_modules/@react-native-community/cli-platform-ios/native_modules'
...
use_native_modules!

But I want to organize the project different due to not change my existing project structure,但是由于不改变我现有的项目结构,我想组织不同的项目,

so I add react-native-integrate module like as a part of my IOs project like this所以我添加了 react-native-integrate 模块,就像我的 IOs 项目的一部分一样

my_ios_project
  Podfile
  libs/
     ... other modules
     react-native-integrate
         node_modules
             react-native
             @react-native-community
             react 
         package.json

And then I change the path of relative-module:然后我改变了相对模块的路径:

require_relative './libs/react-native-libs/node_modules/@react-native-community/cli-platform-ios/native_modules'
...
use_native_module!   

But the problem is in native_modules files and others libraries in node_modules use absolute require .但问题在于 native_modules 文件和 node_modules 中的其他库使用 absolute require For example in @react-community/cli-platform-ios/native_module.rb there is a line such as例如在@react-community/cli-platform-ios/native_module.rb有一行如

cli_resolve_script = "try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('@react-native/cli'))}"

that require absolute path '@react-native-community'.需要绝对路径'@react-native-community'。 So that when I run Pod install my pod file from parent directory the node can not recognize my children module so that it cause error.因此,当我从父目录运行Pod install我的 pod 文件时, node无法识别我的子模块,从而导致错误。 在此处输入图像描述

As I know the node_module 'spaths list is basically a list of node_modules directories under every directory from the current directory to the root directory.据我所知, node_module 的路径列表基本上是从当前目录到根目录的每个目录下的 node_modules 目录列表。 And the current directory is that the directory of the Podfile that call require 'native_module.rb' Could you please give me a solution solve this problem like add node path from children directory or something else?当前目录是调用 require 'native_module.rb' 的 Podfile 的目录,你能给我一个解决这个问题的解决方案吗,比如从子目录添加节点路径或其他什么? Thank you.谢谢你。

I found a solution:我找到了一个解决方案:

  • add package.json file at root ios with property main添加 package.json 文件在根 ios 与属性main
  • add react-native.config.js at root ios project, edit path to cli-platform-ios and cli-platform-android :在根 ios 项目中添加 react-native.config.js,编辑cli-platform-ioscli-platform-android路径:
'use strict';

const ios = require('./node_modules/@react-native-community/cli-platform-ios');
const android = require('./node_modules/@react-native-community/cli-platform-android');

module.exports = {
  commands: [...ios.commands, ...android.commands],
  platforms: {
    ios: {
      linkConfig: ios.linkConfig,
      projectConfig: ios.projectConfig,
      dependencyConfig: ios.dependencyConfig,
    },
    android: {
      linkConfig: android.linkConfig,
      projectConfig: android.projectConfig,
      dependencyConfig: android.dependencyConfig,
    },
  }
};
  • Run pod install again再次运行pod install

Checkout my demo here: https://github.com/lehoangnam97/demo-intergrate-rn-on-ios在这里查看我的演示: https://github.com/lehoangnam97/demo-intergrate-rn-on-ios

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试将react-native应用程序与现有ios应用程序集成时出现“ _fbBatchedBridge未定义”错误 - “_fbBatchedBridge is undefined” error while trying to integrate a react-native app with an existing ios app 如何在现有的 React Native App 中集成原生 ios 摄像头 SDK? - How to integrate native ios camera SDK in existing react native App? 如何为 iOS 应用程序 React-Native 配置最低应用程序版本 - How to configure a minimum app version for an iOS app React-Native 将React-Native应用程序集成到Swift 3中 - Integrate React-Native app to Swift 3 使用react-native-navigation将React本机应用程序与现有iOS应用程序集成 - integrate react native app using react-native-navigation with existing iOS app react-native与现有ios应用程序集成 - react-native integrating with existing ios apps 将React-Native集成到现有App - Integrating React-Native to an existing App 在现有的 React Native iOS 项目中安装 React-Native Android? - Installing React-Native Android in existing React Native iOS project? react-native IOS应用程序的调试版本成功构建。 发布版本失败。 - debug version of react-native IOS app builds successfully. Release version fails. 将React Native应用程序集成到现有的iOS Obj-C / Swift应用程序中 - Integrate a React Native app in to an existing iOS Obj-C/Swift App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM