[flutter_tools] toolexit when using plugins with preview device (#136936)
Part of https://github.com/flutter/flutter/issues/130277 Without this, if a user runs an app that has plugins that call method channels with the `preview` device, the app will build successfully, however, they will get a runtime error when their dart code tries to call the method channel that does not exist in the native build (which was pre-built and thus does not include the plugin code). This change adds a validation when injecting plugins that will tool exit if the device-id is `preview` and their project contains plugins with method channels.
This commit is contained in:
committed by
GitHub
parent
5ebca79f76
commit
d550ba54eb
@@ -17,6 +17,7 @@ import 'package:flutter_tools/src/flutter_plugins.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
||||
import 'package:flutter_tools/src/plugins.dart';
|
||||
import 'package:flutter_tools/src/preview_device.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:test/fake.dart';
|
||||
@@ -210,7 +211,7 @@ void main() {
|
||||
? fakePubCache.childDirectory(name)
|
||||
: fileSystem.directory(nameOrPath);
|
||||
packagesFile.writeAsStringSync(
|
||||
'$name:file://${pluginDirectory.childFile('lib').uri}\n',
|
||||
'$name:${pluginDirectory.childFile('lib').uri}\n',
|
||||
mode: FileMode.writeOnlyAppend);
|
||||
pluginDirectory.childFile('pubspec.yaml')
|
||||
..createSync(recursive: true)
|
||||
@@ -1438,6 +1439,29 @@ flutter:
|
||||
FileSystem: () => fsWindows,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('injectPlugins will validate if all plugins in the project are part of the passed allowedPlugins', () async {
|
||||
// Re-run the setup using the Windows filesystem.
|
||||
setUpProject(fsWindows);
|
||||
createFakePlugins(fsWindows, const <String>['plugin_one', 'plugin_two']);
|
||||
|
||||
expect(
|
||||
() => injectPlugins(
|
||||
flutterProject,
|
||||
linuxPlatform: true,
|
||||
windowsPlatform: true,
|
||||
allowedPlugins: PreviewDevice.supportedPubPlugins,
|
||||
),
|
||||
throwsToolExit(message: '''
|
||||
The Flutter Preview device does not support the following plugins from your pubspec.yaml:
|
||||
|
||||
[plugin_one, plugin_two]
|
||||
'''),
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fsWindows,
|
||||
ProcessManager: () => FakeProcessManager.empty(),
|
||||
});
|
||||
});
|
||||
|
||||
group('createPluginSymlinks', () {
|
||||
|
||||
Reference in New Issue
Block a user