@@ -16,53 +16,70 @@ def parse_KV_file(file, separator='=')
1616 if !File . exists? file_abs_path
1717 return [ ] ;
1818 end
19- pods_ary = [ ]
19+ generated_key_values = { }
2020 skip_line_start_symbols = [ "#" , "/" ]
21- File . foreach ( file_abs_path ) { |line |
22- next if skip_line_start_symbols . any? { |symbol | line =~ /^\s *#{ symbol } / }
23- plugin = line . split ( pattern = separator )
24- if plugin . length == 2
25- podname = plugin [ 0 ] . strip ( )
26- path = plugin [ 1 ] . strip ( )
27- podpath = File . expand_path ( "#{ path } " , file_abs_path )
28- pods_ary . push ( { :name => podname , :path => podpath } ) ;
29- else
30- puts "Invalid plugin specification: #{ line } "
31- end
32- }
33- return pods_ary
21+ File . foreach ( file_abs_path ) do |line |
22+ next if skip_line_start_symbols . any? { |symbol | line =~ /^\s *#{ symbol } / }
23+ plugin = line . split ( pattern = separator )
24+ if plugin . length == 2
25+ podname = plugin [ 0 ] . strip ( )
26+ path = plugin [ 1 ] . strip ( )
27+ podpath = File . expand_path ( "#{ path } " , file_abs_path )
28+ generated_key_values [ podname ] = podpath
29+ else
30+ puts "Invalid plugin specification: #{ line } "
31+ end
32+ end
33+ generated_key_values
3434end
3535
3636target 'Runner' do
37+ # Flutter Pod
38+
39+ copied_flutter_dir = File . join ( __dir__ , 'Flutter' )
40+ copied_framework_path = File . join ( copied_flutter_dir , 'Flutter.framework' )
41+ copied_podspec_path = File . join ( copied_flutter_dir , 'Flutter.podspec' )
42+ unless File . exist? ( copied_framework_path ) && File . exist? ( copied_podspec_path )
43+ # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
44+ # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
45+ # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
46+
47+ generated_xcode_build_settings_path = File . join ( copied_flutter_dir , 'Generated.xcconfig' )
48+ unless File . exist? ( generated_xcode_build_settings_path )
49+ raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
50+ end
51+ generated_xcode_build_settings = parse_KV_file ( generated_xcode_build_settings_path )
52+ cached_framework_dir = generated_xcode_build_settings [ 'FLUTTER_FRAMEWORK_DIR' ] ;
53+
54+ unless File . exist? ( copied_framework_path )
55+ FileUtils . cp_r ( File . join ( cached_framework_dir , 'Flutter.framework' ) , copied_flutter_dir )
56+ end
57+ unless File . exist? ( copied_podspec_path )
58+ FileUtils . cp ( File . join ( cached_framework_dir , 'Flutter.podspec' ) , copied_flutter_dir )
59+ end
60+ end
61+
62+ # Keep pod path relative so it can be checked into Podfile.lock.
63+ pod 'Flutter' , :path => 'Flutter'
64+
65+ # Plugin Pods
3766 pod 'PSPDFKit' , podspec :'https://customers.pspdfkit.com/cocoapods/YOUR_COCOAPODS_KEY_GOES_HERE/pspdfkit/latest.podspec'
38-
67+
3968 # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
4069 # referring to absolute paths on developers' machines.
4170 system ( 'rm -rf .symlinks' )
4271 system ( 'mkdir -p .symlinks/plugins' )
43-
44- # Flutter Pods
45- generated_xcode_build_settings = parse_KV_file ( './Flutter/Generated.xcconfig' )
46- if generated_xcode_build_settings . empty?
47- puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
48- end
49- generated_xcode_build_settings . map { |p |
50- if p [ :name ] == 'FLUTTER_FRAMEWORK_DIR'
51- symlink = File . join ( '.symlinks' , 'flutter' )
52- File . symlink ( File . dirname ( p [ :path ] ) , symlink )
53- pod 'Flutter' , :path => File . join ( symlink , File . basename ( p [ :path ] ) )
54- end
55- }
56-
57- # Plugin Pods
5872 plugin_pods = parse_KV_file ( '../.flutter-plugins' )
59- plugin_pods . map { | p |
60- symlink = File . join ( '.symlinks' , 'plugins' , p [ : name] )
61- File . symlink ( p [ : path] , symlink )
62- pod p [ : name] , :path => File . join ( symlink , 'ios' )
63- }
73+ plugin_pods . each do | name , path |
74+ symlink = File . join ( '.symlinks' , 'plugins' , name )
75+ File . symlink ( path , symlink )
76+ pod name , :path => File . join ( symlink , 'ios' )
77+ end
6478end
6579
80+ # Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
81+ install! 'cocoapods' , :disable_input_output_paths => true
82+
6683post_install do |installer |
6784 installer . pods_project . targets . each do |target |
6885 target . build_configurations . each do |config |
0 commit comments