Add iOS module template (#18830)
Add iOS module template This will enable integration of flutter-views into existing iOS project.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>App</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>io.flutter.flutter.app</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>App</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>8.0</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,2 @@
|
||||
This directory contains support code for embedding the Flutter project in an iOS app.
|
||||
It should not be edited or checked in.
|
||||
@@ -0,0 +1,77 @@
|
||||
# This file should be used from the target section of the host-app's Podfile like this:
|
||||
# ```
|
||||
# target 'host' do
|
||||
# flutter_application_path = /"(.*)\/.ios\/Generated.xcconfig"/.match(File.read("./Flutter/FlutterConfig.xcconfig"))[1]
|
||||
# eval(File.read(File.join(flutter_application_path, '.ios', 'podhelper.rb')))
|
||||
# end
|
||||
# ```
|
||||
|
||||
def parse_KV_file(file, separator='=')
|
||||
file_abs_path = File.expand_path(file)
|
||||
if !File.exists? file_abs_path
|
||||
return [];
|
||||
end
|
||||
pods_array = []
|
||||
skip_line_start_symbols = ["#", "/"]
|
||||
File.foreach(file_abs_path) { |line|
|
||||
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
|
||||
plugin = line.split(pattern=separator)
|
||||
if plugin.length == 2
|
||||
podname = plugin[0].strip()
|
||||
path = plugin[1].strip()
|
||||
podpath = File.expand_path("#{path}", file_abs_path)
|
||||
pods_array.push({:name => podname, :path => podpath});
|
||||
else
|
||||
puts "Invalid plugin specification: #{line}"
|
||||
end
|
||||
}
|
||||
return pods_array
|
||||
end
|
||||
|
||||
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
|
||||
# referring to absolute paths on developers' machines.
|
||||
system('rm -rf .symlinks')
|
||||
system('mkdir -p .symlinks/plugins')
|
||||
|
||||
def flutter_root(f)
|
||||
generated_xcode_build_settings = parse_KV_file(File.join(f, File.join('.ios', 'Generated.xcconfig')))
|
||||
if generated_xcode_build_settings.empty?
|
||||
puts "Generated.xcconfig must exist. Make sure `flutter packages get` is executed in ${f}."
|
||||
exit
|
||||
end
|
||||
generated_xcode_build_settings.map { |p|
|
||||
if p[:name] == 'FLUTTER_ROOT'
|
||||
return p[:path]
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
framework_dir = File.join(File.expand_path(File.dirname(__FILE__)), 'Flutter')
|
||||
engine_dir = File.join(framework_dir, 'engine')
|
||||
if !File.exist?(engine_dir)
|
||||
# Copy the debug engine to have something to link against if the xcode backend script has not run yet.
|
||||
debug_framework_dir = File.join(flutter_root(flutter_application_path), 'bin', 'cache', 'artifacts', 'engine', 'ios')
|
||||
FileUtils.mkdir(engine_dir)
|
||||
FileUtils.cp_r(File.join(debug_framework_dir, 'Flutter.framework'), engine_dir)
|
||||
FileUtils.cp(File.join(debug_framework_dir, 'Flutter.podspec'), engine_dir)
|
||||
end
|
||||
|
||||
symlink = File.join('.symlinks', 'flutter')
|
||||
|
||||
File.symlink(framework_dir, symlink)
|
||||
pod 'Flutter', :path => File.join(symlink, 'engine')
|
||||
|
||||
|
||||
plugin_pods = parse_KV_file(File.join(flutter_application_path, '.flutter-plugins'))
|
||||
|
||||
plugin_pods.map { |r|
|
||||
symlink = File.join('.symlinks', 'plugins', r[:name])
|
||||
|
||||
File.symlink(r[:path], symlink)
|
||||
pod r[:name], :path => File.join(symlink, 'ios')
|
||||
}
|
||||
|
||||
symlink = File.join('.symlinks', 'FlutterApp')
|
||||
File.symlink(File.absolute_path(flutter_application_path), symlink)
|
||||
|
||||
pod 'FlutterPluginRegistrant', :path => File.join(symlink, '.ios', 'FlutterPluginRegistrant')
|
||||
Reference in New Issue
Block a user