无法构建Objective-C模块“反应”

时间:2018-08-11 04:16:31

标签: ios objective-c swift react-native cocoapods

我一直在从事React Native iOS项目并使用cocoapods。当我在项目中“导入React”时,它会引发错误“无法构建Objective-C模块'React'”。并且在“ ArtNode.h”中出现错误,提示“ 在框架模块'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

1 个答案:

答案 0 :(得分:0)

您可以将Build Settings中的 允许框架模块中的非模块化包含 ,将受影响的目标设置为“是”。这是您需要编辑的构建设置:

enter image description here

并在尝试导入标题之前重建项目