Fix v1 embedding support heuristic for plugins (#44214)
This commit is contained in:
@@ -64,17 +64,20 @@ class AndroidPlugin extends PluginPlatform {
|
||||
'name': name,
|
||||
'package': package,
|
||||
'class': pluginClass,
|
||||
'usesEmbedding2': _embeddingVersion == '2',
|
||||
// Mustache doesn't support complex types.
|
||||
'supportsEmbeddingV1': _supportedEmbedings.contains('1'),
|
||||
'supportsEmbeddingV2': _supportedEmbedings.contains('2'),
|
||||
};
|
||||
}
|
||||
|
||||
String _cachedEmbeddingVersion;
|
||||
Set<String> _cachedEmbeddingVersion;
|
||||
|
||||
/// Returns the version of the Android embedding.
|
||||
String get _embeddingVersion => _cachedEmbeddingVersion ??= _getEmbeddingVersion();
|
||||
Set<String> get _supportedEmbedings => _cachedEmbeddingVersion ??= _getSupportedEmbeddings();
|
||||
|
||||
String _getEmbeddingVersion() {
|
||||
Set<String> _getSupportedEmbeddings() {
|
||||
assert(pluginPath != null);
|
||||
final Set<String> supportedEmbeddings = <String>{};
|
||||
final String baseMainPath = fs.path.join(
|
||||
pluginPath,
|
||||
'android',
|
||||
@@ -113,9 +116,15 @@ class AndroidPlugin extends PluginPlatform {
|
||||
}
|
||||
if (mainClassContent
|
||||
.contains('io.flutter.embedding.engine.plugins.FlutterPlugin')) {
|
||||
return '2';
|
||||
supportedEmbeddings.add('2');
|
||||
} else {
|
||||
supportedEmbeddings.add('1');
|
||||
}
|
||||
return '1';
|
||||
if (mainClassContent.contains('PluginRegistry')
|
||||
&& mainClassContent.contains('registerWith')) {
|
||||
supportedEmbeddings.add('1');
|
||||
}
|
||||
return supportedEmbeddings;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -337,12 +337,14 @@ public final class GeneratedPluginRegistrant {
|
||||
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
|
||||
{{/needsShim}}
|
||||
{{#plugins}}
|
||||
{{#usesEmbedding2}}
|
||||
{{#supportsEmbeddingV2}}
|
||||
flutterEngine.getPlugins().add(new {{package}}.{{class}}());
|
||||
{{/usesEmbedding2}}
|
||||
{{^usesEmbedding2}}
|
||||
{{package}}.{{class}}.registerWith(shimPluginRegistry.registrarFor("{{package}}.{{class}}"));
|
||||
{{/usesEmbedding2}}
|
||||
{{/supportsEmbeddingV2}}
|
||||
{{^supportsEmbeddingV2}}
|
||||
{{#supportsEmbeddingV1}}
|
||||
{{package}}.{{class}}.registerWith(shimPluginRegistry.registrarFor("{{package}}.{{class}}"));
|
||||
{{/supportsEmbeddingV1}}
|
||||
{{/supportsEmbeddingV2}}
|
||||
{{/plugins}}
|
||||
}
|
||||
}
|
||||
@@ -396,14 +398,24 @@ 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,
|
||||
// then add shim for the old plugins.
|
||||
for (Map<String, dynamic> plugin in androidPlugins) {
|
||||
if (!plugin['usesEmbedding2']) {
|
||||
if (plugin['supportsEmbeddingV1'] && !plugin['supportsEmbeddingV2']) {
|
||||
templateContext['needsShim'] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
templateContent = _androidPluginRegistryTemplateNewEmbedding;
|
||||
break;
|
||||
break;
|
||||
case AndroidEmbeddingVersion.v1:
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user