swift - 使用 use_modular_headers 复制 React 定义 cocoapods

标签 swift xcode react-native cocoapods

我正在构建一个主要使用 swift 的 React Native Cocoapod 库。

我很难获得正确的 podspec 和 podfile 组合以避免在运行时出现重新定义警告

我的应用程序的 Podfile

install! 'cocoapods', :deterministic_uuids => false

platform :ios, '11.0'

use_modular_headers!

target 'chowchow' do

    pod 'React', :path => '../node_modules/react-native', :subspecs => [
        'Core',
        'ART',
        'CxxBridge', # Include this for RN >= 0.47
        'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
        'RCTText',
        'RCTImage',
        'RCTNetwork',
        'RCTWebSocket', # Needed for debugging
        'RCTAnimation', # Needed for FlatList and animations running on native UI thread
        'RCTActionSheet',
        'RCTLinkingIOS',
    ]

    # Explicitly include Yoga if you are using RN >= 0.42.0
    pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

    # React's third party deps podspec link
    pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec', :modular_headers => false
    pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec', :modular_headers => false
    pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec', :modular_headers => false

#    pod 'google-cast-sdk'

    # React Community
    pod 'react-native-async-storage', :path => '../node_modules/@react-native-community/async-storage', :modular_headers => false
    pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo', :modular_headers => false

    # Fabric & Crashlytics
    pod 'Firebase/Core', :modular_headers => false
    pod 'Fabric', :modular_headers => false
    pod 'Crashlytics', :modular_headers => false

    # Fast image
    pod 'react-native-fast-image', :path => '../node_modules/react-native-fast-image', :modular_headers => false

    # Node modules
    pod 'ReactNativeNavigation', :path => '../node_modules/react-native-navigation', :modular_headers => false
    pod 'TouchID', :path => '../node_modules/react-native-touch-id', :modular_headers => false
    pod 'RNKeychain', :path => '../node_modules/react-native-keychain', :modular_headers => false
    pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons', :modular_headers => false
    pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info', :modular_headers => false
    pod 'RNMyLibrary', :path => '../node_modules/react-native-my-library'

end

post_install do |installer|
    installer.pods_project.targets.each do |target|

        # https://github.com/facebook/react-native/issues/20492
        # The following is needed to ensure the "archive" step works in XCode.
        # It removes React & Yoga from the Pods project, as it is already included in the main project.
        # Without this, you'd see errors when you archive like:
        # "Multiple commands produce ... libReact.a"
        # "Multiple commands produce ... libyoga.a"

        targets_to_ignore = %w(React yoga)

        if targets_to_ignore.include? target.name
            target.remove_from_project
        end
    end
end

我的图书馆的 Podspec

require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))

Pod::Spec.new do |s|
  s.name         = "RNMyLibrary"
  s.version      = package["version"]
  s.summary      = package["description"]
  s.description  = <<-DESC
                  RNMyLibrary
                   DESC
  s.homepage     = "https://github.com/brenwell/RNMyLibrary"
  s.license      = "UNLICENSED"
  s.author       = { "author" => "author@domain.cn" }
  s.platform     = :ios, "11.0"
  s.source       = { :git => "https://github.com/brenwell/RNMyLibrary.git", :tag => "#{s.version}" }

  s.source_files = "ios/**/*.{h,m,swift}"

  s.resource_bundles = {
    'TrackModel' => ["ios/RNMyLibrary/Track.xcdatamodeld"]
  }

  s.requires_arc = true

  s.dependency "google-cast-sdk", '4.3.0'
  s.dependency "CocoaHTTPServer"
  s.dependency "React"

end

错误

Error while loading Swift module:
D-MediaStore: /Users/brenwell/Library/Developer/Xcode/DerivedData/my-library-axsmrqxaoagdyfbmkmhxgjoxfini/Build/Products/Debug-iphonesimulator/RNMyLibrary/Swift Compatibility Header/RNMyLibrary-Swift.h:172:9: note: while building module 'React' imported from /Users/brenwell/Library/Developer/Xcode/DerivedData/my-library-axsmrqxaoagdyfbmkmhxgjoxfini/Build/Products/Debug-iphonesimulator/RNMyLibrary/Swift Compatibility Header/RNMyLibrary-Swift.h:172:
@import React;
        ^

<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "React-umbrella.h"
        ^

/Users/brenwell/Dev/native/my-library/ios/Pods/Headers/Public/React/React-umbrella.h:36:9: note: in file included from /Users/brenwell/Dev/native/my-library/ios/Pods/Headers/Public/React/React-umbrella.h:36:
#import "React/RCTBridge.h"
        ^

error: /Users/brenwell/Dev/native/my-library/ios/Pods/Headers/Public/React/React/RCTBridge.h:106:1: error: duplicate interface definition for class 'RCTBridge'
@interface RCTBridge : NSObject <RCTInvalidating>
^

/Users/brenwell/Library/Developer/Xcode/DerivedData/my-library-axsmrqxaoagdyfbmkmhxgjoxfini/Build/Products/Debug-iphonesimulator/include/React/RCTBridge.h:106:12: note: previous definition is here
@interface RCTBridge : NSObject <RCTInvalidating>
           ^

这对每个 React Import 都会重复。任何人有任何想法

最佳答案

您导入了两次 React 框架,因此请删除应用 podfile 中的导入。

关于swift - 使用 use_modular_headers 复制 React 定义 cocoapods,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55591549/

相关文章:

快速警告 : expression implicitly coerced from 'String?' to Any

ios - UITableViewRowAction Action 在滑动时触发,而不是在点击时触发

swift - 我正在尝试检测 ARKit SceneKit 中两个节点之间的接触

xcode - 在 Xcode 上创建新的基于文档的 Cocoa 应用程序的奇怪事情

ios - 我删除了指向 Xcode 中 View 的箭头。我怎么把它拿回来

ios - 如何再次调用权限表 CoreMotion

ios - 执行自动转场

android - 如何为 React Native App 提供 Android notch 支持

javascript - 通过 setTimeOut 再次调用 setState 来响应更改状态

javascript - 淡入淡出到黑色过渡