Unverified Commit 02aac507 authored by Michael Klimushyn's avatar Michael Klimushyn Committed by GitHub

Revert "Exit tool if a plugin supports the embedding v2 but the app doesn't (#44026)"

This missed some plugins that _do_ support the v1 embedding
(shared_preferences as one known case) so caused unexpected breakages.

This reverts commit b94c1a41.
parent 8b53c66c
...@@ -64,20 +64,17 @@ class AndroidPlugin extends PluginPlatform { ...@@ -64,20 +64,17 @@ class AndroidPlugin extends PluginPlatform {
'name': name, 'name': name,
'package': package, 'package': package,
'class': pluginClass, 'class': pluginClass,
// Mustache doesn't support complex types. 'usesEmbedding2': _embeddingVersion == '2',
'supportsEmbeddingV1': _supportedEmbedings.contains('1'),
'supportsEmbeddingV2': _supportedEmbedings.contains('2'),
}; };
} }
Set<String> _cachedEmbeddingVersion; String _cachedEmbeddingVersion;
/// Returns the version of the Android embedding. /// Returns the version of the Android embedding.
Set<String> get _supportedEmbedings => _cachedEmbeddingVersion ??= _getSupportedEmbeddings(); String get _embeddingVersion => _cachedEmbeddingVersion ??= _getEmbeddingVersion();
Set<String> _getSupportedEmbeddings() { String _getEmbeddingVersion() {
assert(pluginPath != null); assert(pluginPath != null);
final Set<String> supportedEmbeddings = <String>{};
final String baseMainPath = fs.path.join( final String baseMainPath = fs.path.join(
pluginPath, pluginPath,
'android', 'android',
...@@ -116,15 +113,9 @@ class AndroidPlugin extends PluginPlatform { ...@@ -116,15 +113,9 @@ class AndroidPlugin extends PluginPlatform {
} }
if (mainClassContent if (mainClassContent
.contains('io.flutter.embedding.engine.plugins.FlutterPlugin')) { .contains('io.flutter.embedding.engine.plugins.FlutterPlugin')) {
supportedEmbeddings.add('2'); return '2';
} else {
supportedEmbeddings.add('1');
} }
if (mainClassContent.contains('registerWith(Registrar registrar)') || return '1';
mainClassContent.contains('registerWith(registrar: Registrar)')) {
supportedEmbeddings.add('1');
}
return supportedEmbeddings;
} }
} }
......
...@@ -337,14 +337,12 @@ public final class GeneratedPluginRegistrant { ...@@ -337,14 +337,12 @@ public final class GeneratedPluginRegistrant {
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine); ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
{{/needsShim}} {{/needsShim}}
{{#plugins}} {{#plugins}}
{{#supportsEmbeddingV2}} {{#usesEmbedding2}}
flutterEngine.getPlugins().add(new {{package}}.{{class}}()); flutterEngine.getPlugins().add(new {{package}}.{{class}}());
{{/supportsEmbeddingV2}} {{/usesEmbedding2}}
{{^supportsEmbeddingV2}} {{^usesEmbedding2}}
{{#supportsEmbeddingV1}}
{{package}}.{{class}}.registerWith(shimPluginRegistry.registrarFor("{{package}}.{{class}}")); {{package}}.{{class}}.registerWith(shimPluginRegistry.registrarFor("{{package}}.{{class}}"));
{{/supportsEmbeddingV1}} {{/usesEmbedding2}}
{{/supportsEmbeddingV2}}
{{/plugins}} {{/plugins}}
} }
} }
...@@ -398,24 +396,14 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin> ...@@ -398,24 +396,14 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
// If a plugin is using an embedding version older than 2.0 and the app is using 2.0, // If a plugin is using an embedding version older than 2.0 and the app is using 2.0,
// then add shim for the old plugins. // then add shim for the old plugins.
for (Map<String, dynamic> plugin in androidPlugins) { for (Map<String, dynamic> plugin in androidPlugins) {
if (plugin['supportsEmbeddingV1'] && !plugin['supportsEmbeddingV2']) { if (!plugin['usesEmbedding2']) {
templateContext['needsShim'] = true; templateContext['needsShim'] = true;
break; break;
} }
} }
templateContent = _androidPluginRegistryTemplateNewEmbedding; templateContent = _androidPluginRegistryTemplateNewEmbedding;
break; break;
case AndroidEmbeddingVersion.v1:
default: default:
for (Map<String, dynamic> plugin in androidPlugins) {
if (!plugin['supportsEmbeddingV1'] && plugin['supportsEmbeddingV2']) {
throwToolExit(
'The plugin `${plugin['name']}` requires your app to be migrated to '
'the Android embedding v2. Follow the steps on https://flutter.dev/go/android-project-migration '
'and re-run this command.'
);
}
}
templateContent = _androidPluginRegistryTemplateOldEmbedding; templateContent = _androidPluginRegistryTemplateOldEmbedding;
break; break;
} }
......
...@@ -265,99 +265,6 @@ plugin3:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()} ...@@ -265,99 +265,6 @@ plugin3:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()}
XcodeProjectInterpreter: () => xcodeProjectInterpreter, XcodeProjectInterpreter: () => xcodeProjectInterpreter,
}); });
testUsingContext('exits the tool if an app uses the v1 embedding and a plugin only supports the v2 embedding', () async {
when(flutterProject.isModule).thenReturn(false);
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
final Directory pluginUsingJavaAndNewEmbeddingDir =
fs.systemTempDirectory.createTempSync('flutter_plugin_using_java_and_new_embedding_dir.');
pluginUsingJavaAndNewEmbeddingDir
.childFile('pubspec.yaml')
.writeAsStringSync('''
flutter:
plugin:
androidPackage: plugin1
pluginClass: UseNewEmbedding
''');
pluginUsingJavaAndNewEmbeddingDir
.childDirectory('android')
.childDirectory('src')
.childDirectory('main')
.childDirectory('java')
.childDirectory('plugin1')
.childFile('UseNewEmbedding.java')
..createSync(recursive: true)
..writeAsStringSync('import io.flutter.embedding.engine.plugins.FlutterPlugin;');
flutterProject.directory
.childFile('.packages')
.writeAsStringSync('''
plugin1:${pluginUsingJavaAndNewEmbeddingDir.childDirectory('lib').uri.toString()}
''');
await expectLater(
() async {
await injectPlugins(flutterProject);
},
throwsToolExit(
message: 'The plugin `plugin1` requires your app to be migrated to the Android embedding v2. '
'Follow the steps on https://flutter.dev/go/android-project-migration and re-run this command.'
),
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => featureFlags,
XcodeProjectInterpreter: () => xcodeProjectInterpreter,
});
testUsingContext('allows app use a plugin that supports v1 and v2 embedding', () async {
when(flutterProject.isModule).thenReturn(false);
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
final Directory pluginUsingJavaAndNewEmbeddingDir =
fs.systemTempDirectory.createTempSync('flutter_plugin_using_java_and_new_embedding_dir.');
pluginUsingJavaAndNewEmbeddingDir
.childFile('pubspec.yaml')
.writeAsStringSync('''
flutter:
plugin:
androidPackage: plugin1
pluginClass: UseNewEmbedding
''');
pluginUsingJavaAndNewEmbeddingDir
.childDirectory('android')
.childDirectory('src')
.childDirectory('main')
.childDirectory('java')
.childDirectory('plugin1')
.childFile('UseNewEmbedding.java')
..createSync(recursive: true)
..writeAsStringSync(
'import io.flutter.embedding.engine.plugins.FlutterPlugin;'
'registerWith(Registrar registrar)'
);
flutterProject.directory
.childFile('.packages')
.writeAsStringSync('''
plugin1:${pluginUsingJavaAndNewEmbeddingDir.childDirectory('lib').uri.toString()}
''');
await injectPlugins(flutterProject);
final File registrant = flutterProject.directory
.childDirectory(fs.path.join('android', 'app', 'src', 'main', 'java', 'io', 'flutter', 'plugins'))
.childFile('GeneratedPluginRegistrant.java');
expect(registrant.existsSync(), isTrue);
expect(registrant.readAsStringSync(), contains('package io.flutter.plugins'));
expect(registrant.readAsStringSync(), contains('class GeneratedPluginRegistrant'));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => featureFlags,
XcodeProjectInterpreter: () => xcodeProjectInterpreter,
});
testUsingContext('Registrant doesn\'t use new embedding if app doesn\'t use new embedding', () async { testUsingContext('Registrant doesn\'t use new embedding if app doesn\'t use new embedding', () async {
when(flutterProject.isModule).thenReturn(false); when(flutterProject.isModule).thenReturn(false);
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1); when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment