web-dev-qa-db-de.com

Native iOS reagieren: Modul 'Yoga' konnte nicht erstellt werden: 'Algorithmus'-Datei nicht gefunden

Ich versuche, React Native mit diesem Integrationshandbuch in eine vorhandene Swift-iOS-Anwendung zu integrieren: https://facebook.github.io/react-native/docs/integration-with-existing-apps.html . Die Version von React Native ist 0.53.0.

Ich habe alle erforderlichen Pods erfolgreich installiert und versuche jetzt, das Projekt zu erstellen, wobei jedoch immer der folgende Kompilierungsfehler angezeigt wird:

 enter image description here  enter image description here

 enter image description here

Das Fehlerprotokoll:

While building module 'yoga' imported from ...node_modules/react-native/React/Base/RCTConvert.h:19:
In file included from <module-includes>:1:
In file included from ...ios/Vandebron/Pods/Target Support Files/yoga/yoga-umbrella.h:15:
In file included from ...node_modules/react-native/ReactCommon/yoga/yoga/YGNode.h:13:
...node_modules/react-native/ReactCommon/yoga/yoga/Yoga-internal.h:11:10: fatal error: 'algorithm' file not found
#include <algorithm>
         ^~~~~~~~~~~
1 error generated.
In file included from ...node_modules/react-native/React/Views/RCTActivityIndicatorViewManager.m:10:
In file included from ...node_modules/react-native/React/Views/RCTActivityIndicatorViewManager.h:10:
In file included from ...node_modules/react-native/React/Views/RCTViewManager.h:13:
...node_modules/react-native/React/Base/RCTConvert.h:19:9: fatal error: could not build module 'yoga'
#import <yoga/Yoga.h
7
makovkastar

Dies ist ein Problem der Kokosapoden. Versuchen Sie, nur die benötigten Kopfzeilen freizulegen, indem Sie die Datei yoga.podspec bearbeiten: node_modules/reag-native/ReactCommon/yoga/yoga.podspec Fügen Sie diese Zeile am Ende von yoga.podspec hinzu: 

spec.public_header_files = 'yoga/Yoga.h', 'yoga/YGEnums.h', 

Sieht aus wie das:

      source_files = 'yoga/**/*.{cpp,h}'
       source_files = File.join('ReactCommon/yoga', source_files) if ENV['INSTALL_YOGA_WITHOUT_PATH_OPTION']       
       spec.source_files = source_files    spec.source_files = source_files
+
+  # Only expose the needed headers
+  spec.public_header_files = 'yoga/Yoga.h', 'yoga/YGEnums.h', 'yoga/YGMacros.h'
+
end 

Ref: https://github.com/facebook/react-native/issues/17893

Die eigentliche Pull-Anfrage: https://github.com/facebook/react-native/pull/17764 . Schau dir den Kommentar von Plo4ox an.

10
Thanh Lam

Sie können den folgenden Ausschnitt in Ihre Pod-Datei einfügen, um dieses und einige andere bekannte Probleme mit React Native + Cocoapods zu beheben. Wir haben es in unserem eigenen Projekt getestet und es hat gut funktioniert:

# When using RN in combination with Cocoapods, a lot of
# things are broken. These are the fixes we had to append
# to our Podfile when upgrading to [email protected]
#
# WARNING: Check those line numbers when you're on a different version!

def change_lines_in_file(file_path, &change)
    print "Fixing #{file_path}...\n"

    contents = []

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

    File.open(file_path, 'w') do |f|
        f.puts(change.call(contents))
    end
end


post_install do |installer|

    # https://github.com/facebook/yoga/issues/711#issuecomment-381098373
    change_lines_in_file('./Pods/Target Support Files/yoga/yoga-umbrella.h') do |lines|
        lines.reject do | line |
            [
            '#import "Utils.h"',
            '#import "YGLayout.h"',
            '#import "YGNode.h"',
            '#import "YGNodePrint.h"',
            '#import "YGStyle.h"',
            '#import "Yoga-internal.h"',
            ].include?(line.strip)
        end
    end

    # https://github.com/facebook/yoga/issues/711#issuecomment-374605785
    change_lines_in_file('../../node_modules/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceSizeMeasureMode.h') do |lines|
        unless lines[27].include?("#ifdef __cplusplus")
            lines.insert(27, "#ifdef __cplusplus")
            lines.insert(34, "#endif")
        end
        lines
    end

    # https://github.com/facebook/react-native/issues/13198
    change_lines_in_file('../../node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h') do |lines|
        lines.map { |line| line.include?("#import <RCTAnimation/RCTValueAnimatedNode.h>") ? '#import "RCTValueAnimatedNode.h"' : line }
    end

    # https://github.com/facebook/react-native/issues/16039
    change_lines_in_file('../../node_modules/react-native/Libraries/WebSocket/RCTReconnectingWebSocket.m') do |lines|
        lines.map { |line| line.include?("#import <fishhook/fishhook.h>") ? '#import "fishhook.h"' : line }
    end
end

Der Quellcode stammt aus dieser Gist: https://Gist.github.com/Jpunt/3fe75effd54a702034b75ff697e47578

1
makovkastar

Für React 59 oder höher müssen Sie dies tun. Es behebt auch das Problem beim Herunterladen von React 11

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'root' do
# Uncomment the next line if you're using Swift or would like to use dynamic 
 frameworks
 # use_frameworks!
 # Pods for root
  pod 'React', :path => '../node_modules/react-native'
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
end

post_install do |installer|
 installer.pods_project.targets.each do |target|
  if target.name == "React"
    target.remove_from_project
  end
 end
end
0
Mohammad f