简体   繁体   English

如何将 react-native 与 iOS 与单独的文件夹集成。 (不在反应根目录内)。?

[英]How to Integrate react-native to iOS with separate folders. (Not inside react root directory).?

I already have a project on iOS and Android.我已经有一个关于 iOS 和 Android 的项目。 I would like to implement some new features in react-native.我想在 react-native 中实现一些新功能。 I have done integration in sample apps as well and its working like a charm.我也已经在示例应用程序中进行了集成,并且它的工作方式非常有魅力。

But my doubt is, this is working when I have iOS and Android code in react root directory.但我的疑问是,当我在反应根目录中有 iOS 和 Android 代码时,这是有效的。 when I move the iOS and Android in a separate folder unable to install pod in ios.当我将 iOS 和 Android 移动到单独的文件夹中时,无法在 ios 中安装 pod。 Getting error in "use_native_modules".在“use_native_modules”中出现错误。

Working Folder Structure工作文件夹结构

工作文件夹结构

But I need但是我需要

Expecting_folder_structure

I have changed the path in Podfile pointing to the react directory.我已经更改了 Podfile 中指向 react 目录的路径。 When I use当我使用

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

I am unable to install the pods.我无法安装吊舱。 getting得到

[!] Invalid `Podfile` file: [!] /usr/local/bin/node -e try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}

internal/modules/cjs/loader.js:1032
 throw err;
 ^

Error: Cannot find module 'react-native/cli'
Require stack:
- /Users/user/Documents/Sample ReactNative Projects/SeperateFolders/iOS/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
    at Function.Module._load (internal/modules/cjs/loader.js:898:27)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at require (internal/modules/cjs/helpers.js:73:18)
    at [eval]:1:87
    at Script.runInThisContext (vm.js:131:18)
    at Object.runInThisContext (vm.js:295:38)
    at Object.<anonymous> ([eval]-wrapper:10:26)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at evalScript (internal/process/execution.js:98:25) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/user/Documents/Sample ReactNative Projects/SeperateFolders/iOS/[eval]'
  ]
}
.

 #  from /Users/user/Documents/Sample ReactNative Projects/SeperateFolders/iOS/Podfile:48
 #  -------------------------------------------
 #    
 >    use_native_modules!
 #    
 #  -------------------------------------------

Also when I comment those 2 lines in pod file auto-linked pods are not getting installed.此外,当我评论 pod 文件中的这两行时,自动链接的 pod 没有安装。 Is there any way to achieve this?有什么办法可以做到这一点? or Is this the structure we need to follow?或者这是我们需要遵循的结构吗?

Kindly help.请帮忙。

Thanks in advance.提前致谢。

Try executing pod install in React directory with flag --project-directory尝试使用标志--project-directoryReact目录中执行pod install

In your case based on provided image of directory structure.在您的情况下,基于提供的目录结构图像。

cd React/
pod install --project-directory=../iOS

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM