Unverified Commit e1ae4dfc authored by xster's avatar xster Committed by GitHub

Move v1 embedding migration warning from plugin consumers to all apps (#64181)

parent a1097d70
......@@ -661,12 +661,6 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
break;
case AndroidEmbeddingVersion.v1:
default:
globals.printStatus(
'Your Flutter application is created using an older version of the '
"Android embedding. It's being deprecated in favor of Android embedding "
'v2. Follow the steps on https://flutter.dev/go/android-project-migration '
'to migrate your project.'
);
for (final Map<String, dynamic> plugin in androidPlugins) {
if (!(plugin['supportsEmbeddingV1'] as bool) && plugin['supportsEmbeddingV2'] as bool) {
throwToolExit(
......
......@@ -756,6 +756,23 @@ class AndroidProject extends FlutterProjectPlatform {
}
Future<void> ensureReadyForPlatformSpecificTooling() async {
if (getEmbeddingVersion() == AndroidEmbeddingVersion.v1) {
globals.printStatus(
"""
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It's being deprecated in favor of Android embedding v2. Follow the
steps at
https://flutter.dev/go/android-project-migration
to migrate your project.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
"""
);
}
if (isModule && _shouldRegenerateFromTemplate()) {
await _regenerateLibrary();
// Add ephemeral host app, if an editable host app does not already exist.
......
......@@ -654,6 +654,31 @@ void main() {
expect(actualContents.contains('useAndroidX'), true);
});
testUsingContext('creating a new project should create v2 embedding and never show an Android v1 deprecation warning', () async {
Cache.flutterRoot = '../..';
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--no-pub', '--platforms', 'android', projectDir.path]);
final String androidManifest = await globals.fs.file(
projectDir.path + '/android/app/src/main/AndroidManifest.xml'
).readAsString();
expect(androidManifest.contains('android:name="flutterEmbedding"'), true);
expect(androidManifest.contains('android:value="2"'), true);
final String mainActivity = await globals.fs.file(
projectDir.path + '/android/app/src/main/kotlin/com/example/flutter_project/MainActivity.kt'
).readAsString();
// Import for the new embedding class.
expect(mainActivity.contains('import io.flutter.embedding.android.FlutterActivity'), true);
expect(testLogger.statusText, isNot(contains('https://flutter.dev/go/android-project-migration')));
});
testUsingContext('app supports Linux if requested', () async {
Cache.flutterRoot = '../..';
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
......
......@@ -638,7 +638,7 @@ dependencies:
XcodeProjectInterpreter: () => xcodeProjectInterpreter,
});
testUsingContext('old embedding app uses a plugin that supports v1 and v2 embedding works but shows a deprecation warning', () async {
testUsingContext('old embedding app uses a plugin that supports v1 and v2 embedding works', () async {
when(flutterProject.isModule).thenReturn(false);
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
......@@ -655,7 +655,6 @@ dependencies:
expect(registrant.readAsStringSync(), contains('class GeneratedPluginRegistrant'));
expect(registrant.readAsStringSync(),
contains('UseBothEmbedding.registerWith(registry.registrarFor("plugin4.UseBothEmbedding"));'));
expect(testLogger.statusText, contains('Follow the steps on https://flutter.dev/go/android-project-migration'));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
......
......@@ -148,6 +148,20 @@ void main() {
await project.ensureReadyForPlatformSpecificTooling();
expectExists(project.android.hostAppGradleRoot.childFile('local.properties'));
});
_testInMemory('Android project not on v2 embedding shows a warning', () async {
final FlutterProject project = await someProject();
// The default someProject with an empty <manifest> already indicates
// v1 embedding, as opposed to having <meta-data
// android:name="flutterEmbedding" android:value="2" />.
await project.ensureReadyForPlatformSpecificTooling();
expect(testLogger.statusText, contains('https://flutter.dev/go/android-project-migration'));
});
_testInMemory('updates local properties for Android', () async {
final FlutterProject project = await someProject();
await project.ensureReadyForPlatformSpecificTooling();
expectExists(project.android.hostAppGradleRoot.childFile('local.properties'));
});
testUsingContext('injects plugins for macOS', () async {
final FlutterProject project = await someProject();
project.macos.managedDirectory.createSync(recursive: true);
......
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