Commit 9884f998 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by Flutter GitHub Bot

Change meaning of a plugin not supporting the android platform (#47015)

parent b3e14cc6
...@@ -74,7 +74,9 @@ Future<void> main() async { ...@@ -74,7 +74,9 @@ Future<void> main() async {
); );
}); });
File(path.join(pluginCDirectory.path, 'android')).deleteSync(recursive: true); // https://github.com/flutter/flutter/issues/46898
// https://github.com/flutter/flutter/issues/39657
File(path.join(pluginCDirectory.path, 'android', 'build.gradle')).deleteSync();
final File pluginCpubspec = File(path.join(pluginCDirectory.path, 'pubspec.yaml')); final File pluginCpubspec = File(path.join(pluginCDirectory.path, 'pubspec.yaml'));
await pluginCpubspec.writeAsString(''' await pluginCpubspec.writeAsString('''
......
...@@ -331,15 +331,24 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -331,15 +331,24 @@ class FlutterPlugin implements Plugin<Project> {
} }
} }
// Returns `true` if the given path contains an `android/build.gradle` file.
//
// TODO(egarciad): Fix https://github.com/flutter/flutter/issues/39657.
// Android Studio may create empty android directories due to the logic in <app>/android/settings.gradle,
// which imports all plugins regardless of whether they support the android platform.
private Boolean doesSupportAndroidPlatform(String path) {
File editableAndroidProject = new File(path, 'android' + File.separator + 'build.gradle')
return editableAndroidProject.exists()
}
// Add the dependencies on other plugin projects to the plugin project. // Add the dependencies on other plugin projects to the plugin project.
// A plugin A can depend on plugin B. As a result, this dependency must be surfaced by // A plugin A can depend on plugin B. As a result, this dependency must be surfaced by
// making the Gradle plugin project A depend on the Gradle plugin project B. // making the Gradle plugin project A depend on the Gradle plugin project B.
private void configurePluginDependencies(Object dependencyObject) { private void configurePluginDependencies(Object dependencyObject) {
assert dependencyObject.name instanceof String assert dependencyObject.name instanceof String
Project pluginProject = project.rootProject.findProject(":${dependencyObject.name}") Project pluginProject = project.rootProject.findProject(":${dependencyObject.name}")
if (pluginProject == null) { if (pluginProject == null ||
// Ignore plugins that don't have a project since most likely they don't !doesSupportAndroidPlatform(pluginProject.projectDir.parentFile.path)) {
// have an android/ directory.
return return
} }
assert dependencyObject.dependencies instanceof List assert dependencyObject.dependencies instanceof List
...@@ -349,7 +358,8 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -349,7 +358,8 @@ class FlutterPlugin implements Plugin<Project> {
return return
} }
Project dependencyProject = project.rootProject.findProject(":$pluginDependencyName") Project dependencyProject = project.rootProject.findProject(":$pluginDependencyName")
if (!dependencyProject.projectDir.exists() || dependencyProject == null) { if (dependencyProject == null ||
!doesSupportAndroidPlatform(dependencyProject.projectDir.parentFile.path)) {
return return
} }
// Wait for the Android plugin to load and add the dependency to the plugin project. // Wait for the Android plugin to load and add the dependency to the plugin project.
...@@ -366,8 +376,7 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -366,8 +376,7 @@ class FlutterPlugin implements Plugin<Project> {
Properties allPlugins = readPropertiesIfExist(pluginsFile) Properties allPlugins = readPropertiesIfExist(pluginsFile)
Properties androidPlugins = new Properties() Properties androidPlugins = new Properties()
allPlugins.each { name, path -> allPlugins.each { name, path ->
File editableAndroidProject = new File(path, 'android' + File.separator + 'build.gradle') if (doesSupportAndroidPlatform(path)) {
if (editableAndroidProject.exists()) {
androidPlugins.setProperty(name, path) androidPlugins.setProperty(name, path)
} }
// TODO(amirh): log an error if this plugin was specified to be an Android // TODO(amirh): log an error if this plugin was specified to be an Android
......
...@@ -716,8 +716,9 @@ Future<void> buildPluginsAsAar( ...@@ -716,8 +716,9 @@ Future<void> buildPluginsAsAar(
assert(pluginDirectory.existsSync()); assert(pluginDirectory.existsSync());
final String pluginName = pluginParts.first; final String pluginName = pluginParts.first;
if (!pluginDirectory.childDirectory('android').existsSync()) { final File buildGradleFile = pluginDirectory.childDirectory('android').childFile('build.gradle');
printTrace('Skipping plugin $pluginName since it doesn\'t have an android directory'); if (!buildGradleFile.existsSync()) {
printTrace('Skipping plugin $pluginName since it doesn\'t have a android/build.gradle file');
continue; continue;
} }
logger.printStatus('Building plugin $pluginName...'); logger.printStatus('Building plugin $pluginName...');
......
...@@ -897,7 +897,10 @@ flutter: ...@@ -897,7 +897,10 @@ flutter:
androidPackage: irrelevant androidPackage: irrelevant
'''); ''');
plugin1.childDirectory('android').createSync(); plugin1
.childDirectory('android')
.childFile('build.gradle')
.createSync(recursive: true);
final Directory plugin2 = fs.directory('plugin2.'); final Directory plugin2 = fs.directory('plugin2.');
plugin2 plugin2
...@@ -910,7 +913,10 @@ flutter: ...@@ -910,7 +913,10 @@ flutter:
androidPackage: irrelevant androidPackage: irrelevant
'''); ''');
plugin2.childDirectory('android').createSync(); plugin2
.childDirectory('android')
.childFile('build.gradle')
.createSync(recursive: true);
androidDirectory androidDirectory
.childFile('.flutter-plugins') .childFile('.flutter-plugins')
...@@ -976,7 +982,7 @@ plugin2=${plugin2.path} ...@@ -976,7 +982,7 @@ plugin2=${plugin2.path}
GradleUtils: () => FakeGradleUtils(), GradleUtils: () => FakeGradleUtils(),
}); });
testUsingContext('skips plugin without an android directory', () async { testUsingContext('skips plugin without a android/build.gradle file', () async {
final Directory androidDirectory = fs.directory('android.'); final Directory androidDirectory = fs.directory('android.');
androidDirectory.createSync(); androidDirectory.createSync();
androidDirectory androidDirectory
...@@ -999,6 +1005,10 @@ flutter: ...@@ -999,6 +1005,10 @@ flutter:
.writeAsStringSync(''' .writeAsStringSync('''
plugin1=${plugin1.path} plugin1=${plugin1.path}
'''); ''');
// Create an empty android directory.
// https://github.com/flutter/flutter/issues/46898
plugin1.childDirectory('android').createSync();
final Directory buildDirectory = androidDirectory.childDirectory('build'); final Directory buildDirectory = androidDirectory.childDirectory('build');
buildDirectory buildDirectory
......
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