mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] build ios-frameworks: option to exclude plugin frameworks from the build (#129739)
A lot of details are written in the feature request: https://github.com/flutter/flutter/issues/114692. tl;dr: Options B & C from the add2app iOS guide have a limitation (build error) in case the Flutter plugin and native iOS app have a shared dependency. We can use a workaround to avoid the issue, but in this case we don't need to build frameworks for plugins. Closes https://github.com/flutter/flutter/issues/114692 Part of https://github.com/flutter/flutter/issues/130220
This commit is contained in:
parent
f387b77f2f
commit
0f67c99208
@ -493,6 +493,12 @@ Future<void> _testBuildIosFramework(Directory projectDir, { bool isModule = fals
|
||||
isModule) {
|
||||
throw TaskResult.failure('Unexpected GeneratedPluginRegistrant.m.');
|
||||
}
|
||||
|
||||
section('Build frameworks without plugins');
|
||||
await _testBuildFrameworksWithoutPlugins(projectDir, platform: 'ios');
|
||||
|
||||
section('check --static cannot be used with the --no-plugins flag');
|
||||
await _testStaticAndNoPlugins(projectDir);
|
||||
}
|
||||
|
||||
|
||||
@ -816,6 +822,83 @@ Future<void> _testBuildMacOSFramework(Directory projectDir) async {
|
||||
outputPath,
|
||||
'GeneratedPluginRegistrant.swift',
|
||||
));
|
||||
|
||||
section('Build frameworks without plugins');
|
||||
await _testBuildFrameworksWithoutPlugins(projectDir, platform: 'macos');
|
||||
}
|
||||
|
||||
Future<void> _testBuildFrameworksWithoutPlugins(Directory projectDir, { required String platform}) async {
|
||||
const String noPluginsOutputDir = 'flutter-frameworks-no-plugins';
|
||||
|
||||
await inDirectory(projectDir, () async {
|
||||
await flutter(
|
||||
'build',
|
||||
options: <String>[
|
||||
'$platform-framework',
|
||||
'--cocoapods',
|
||||
'--force', // Allow podspec creation on master.
|
||||
'--output=$noPluginsOutputDir',
|
||||
'--no-plugins',
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
final String noPluginsOutputPath = path.join(projectDir.path, noPluginsOutputDir);
|
||||
for (final String mode in <String>['Debug', 'Profile', 'Release']) {
|
||||
checkFileExists(path.join(
|
||||
noPluginsOutputPath,
|
||||
mode,
|
||||
'Flutter${platform == 'macos' ? 'MacOS' : ''}.podspec',
|
||||
));
|
||||
checkDirectoryExists(path.join(
|
||||
noPluginsOutputPath,
|
||||
mode,
|
||||
'App.xcframework',
|
||||
));
|
||||
|
||||
checkDirectoryNotExists(path.join(
|
||||
noPluginsOutputPath,
|
||||
mode,
|
||||
'package_info.xcframework',
|
||||
));
|
||||
|
||||
checkDirectoryNotExists(path.join(
|
||||
noPluginsOutputPath,
|
||||
mode,
|
||||
'connectivity.xcframework',
|
||||
));
|
||||
|
||||
checkDirectoryNotExists(path.join(
|
||||
noPluginsOutputPath,
|
||||
mode,
|
||||
'Reachability.xcframework',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _testStaticAndNoPlugins(Directory projectDir) async {
|
||||
const String noPluginsOutputDir = 'flutter-frameworks-no-plugins-static';
|
||||
final ProcessResult result = await inDirectory(projectDir, () async {
|
||||
return executeFlutter(
|
||||
'build',
|
||||
options: <String>[
|
||||
'ios-framework',
|
||||
'--cocoapods',
|
||||
'--force', // Allow podspec creation on master.
|
||||
'--output=$noPluginsOutputDir',
|
||||
'--no-plugins',
|
||||
'--static'
|
||||
],
|
||||
canFail: true
|
||||
);
|
||||
});
|
||||
if (result.exitCode == 0) {
|
||||
throw TaskResult.failure('Build framework command did not exit with error as expected');
|
||||
}
|
||||
final String output = '${result.stdout}\n${result.stderr}';
|
||||
if (!output.contains('--static cannot be used with the --no-plugins flag')) {
|
||||
throw TaskResult.failure(output);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _checkDylib(String pathToLibrary) async {
|
||||
|
@ -68,6 +68,11 @@ abstract class BuildFrameworkCommand extends BuildSubCommand {
|
||||
..addFlag('cocoapods',
|
||||
help: 'Produce a Flutter.podspec instead of an engine Flutter.xcframework (recommended if host app uses CocoaPods).',
|
||||
)
|
||||
..addFlag('plugins',
|
||||
defaultsTo: true,
|
||||
help: 'Whether to produce frameworks for the plugins. '
|
||||
'This is intended for cases where plugins are already being built separately.',
|
||||
)
|
||||
..addFlag('static',
|
||||
help: 'Build plugins as static frameworks. Link on, but do not embed these frameworks in the existing Xcode project.',
|
||||
)
|
||||
@ -135,6 +140,10 @@ abstract class BuildFrameworkCommand extends BuildSubCommand {
|
||||
if ((await getBuildInfos()).isEmpty) {
|
||||
throwToolExit('At least one of "--debug" or "--profile", or "--release" is required.');
|
||||
}
|
||||
|
||||
if (!boolArg('plugins') && boolArg('static')) {
|
||||
throwToolExit('--static cannot be used with the --no-plugins flag');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> produceXCFramework(
|
||||
@ -264,7 +273,7 @@ class BuildIOSFrameworkCommand extends BuildFrameworkCommand {
|
||||
|
||||
// Build and copy plugins.
|
||||
await processPodsIfNeeded(project.ios, getIosBuildDirectory(), buildInfo.mode);
|
||||
if (hasPlugins(project)) {
|
||||
if (boolArg('plugins') && hasPlugins(project)) {
|
||||
await _producePlugins(buildInfo.mode, xcodeBuildConfiguration, iPhoneBuildOutput, simulatorBuildOutput, modeDirectory);
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ class BuildMacOSFrameworkCommand extends BuildFrameworkCommand {
|
||||
// Build and copy plugins.
|
||||
final Directory buildOutput = modeDirectory.childDirectory('macos');
|
||||
await processPodsIfNeeded(project.macos, getMacOSBuildDirectory(), buildInfo.mode);
|
||||
if (hasPlugins(project)) {
|
||||
if (boolArg('plugins') && hasPlugins(project)) {
|
||||
await _producePlugins(xcodeBuildConfiguration, buildOutput, modeDirectory);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user