Always embed Flutter.framework build mode version from Xcode configuration (#42029)
This commit is contained in:
@@ -146,6 +146,7 @@ BuildApp() {
|
||||
RunCommand find "${derived_dir}/engine/Flutter.framework" -type f \( -name '*.h' -o -name '*.modulemap' -o -name '*.plist' \) -exec chmod a-w "{}" \;
|
||||
else
|
||||
RunCommand rm -rf -- "${derived_dir}/Flutter.framework"
|
||||
RunCommand cp -- "${flutter_podspec}" "${derived_dir}"
|
||||
RunCommand cp -r -- "${flutter_framework}" "${derived_dir}"
|
||||
# Make headers, plists, and modulemap files read-only to discourage editing.
|
||||
RunCommand find "${derived_dir}/Flutter.framework" -type f \( -name '*.h' -o -name '*.modulemap' -o -name '*.plist' \) -exec chmod a-w "{}" \;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../base/common.dart';
|
||||
@@ -34,12 +35,19 @@ const String brokenCocoaPodsConsequence = '''
|
||||
This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
|
||||
This can usually be fixed by re-installing CocoaPods. For more info, see https://github.com/flutter/flutter/issues/14293.''';
|
||||
|
||||
const String outOfDatePodfileConsequence = '''
|
||||
This can cause a mismatched version of Flutter to be embedded in your app, which may result in App Store submission rejection or crashes.
|
||||
If you have local Podfile edits you would like to keep, see https://github.com/flutter/flutter/issues/24641 for instructions.''';
|
||||
|
||||
const String cocoaPodsInstallInstructions = '''
|
||||
sudo gem install cocoapods''';
|
||||
|
||||
const String cocoaPodsUpgradeInstructions = '''
|
||||
sudo gem install cocoapods''';
|
||||
|
||||
const String podfileMigrationInstructions = '''
|
||||
rm ios/Podfile''';
|
||||
|
||||
CocoaPods get cocoaPods => context.get<CocoaPods>();
|
||||
|
||||
/// Result of evaluating the CocoaPods installation.
|
||||
@@ -131,13 +139,15 @@ class CocoaPods {
|
||||
if (!xcodeProject.podfile.existsSync()) {
|
||||
throwToolExit('Podfile missing');
|
||||
}
|
||||
bool podsProcessed = false;
|
||||
if (await _checkPodCondition()) {
|
||||
if (_shouldRunPodInstall(xcodeProject, dependenciesChanged)) {
|
||||
await _runPodInstall(xcodeProject, engineDir);
|
||||
return true;
|
||||
podsProcessed = true;
|
||||
}
|
||||
_warnIfPodfileOutOfDate(xcodeProject);
|
||||
}
|
||||
return false;
|
||||
return podsProcessed;
|
||||
}
|
||||
|
||||
/// Make sure the CocoaPods tools are in the right states.
|
||||
@@ -291,7 +301,6 @@ class CocoaPods {
|
||||
<String>['pod', 'install', '--verbose'],
|
||||
workingDirectory: fs.path.dirname(xcodeProject.podfile.path),
|
||||
environment: <String, String>{
|
||||
// For backward compatibility with previously created Podfile only.
|
||||
'FLUTTER_FRAMEWORK_DIR': engineDirectory,
|
||||
// See https://github.com/flutter/flutter/issues/10873.
|
||||
// CocoaPods analytics adds a lot of latency.
|
||||
@@ -326,4 +335,30 @@ class CocoaPods {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Previously, the Podfile created a symlink to the cached artifacts engine framework
|
||||
// and installed the Flutter pod from that path. This could get out of sync with the copy
|
||||
// of the Flutter engine that was copied to ios/Flutter by the xcode_backend script.
|
||||
// It was possible for the symlink to point to a Debug version of the engine when the
|
||||
// Xcode build configuration was Release, which caused App Store submission rejections.
|
||||
//
|
||||
// Warn the user if they are still symlinking to the framework.
|
||||
void _warnIfPodfileOutOfDate(XcodeBasedProject xcodeProject) {
|
||||
if (xcodeProject is! IosProject) {
|
||||
return;
|
||||
}
|
||||
final Link flutterSymlink = fs.link(fs.path.join(
|
||||
xcodeProject.symlinks.path,
|
||||
'flutter',
|
||||
));
|
||||
if (flutterSymlink.existsSync()) {
|
||||
printError(
|
||||
'Warning: Podfile is out of date\n'
|
||||
'$outOfDatePodfileConsequence\n'
|
||||
'To regenerate the Podfile, run:\n'
|
||||
'$podfileMigrationInstructions\n',
|
||||
emphasis: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,6 +288,9 @@ abstract class XcodeBasedProject {
|
||||
|
||||
/// True if the host app project is using Swift.
|
||||
Future<bool> get isSwift;
|
||||
|
||||
/// Directory containing symlinks to pub cache plugins source generated on `pod install`.
|
||||
Directory get symlinks;
|
||||
}
|
||||
|
||||
/// Represents the iOS sub-project of a Flutter project.
|
||||
@@ -350,6 +353,9 @@ class IosProject implements XcodeBasedProject {
|
||||
/// The 'Info.plist' file of the host app.
|
||||
File get hostInfoPlist => hostAppRoot.childDirectory(_hostAppBundleName).childFile('Info.plist');
|
||||
|
||||
@override
|
||||
Directory get symlinks => _flutterLibRoot.childDirectory('.symlinks');
|
||||
|
||||
@override
|
||||
Directory get xcodeProject => hostAppRoot.childDirectory('$_hostAppBundleName.xcodeproj');
|
||||
|
||||
@@ -742,6 +748,9 @@ class MacOSProject implements XcodeBasedProject {
|
||||
@override
|
||||
Directory get xcodeWorkspace => _macOSDirectory.childDirectory('$_hostAppBundleName.xcworkspace');
|
||||
|
||||
@override
|
||||
Directory get symlinks => ephemeralDirectory.childDirectory('.symlinks');
|
||||
|
||||
@override
|
||||
Future<bool> get isSwift async => true;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ xcuserdata
|
||||
**/.generated/
|
||||
Flutter/App.framework
|
||||
Flutter/Flutter.framework
|
||||
Flutter/Flutter.podspec
|
||||
Flutter/Generated.xcconfig
|
||||
Flutter/app.flx
|
||||
Flutter/app.zip
|
||||
|
||||
@@ -15,51 +15,66 @@ def parse_KV_file(file, separator='=')
|
||||
if !File.exists? file_abs_path
|
||||
return [];
|
||||
end
|
||||
pods_ary = []
|
||||
generated_key_values = {}
|
||||
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_ary.push({:name => podname, :path => podpath});
|
||||
else
|
||||
puts "Invalid plugin specification: #{line}"
|
||||
end
|
||||
}
|
||||
return pods_ary
|
||||
File.foreach(file_abs_path) do |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)
|
||||
generated_key_values[podname] = podpath
|
||||
else
|
||||
puts "Invalid plugin specification: #{line}"
|
||||
end
|
||||
end
|
||||
generated_key_values
|
||||
end
|
||||
|
||||
target 'Runner' do
|
||||
use_modular_headers!
|
||||
|
||||
# Flutter Pod
|
||||
|
||||
copied_flutter_dir = File.join(__dir__, 'Flutter')
|
||||
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
|
||||
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
|
||||
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
|
||||
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
|
||||
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
|
||||
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
|
||||
|
||||
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
|
||||
unless File.exist?(generated_xcode_build_settings_path)
|
||||
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
|
||||
end
|
||||
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
|
||||
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
|
||||
|
||||
unless File.exist?(copied_framework_path)
|
||||
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
|
||||
end
|
||||
unless File.exist?(copied_podspec_path)
|
||||
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
|
||||
end
|
||||
end
|
||||
|
||||
# Keep pod path relative so it can be checked into Podfile.lock.
|
||||
pod 'Flutter', :path => 'Flutter'
|
||||
|
||||
# Plugin Pods
|
||||
|
||||
# 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')
|
||||
|
||||
# Flutter Pods
|
||||
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
|
||||
if generated_xcode_build_settings.empty?
|
||||
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first."
|
||||
end
|
||||
generated_xcode_build_settings.map { |p|
|
||||
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
|
||||
symlink = File.join('.symlinks', 'flutter')
|
||||
File.symlink(File.dirname(p[:path]), symlink)
|
||||
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
|
||||
end
|
||||
}
|
||||
|
||||
# Plugin Pods
|
||||
plugin_pods = parse_KV_file('../.flutter-plugins')
|
||||
plugin_pods.map { |p|
|
||||
symlink = File.join('.symlinks', 'plugins', p[:name])
|
||||
File.symlink(p[:path], symlink)
|
||||
pod p[:name], :path => File.join(symlink, 'ios')
|
||||
}
|
||||
plugin_pods.each do |name, path|
|
||||
symlink = File.join('.symlinks', 'plugins', name)
|
||||
File.symlink(path, symlink)
|
||||
pod name, :path => File.join(symlink, 'ios')
|
||||
end
|
||||
end
|
||||
|
||||
# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
|
||||
|
||||
@@ -15,52 +15,67 @@ def parse_KV_file(file, separator='=')
|
||||
if !File.exists? file_abs_path
|
||||
return [];
|
||||
end
|
||||
pods_ary = []
|
||||
generated_key_values = {}
|
||||
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_ary.push({:name => podname, :path => podpath});
|
||||
else
|
||||
puts "Invalid plugin specification: #{line}"
|
||||
end
|
||||
}
|
||||
return pods_ary
|
||||
File.foreach(file_abs_path) do |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)
|
||||
generated_key_values[podname] = podpath
|
||||
else
|
||||
puts "Invalid plugin specification: #{line}"
|
||||
end
|
||||
end
|
||||
generated_key_values
|
||||
end
|
||||
|
||||
target 'Runner' do
|
||||
use_frameworks!
|
||||
use_modular_headers!
|
||||
|
||||
# Flutter Pod
|
||||
|
||||
copied_flutter_dir = File.join(__dir__, 'Flutter')
|
||||
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
|
||||
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
|
||||
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
|
||||
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
|
||||
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
|
||||
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
|
||||
|
||||
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
|
||||
unless File.exist?(generated_xcode_build_settings_path)
|
||||
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
|
||||
end
|
||||
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
|
||||
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
|
||||
|
||||
unless File.exist?(copied_framework_path)
|
||||
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
|
||||
end
|
||||
unless File.exist?(copied_podspec_path)
|
||||
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
|
||||
end
|
||||
end
|
||||
|
||||
# Keep pod path relative so it can be checked into Podfile.lock.
|
||||
pod 'Flutter', :path => 'Flutter'
|
||||
|
||||
# Plugin Pods
|
||||
|
||||
# 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')
|
||||
|
||||
# Flutter Pods
|
||||
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
|
||||
if generated_xcode_build_settings.empty?
|
||||
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first."
|
||||
end
|
||||
generated_xcode_build_settings.map { |p|
|
||||
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
|
||||
symlink = File.join('.symlinks', 'flutter')
|
||||
File.symlink(File.dirname(p[:path]), symlink)
|
||||
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
|
||||
end
|
||||
}
|
||||
|
||||
# Plugin Pods
|
||||
plugin_pods = parse_KV_file('../.flutter-plugins')
|
||||
plugin_pods.map { |p|
|
||||
symlink = File.join('.symlinks', 'plugins', p[:name])
|
||||
File.symlink(p[:path], symlink)
|
||||
pod p[:name], :path => File.join(symlink, 'ios')
|
||||
}
|
||||
plugin_pods.each do |name, path|
|
||||
symlink = File.join('.symlinks', 'plugins', name)
|
||||
File.symlink(path, symlink)
|
||||
pod name, :path => File.join(symlink, 'ios')
|
||||
end
|
||||
end
|
||||
|
||||
# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
|
||||
|
||||
@@ -57,6 +57,7 @@ build/
|
||||
**/ios/.generated/
|
||||
**/ios/Flutter/App.framework
|
||||
**/ios/Flutter/Flutter.framework
|
||||
**/ios/Flutter/Flutter.podspec
|
||||
**/ios/Flutter/Generated.xcconfig
|
||||
**/ios/Flutter/app.flx
|
||||
**/ios/Flutter/app.zip
|
||||
|
||||
@@ -314,6 +314,27 @@ void main() {
|
||||
ProcessManager: () => mockProcessManager,
|
||||
});
|
||||
|
||||
testUsingContext('prints warning, if Podfile is out of date', () async {
|
||||
pretendPodIsInstalled();
|
||||
|
||||
fs.file(fs.path.join('project', 'ios', 'Podfile'))
|
||||
..createSync()
|
||||
..writeAsStringSync('Existing Podfile');
|
||||
|
||||
final Directory symlinks = projectUnderTest.ios.symlinks
|
||||
..createSync(recursive: true);
|
||||
symlinks.childLink('flutter').createSync('cache');
|
||||
|
||||
await cocoaPodsUnderTest.processPods(
|
||||
xcodeProject: projectUnderTest.ios,
|
||||
engineDir: 'engine/path',
|
||||
);
|
||||
expect(testLogger.errorText, contains('Warning: Podfile is out of date'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
});
|
||||
|
||||
testUsingContext('throws, if Podfile is missing.', () async {
|
||||
pretendPodIsInstalled();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user