From f264d6c2773c3608ad778fa6b5e2f96a2d709baa Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Sun, 8 Dec 2019 20:04:19 -0800 Subject: [PATCH] Allow plugins that don't support the Android platform (#46282) --- .../bin/tasks/plugin_dependencies_test.dart | 57 ++++++++++++++++--- packages/flutter_tools/gradle/flutter.gradle | 2 +- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/dev/devicelab/bin/tasks/plugin_dependencies_test.dart b/dev/devicelab/bin/tasks/plugin_dependencies_test.dart index d5d868c0c0..b931e6d05b 100644 --- a/dev/devicelab/bin/tasks/plugin_dependencies_test.dart +++ b/dev/devicelab/bin/tasks/plugin_dependencies_test.dart @@ -59,6 +59,43 @@ Future main() async { ); }); + section('Create plugin C without android/ directory'); + + final Directory pluginCDirectory = Directory(path.join(tempDir.path, 'plugin_c')); + await inDirectory(tempDir, () async { + await flutter( + 'create', + options: [ + '--org', + 'io.flutter.devicelab.plugin_c', + '--template=plugin', + pluginCDirectory.path, + ], + ); + }); + + File(path.join(pluginCDirectory.path, 'android')).deleteSync(recursive: true); + + final File pluginCpubspec = File(path.join(pluginCDirectory.path, 'pubspec.yaml')); + await pluginCpubspec.writeAsString(''' +name: plugin_c +version: 0.0.1 + +flutter: + plugin: + platforms: + ios: + pluginClass: Plugin_cPlugin + +dependencies: + flutter: + sdk: flutter + +environment: + sdk: ">=2.0.0-dev.28.0 <3.0.0" + flutter: ">=1.5.0 <2.0.0" +''', flush: true); + section('Write dummy Kotlin code in plugin B'); final File pluginBKotlinClass = File(path.join( @@ -81,17 +118,19 @@ public class DummyPluginBClass { } ''', flush: true); - section('Make plugin A depend on plugin B'); + section('Make plugin A depend on plugin B and plugin C'); - final File pubspec = File(path.join(pluginADirectory.path, 'pubspec.yaml')); - String content = await pubspec.readAsString(); - content = content.replaceFirst( + final File pluginApubspec = File(path.join(pluginADirectory.path, 'pubspec.yaml')); + String pluginApubspecContent = await pluginApubspec.readAsString(); + pluginApubspecContent = pluginApubspecContent.replaceFirst( '\ndependencies:\n', '\ndependencies:\n' ' plugin_b:\n' - ' path: ${pluginBDirectory.path}\n', + ' path: ${pluginBDirectory.path}\n' + ' plugin_c:\n' + ' path: ${pluginCDirectory.path}\n', ); - await pubspec.writeAsString(content, flush: true); + await pluginApubspec.writeAsString(pluginApubspecContent, flush: true); section('Write Kotlin code in plugin A that references Kotlin code from plugin B'); @@ -142,11 +181,15 @@ public class DummyPluginAClass { '\"dependencyGraph\":[' '{' '\"name\":\"plugin_a\",' - '\"dependencies\":[\"plugin_b\"]' + '\"dependencies\":[\"plugin_b\",\"plugin_c\"]' '},' '{' '\"name\":\"plugin_b\",' '\"dependencies\":[]' + '},' + '{' + '\"name\":\"plugin_c\",' + '\"dependencies\":[]' '}' ']' '}'; diff --git a/packages/flutter_tools/gradle/flutter.gradle b/packages/flutter_tools/gradle/flutter.gradle index 40a6c9e1bd..fde4000583 100644 --- a/packages/flutter_tools/gradle/flutter.gradle +++ b/packages/flutter_tools/gradle/flutter.gradle @@ -349,7 +349,7 @@ class FlutterPlugin implements Plugin { return } Project dependencyProject = project.rootProject.findProject(":$pluginDependencyName") - if (dependencyProject == null) { + if (!dependencyProject.projectDir.exists() || dependencyProject == null) { return } // Wait for the Android plugin to load and add the dependency to the plugin project.