React-native/iOS 应用程序:未找到模块 'SquareInAppPaymentsSDK',尽管它已添加到项目中
React-native/iOS app: Module 'SquareInAppPaymentsSDK' not found, although it has been added to the project
更多信息
- 我也在 https://github.com/square/in-app-payments-react-native-plugin/issues/66#issuecomment-623619907 中发布了此内容 - 您可以在那里找到更多详细信息。
- 我遇到问题的软件包的安装说明在 https://github.com/square/in-app-payments-react-native-plugin/blob/master/docs/get-started.md
总结问题
- 我遇到的问题是我在 Xcode 中配置了一个 react-native 包 (react-native-square-in-app-payments),但我收到一条错误消息说 'module xxx not found'。
问题是:
- 为什么 Xcode 找不到 'missing' 模块?什么配置不正确?我应该去哪里检查?
错误如下
Module 'SquareInAppPaymentsSDK' not found
我的播客文件:
platform :ios, '11.0'
target 'myproject' do
use_frameworks!
pod 'React', :path => '../node_modules/react-native'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'RNSquareInAppPayments', :path => '../node_modules/react-native-square-in-app-payments'
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'React'
target.remove_from_project
end
end
end
end
我的 project.pbxproj 文件(无法在此处附加,但您可以在 github 中访问):
https://github.com/square/in-app-payments-react-native-plugin/issues/66#issuecomment-625333601
更新:链接(在第一条评论和@DenisTsoi 回答之后)如下
我尝试了自动链接(如前所述,我需要它,因为我使用的是 RN 0.59.9),然后我再次开始并尝试手动链接,因为我有同样的错误。你可以在 https://github.com/square/in-app-payments-react-native-plugin/issues/66#issuecomment-625330210
中看到我对此的评论
顺便说一句,在 'link binary with libraries' 下我有两个包条目:
- SquareInAppPaymentsSDK.framework(根据 https://developer.squareup.com/docs/in-app-payments-sdk/installation#option-3-install-the-in-app-payments-sdk-manually 中的要求)
- libRNSquareInApppayments.a(部分链接)
在下面评论@MuhammadNuman 的回答:
我在一个新的 react-native 项目(由 react-init 创建)中尝试了你的 podfile。当我添加
import { SQIPCore } from 'react-native-square-in-app-payments';
我收到 https://github.com/square/in-app-payments-react-native-plugin/issues/66#issuecomment-629762613
中描述的错误
中找到我的存储库
根据您的 github 问题 link,
你运行宁反应 0.59.x。这意味着您需要 运行
react-native link
要在 iOS XCode 中 link 编辑本机库。
另一种方法是 linking XCode 中的依赖项,可以在 react native docs
上找到
摘录
Step 1 If the library has native code, there must be an .xcodeproj
file inside its folder. Drag this file to your project on Xcode
(usually under the Libraries group on Xcode);

Step 2 Click on your main project file (the one that represents the
.xcodeproj) select Build Phases and drag the static library from the
Products folder inside the Library you are importing to Link Binary
With Libraries

Step 3 Not every library will need this step, what you need to
consider is: Do I need to know the contents of the library at compile
time? What that means is, are you using this library on the native
side or only in JavaScript? If you are only using it in JavaScript,
you are good to go! If you do need to call it from native, then we
need to know the library's headers. To achieve that you have to go to
your project's file, select Build Settings and search for Header
Search Paths. There you should include the path to your library. (This
documentation used to recommend using recursive, but this is no longer
recommended, as it can cause subtle build failures, especially with
CocoaPods.) 
对于 RN 0.60+ link自动完成。
编辑:
也可以在<YOUR_PROJECT_DIRECTORY>/ios
目录下通过命令安装cocoapods SDK
pod install
我过去遇到过此类错误。因为一些配置的东西丢失或损坏导致了这些类型的问题。所以我对你的建议是创建一个新的 react-native 项目,从 NPM 或 GitHub 库的文档中一个一个地安装 package.json 中的所有库。然后将代码从 src (React Code) 复制到新项目中。如果您在 ios 和 android 文件夹中有任何更改,则仅复制文件中的更改并粘贴到新项目 android/ios 文件夹的文件中。 (如果没有任何效果,请应用此解决方案。它对我总是有效)
您还可以为 react-native 0.59.9
克隆和测试样板
https://github.com/nomi9995/in-app-payments-0.59.9.git
更改您的播客文件
platform :ios, '11.1'
target 'myproject' do
use_frameworks!
rn_path = '../node_modules/react-native'
pod 'React', path: rn_path, subspecs: [
'CxxBridge',
'RCTText',
'RCTNetwork',
'RCTWebSocket',
'RCTAnimation',
'RCTActionSheet',
'RCTGeolocation',
'RCTImage',
'RCTSettings',
'RCTVibration',
'RCTLinkingIOS'
]
pod 'yoga', :path => "#{rn_path}/ReactCommon/yoga"
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'RNSquareInAppPayments', :path => '../node_modules/react-native-square-in-app-payments'
end
并重新安装 podfile
pod install
更多信息
- 我也在 https://github.com/square/in-app-payments-react-native-plugin/issues/66#issuecomment-623619907 中发布了此内容 - 您可以在那里找到更多详细信息。
- 我遇到问题的软件包的安装说明在 https://github.com/square/in-app-payments-react-native-plugin/blob/master/docs/get-started.md
总结问题
- 我遇到的问题是我在 Xcode 中配置了一个 react-native 包 (react-native-square-in-app-payments),但我收到一条错误消息说 'module xxx not found'。
问题是:
- 为什么 Xcode 找不到 'missing' 模块?什么配置不正确?我应该去哪里检查?
错误如下
Module 'SquareInAppPaymentsSDK' not found
我的播客文件:
platform :ios, '11.0'
target 'myproject' do
use_frameworks!
pod 'React', :path => '../node_modules/react-native'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'RNSquareInAppPayments', :path => '../node_modules/react-native-square-in-app-payments'
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'React'
target.remove_from_project
end
end
end
end
我的 project.pbxproj 文件(无法在此处附加,但您可以在 github 中访问):
https://github.com/square/in-app-payments-react-native-plugin/issues/66#issuecomment-625333601
更新:链接(在第一条评论和@DenisTsoi 回答之后)如下
我尝试了自动链接(如前所述,我需要它,因为我使用的是 RN 0.59.9),然后我再次开始并尝试手动链接,因为我有同样的错误。你可以在 https://github.com/square/in-app-payments-react-native-plugin/issues/66#issuecomment-625330210
中看到我对此的评论顺便说一句,在 'link binary with libraries' 下我有两个包条目:
- SquareInAppPaymentsSDK.framework(根据 https://developer.squareup.com/docs/in-app-payments-sdk/installation#option-3-install-the-in-app-payments-sdk-manually 中的要求)
- libRNSquareInApppayments.a(部分链接)
在下面评论@MuhammadNuman 的回答:
我在一个新的 react-native 项目(由 react-init 创建)中尝试了你的 podfile。当我添加
import { SQIPCore } from 'react-native-square-in-app-payments';
我收到 https://github.com/square/in-app-payments-react-native-plugin/issues/66#issuecomment-629762613
中描述的错误 中找到我的存储库根据您的 github 问题 link,
你运行宁反应 0.59.x。这意味着您需要 运行
react-native link
要在 iOS XCode 中 link 编辑本机库。
另一种方法是 linking XCode 中的依赖项,可以在 react native docs
上找到摘录
Step 1 If the library has native code, there must be an .xcodeproj file inside its folder. Drag this file to your project on Xcode (usually under the Libraries group on Xcode);

Step 2 Click on your main project file (the one that represents the .xcodeproj) select Build Phases and drag the static library from the Products folder inside the Library you are importing to Link Binary With Libraries

Step 3 Not every library will need this step, what you need to consider is: Do I need to know the contents of the library at compile time? What that means is, are you using this library on the native side or only in JavaScript? If you are only using it in JavaScript, you are good to go! If you do need to call it from native, then we need to know the library's headers. To achieve that you have to go to your project's file, select Build Settings and search for Header Search Paths. There you should include the path to your library. (This documentation used to recommend using recursive, but this is no longer recommended, as it can cause subtle build failures, especially with CocoaPods.) 
对于 RN 0.60+ link自动完成。
编辑:
也可以在<YOUR_PROJECT_DIRECTORY>/ios
目录下通过命令安装cocoapods SDK
pod install
我过去遇到过此类错误。因为一些配置的东西丢失或损坏导致了这些类型的问题。所以我对你的建议是创建一个新的 react-native 项目,从 NPM 或 GitHub 库的文档中一个一个地安装 package.json 中的所有库。然后将代码从 src (React Code) 复制到新项目中。如果您在 ios 和 android 文件夹中有任何更改,则仅复制文件中的更改并粘贴到新项目 android/ios 文件夹的文件中。 (如果没有任何效果,请应用此解决方案。它对我总是有效)
您还可以为 react-native 0.59.9
克隆和测试样板https://github.com/nomi9995/in-app-payments-0.59.9.git
更改您的播客文件
platform :ios, '11.1'
target 'myproject' do
use_frameworks!
rn_path = '../node_modules/react-native'
pod 'React', path: rn_path, subspecs: [
'CxxBridge',
'RCTText',
'RCTNetwork',
'RCTWebSocket',
'RCTAnimation',
'RCTActionSheet',
'RCTGeolocation',
'RCTImage',
'RCTSettings',
'RCTVibration',
'RCTLinkingIOS'
]
pod 'yoga', :path => "#{rn_path}/ReactCommon/yoga"
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'RNSquareInAppPayments', :path => '../node_modules/react-native-square-in-app-payments'
end
并重新安装 podfile
pod install