在React Native 0.61.2中找不到'ReactRCTBridgeModule.h'文件。

问题描述 投票:0回答:1

我正试图为React 0.61.2创建一个自定义的本地模块。

我已经创建了安卓版本,但是在iOS上似乎有一些问题。

我试图执行以下命令。

#import <React/RCTBridgeModule.h>

@interface PaypalSdk : NSObject <RCTBridgeModule>

@end

并得到:

'React/RCTBridgeModule.h' file not found

看来在早期的React Native .6版本中,这个功能的工作方式发生了很多变化。

在另一个更早的React版本中,我将React.xcodeproj添加到了我的库中,并且这也是可行的,然而在这里似乎并不是一个选项,因为React.xcodeproj被删除了。

我正在经历这个问题,并且已经测试了所有的东西,但这些东西似乎都没有工作。

https:/github.comfacebookreact-nativeissues25838)。

我也尝试了这里的一切,包括从我的方案中删除React并重新添加它。

https:/github.comfacebookreact-nativeissues24363。

可能是什么原因造成的?

EDIT:我的PaypalSdk.m文件的一部分。

#import "PaypalSdk.h"
#import <PayPal-iOS-SDK/PayPalMobile.h>
#import <PayPal-iOS-SDK/PayPalConfiguration.h>
#import <PayPal-iOS-SDK/PayPalOAuthScopes.h>
#import <PayPal-iOS-SDK/PayPalProfileSharingViewController.h>
#import <QuartzCore/QuartzCore.h>


@implementation PaypalSdk

... various methods and properties here

RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(generateCode:(NSString *)code callback:(RCTResponseSenderBlock)callback)
{
... more code here
    callback(@[[NSString stringWithFormat: @"code: %@", "test"]]);
}

@end
objective-c xcode react-native
1个回答
0
投票

而不是。

#import <React/RCTBridgeModule.h>

你通常会用这个来解决 0.59x 版本。

#if __has_include("RCTBridgeModule.h")
#import "RCTBridgeModule.h"
#else
#import <React/RCTBridgeModule.h>
#endif

然而,从RN >= v0.60x我们需要将.podspec添加到podfile中,无论哪个第三方自定义库抱怨找不到React{whatever.h}。所以,请。不要 将.a文件添加到你的Xcode的 Linked Framework and Libraries.

为了解决这个问题,我们可以开始做。

  1. 复制 podspec 从其他第三方库(例如,RNDeviceInfo等)。

  2. 创建自己的 podspec 替换几项 s.name, s.source, s.source_files)

s.name   = "MyPayPalLib"
s.source = { :git => "https://github.com/my-super-repo/paypal-lib-repo.git", :tag => "v#{s.version}" }

.

按照接下来的步骤,注意你的库是托管在npmyarngit上(远程)还是存储在你的项目的本地目录下。

.

A. 如果是远程库,请添加以下内容来跟踪所有的lib文件:A:

  1. 添加这个来跟踪你所有的库文件。s.source_files = "ios/**/*.{h,m}"

  2. 添加新的lib到Podfile。pod 'MyPayPalLib', :path => '../node_modules/MyPayPalLib'

  3. 做一个 pod install

B. 如果本地库。

  1. 在相同的自定义库路径创建这个custom.podspec,否则需要修改上面的 s.source 根据你的需要添加新的lib到Podfile。
s.source       = { :http => 'file:' + __dir__ + '/' }
s.source_files = "customLib/*.{h,m}"
  1. 添加新的lib到Podfile。pod 'MyPayPalLib', :path => '../localLibFolder/MyPayPalLib'

  2. 做一个 pod install


解决方法。

修正错误后 'React/RCTBridgeModule.h' file not found in React Native 0.61.2,该 NativeModules 对象为空。

所以,经过一番研究,我们得到了问题的所在:该对象的 s.source_files 道具有错误的价值!

一定要注意使用正确的 s.source_files podspec道具。

上级使用的是。s.source_files = "react-native-paypal-sdk/*.{h,m}"

然而,这应该是。s.source_files = "ios/**/*.{h,m}"

这是远程仓库的推荐方式。

© www.soinside.com 2019 - 2024. All rights reserved.