Unverified Commit 0a8c03dc authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Show warning when an app or plugin uses the V1 Android embedding (#86750)

parent cf3d9409
......@@ -380,27 +380,47 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
templateContext['needsShim'] = false;
// 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.
final List<String> pluginsUsingV1 = <String>[];
for (final Map<String, Object?> plugin in androidPlugins) {
final bool supportsEmbeddingV1 = (plugin['supportsEmbeddingV1'] as bool?) == true;
final bool supportsEmbeddingV2 = (plugin['supportsEmbeddingV2'] as bool?) == true;
if (supportsEmbeddingV1 && !supportsEmbeddingV2) {
templateContext['needsShim'] = true;
if (project.isModule) {
globals.printStatus(
'The plugin `${plugin['name']}` is built using an older version '
"of the Android plugin API which assumes that it's running in a "
'full-Flutter environment. It may have undefined behaviors when '
'Flutter is integrated into an existing app as a module.\n'
'The plugin can be updated to the v2 Android Plugin APIs by '
'following https://flutter.dev/go/android-plugin-migration.'
);
if (plugin['name'] != null) {
pluginsUsingV1.add(plugin['name']! as String);
}
}
}
if (pluginsUsingV1.length > 1) {
globals.printError(
'The plugins `${pluginsUsingV1.join(', ')}` use a deprecated version of the Android embedding.\n'
'To avoid unexpected runtime failures, or future build failures, try to see if these plugins '
'support the Android V2 embedding. Otherwise, consider removing them since a future release '
'of Flutter will remove these deprecated APIs.\n'
'If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: '
'https://flutter.dev/go/android-plugin-migration.'
);
} else if (pluginsUsingV1.isNotEmpty) {
globals.printError(
'The plugin `${pluginsUsingV1.first}` uses a deprecated version of the Android embedding.\n'
'To avoid unexpected runtime failures, or future build failures, try to see if this plugin '
'supports the Android V2 embedding. Otherwise, consider removing it since a future release '
'of Flutter will remove these deprecated APIs.\n'
'If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: '
'https://flutter.dev/go/android-plugin-migration.'
);
}
templateContent = _androidPluginRegistryTemplateNewEmbedding;
break;
case AndroidEmbeddingVersion.v1:
default:
globals.printError(
'This app is using a deprecated version of the Android embedding.\n'
'To avoid unexpected runtime failures, or future build failures, try to migrate this '
'app to the V2 embedding.\n'
'Take a look at the docs for migrating an app: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects'
);
for (final Map<String, Object?> plugin in androidPlugins) {
final bool supportsEmbeddingV1 = (plugin['supportsEmbeddingV1'] as bool?) == true;
final bool supportsEmbeddingV2 = (plugin['supportsEmbeddingV2'] as bool?) == true;
......
......@@ -746,7 +746,11 @@ dependencies:
.childFile('GeneratedPluginRegistrant.java');
expect(registrant.readAsStringSync(),
contains('plugin3.UseOldEmbedding.registerWith(shimPluginRegistry.registrarFor("plugin3.UseOldEmbedding"));'));
expect(testLogger.statusText, contains('The plugin `plugin3` is built using an older version of the Android plugin API'));
expect(testLogger.errorText, equals(
'The plugin `plugin3` uses a deprecated version of the Android embedding.\n'
'To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. '
'Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs.\n'
'If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.\n'));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
......@@ -767,7 +771,7 @@ dependencies:
expect(registrant.readAsStringSync(),
contains('flutterEngine.getPlugins().add(new plugin1.UseNewEmbedding());'));
expect(testLogger.statusText, isNot(contains('go/android-plugin-migration')));
expect(testLogger.errorText, isNot(contains('go/android-plugin-migration')));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
......@@ -788,7 +792,45 @@ dependencies:
expect(registrant.readAsStringSync(),
contains('flutterEngine.getPlugins().add(new plugin4.UseBothEmbedding());'));
expect(testLogger.statusText, isNot(contains('go/android-plugin-migration')));
expect(testLogger.errorText, isNot(contains('go/android-plugin-migration')));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
XcodeProjectInterpreter: () => xcodeProjectInterpreter,
});
testUsingContext('App using plugin with v1 and v2 support shows no warning', () async {
flutterProject.isModule = false;
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
createDualSupportJavaPlugin4();
await injectPlugins(flutterProject, androidPlatform: true);
final File registrant = flutterProject.directory
.childDirectory(fs.path.join('android', 'app', 'src', 'main', 'java', 'io', 'flutter', 'plugins'))
.childFile('GeneratedPluginRegistrant.java');
expect(registrant.readAsStringSync(),
contains('flutterEngine.getPlugins().add(new plugin4.UseBothEmbedding());'));
expect(testLogger.errorText, isNot(contains('go/android-plugin-migration')));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
XcodeProjectInterpreter: () => xcodeProjectInterpreter,
});
testUsingContext('App using the v1 embedding shows warning', () async {
flutterProject.isModule = false;
androidProject.embeddingVersion = AndroidEmbeddingVersion.v1;
await injectPlugins(flutterProject, androidPlatform: true);
expect(testLogger.errorText, equals(
'This app is using a deprecated version of the Android embedding.\n'
'To avoid unexpected runtime failures, or future build failures, try to migrate this app to the V2 embedding.\n'
'Take a look at the docs for migrating an app: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects\n'
));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
......@@ -811,8 +853,40 @@ dependencies:
contains('plugin3.UseOldEmbedding.registerWith(shimPluginRegistry.registrarFor("plugin3.UseOldEmbedding"));'));
expect(registrant.readAsStringSync(),
contains('plugin4.UseOldEmbedding.registerWith(shimPluginRegistry.registrarFor("plugin4.UseOldEmbedding"));'));
expect(testLogger.statusText, contains('The plugin `plugin3` is built using an older version of the Android plugin API'));
expect(testLogger.statusText, contains('The plugin `plugin4` is built using an older version of the Android plugin API'));
expect(testLogger.errorText, equals(
'The plugins `plugin3, plugin4` use a deprecated version of the Android embedding.\n'
'To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. '
'Otherwise, consider removing them since a future release of Flutter will remove these deprecated APIs.\n'
'If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.\n'
));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
XcodeProjectInterpreter: () => xcodeProjectInterpreter,
});
testUsingContext('App using multiple old plugins all show warnings', () async {
flutterProject.isModule = false;
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
createOldJavaPlugin('plugin3');
createOldJavaPlugin('plugin4');
await injectPlugins(flutterProject, androidPlatform: true);
final File registrant = flutterProject.directory
.childDirectory(fs.path.join('android', 'app', 'src', 'main', 'java', 'io', 'flutter', 'plugins'))
.childFile('GeneratedPluginRegistrant.java');
expect(registrant.readAsStringSync(),
contains('plugin3.UseOldEmbedding.registerWith(shimPluginRegistry.registrarFor("plugin3.UseOldEmbedding"));'));
expect(registrant.readAsStringSync(),
contains('plugin4.UseOldEmbedding.registerWith(shimPluginRegistry.registrarFor("plugin4.UseOldEmbedding"));'));
expect(testLogger.errorText, equals(
'The plugins `plugin3, plugin4` use a deprecated version of the Android embedding.\n'
'To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. '
'Otherwise, consider removing them since a future release of Flutter will remove these deprecated APIs.\n'
'If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.\n'
));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
......
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