React-native/iOS 应用程序:未找到模块 'SquareInAppPaymentsSDK',尽管它已添加到项目中

React-native/iOS app: Module 'SquareInAppPaymentsSDK' not found, although it has been added to the project

更多信息

总结问题

问题是:

错误如下

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' 下我有两个包条目:

在下面评论@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

中描述的错误

您可以在 https://github.com/rahamin1/square_with-podfile

中找到我的存储库

根据您的 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