我一直在React Native iOS项目中工作并使用cocoapods . 当我在我的项目中执行"import React"时,它会抛出错误"Could not build Objective-C module 'React'" . 并且"ArtNode.h"中有错误说“ Include of non-modular header inside framework module 'React.ARTNode ” . 20其他类似包含在其他头文件中发生的非模块化头错误 .

我不知道是什么问题,这是我的pod文件:

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'
use_frameworks!

target ‘TestApp’ do
  pod 'Alamofire'
  pod 'RealmSwift'
  pod 'SwiftyJSON', '~> 4.0'
  pod 'SSZipArchive'
  pod 'Firebase/Core'
  pod 'Firebase/Messaging'
  pod 'Fabric'
  pod 'Crashlytics'

  # ReactNative
  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
    'RCTActionSheet',
    'RCTAnimation',
    'RCTText',
    'RCTImage',
    'RCTNetwork',
    'RCTPushNotification',
    'RCTWebSocket', # needed for debugging
    'RCTGeolocation',
    'RCTSettings',
    'RCTVibration',
    'RCTLinkingIOS',
    # Add any other subspecs you want to use in your project
  ]
  # Explicitly include Yoga if you are using RN >= 0.42.0
  pod "yoga", :path => "../node_modules/react-native/ReactCommon/yoga"
  # Third party deps podspec link
  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'

  # Other link
  # pod 'RNI18n', :path => '../node_modules/react-native-i18n'  
  pod 'react-native-fetch-blob', :path => '../node_modules/react-native-fetch-blob'
  pod 'react-native-pdf', :path => '../node_modules/react-native-pdf'
  pod 'react-native-config', :path => '../node_modules/react-native-config'
end

def fix_unused_yoga_headers
    filepath = './Pods/Target Support Files/yoga/yoga-umbrella.h'

    contents = []

    file = File.open(filepath, 'r')
    file.each_line do | line |
        contents << line
    end
    file.close

    if contents[12].include? "Utils.h"
        contents.delete_at(15) # #import "YGNode.h"
        contents.delete_at(15) # #import "YGNodePrint.h"
        contents.delete_at(15) # #import "Yoga-internal.h"
        contents.delete_at(12) # #import "Utils.h"

        file = File.open(filepath, 'w') do |f|
            f.puts(contents)
        end
    end
end

def react_native_fix
    fix_unused_yoga_headers
end

post_install do |installer|
    react_native_fix

    # Fix react-native-config Bug: 'GeneratedDotEnv.m' file not found
    installer.pods_project.targets.each do |target|
        if target.name == 'react-native-config'
            phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
            phase.shell_script = "cd ../../"\
            " && RNC_ROOT=./node_modules/react-native-config/"\
            " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
            " && export BUILD_DIR=$RNC_ROOT/ios/ReactNativeConfig"\
            " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

            target.build_phases << phase
            target.build_phases.move(phase,0)
        end
    end

    installer.pods_project.build_configuration_list.build_configurations.each do |configuration|
             configuration.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
    end

end