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 {
);
});
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'));
await pluginCpubspec.writeAsString('''
......
......@@ -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.
// 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.
private void configurePluginDependencies(Object dependencyObject) {
assert dependencyObject.name instanceof String
Project pluginProject = project.rootProject.findProject(":${dependencyObject.name}")
if (pluginProject == null) {
// Ignore plugins that don't have a project since most likely they don't
// have an android/ directory.
if (pluginProject == null ||
!doesSupportAndroidPlatform(pluginProject.projectDir.parentFile.path)) {
return
}
assert dependencyObject.dependencies instanceof List
......@@ -349,7 +358,8 @@ class FlutterPlugin implements Plugin<Project> {
return
}
Project dependencyProject = project.rootProject.findProject(":$pluginDependencyName")
if (!dependencyProject.projectDir.exists() || dependencyProject == null) {
if (dependencyProject == null ||
!doesSupportAndroidPlatform(dependencyProject.projectDir.parentFile.path)) {
return
}
// Wait for the Android plugin to load and add the dependency to the plugin project.
......@@ -366,8 +376,7 @@ class FlutterPlugin implements Plugin<Project> {
Properties allPlugins = readPropertiesIfExist(pluginsFile)
Properties androidPlugins = new Properties()
allPlugins.each { name, path ->
File editableAndroidProject = new File(path, 'android' + File.separator + 'build.gradle')
if (editableAndroidProject.exists()) {
if (doesSupportAndroidPlatform(path)) {
androidPlugins.setProperty(name, path)
}
// TODO(amirh): log an error if this plugin was specified to be an Android
......
......@@ -716,8 +716,9 @@ Future<void> buildPluginsAsAar(
assert(pluginDirectory.existsSync());
final String pluginName = pluginParts.first;
if (!pluginDirectory.childDirectory('android').existsSync()) {
printTrace('Skipping plugin $pluginName since it doesn\'t have an android directory');
final File buildGradleFile = pluginDirectory.childDirectory('android').childFile('build.gradle');
if (!buildGradleFile.existsSync()) {
printTrace('Skipping plugin $pluginName since it doesn\'t have a android/build.gradle file');
continue;
}
logger.printStatus('Building plugin $pluginName...');
......
......@@ -897,7 +897,10 @@ flutter:
androidPackage: irrelevant
''');
plugin1.childDirectory('android').createSync();
plugin1
.childDirectory('android')
.childFile('build.gradle')
.createSync(recursive: true);
final Directory plugin2 = fs.directory('plugin2.');
plugin2
......@@ -910,7 +913,10 @@ flutter:
androidPackage: irrelevant
''');
plugin2.childDirectory('android').createSync();
plugin2
.childDirectory('android')
.childFile('build.gradle')
.createSync(recursive: true);
androidDirectory
.childFile('.flutter-plugins')
......@@ -976,7 +982,7 @@ plugin2=${plugin2.path}
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.');
androidDirectory.createSync();
androidDirectory
......@@ -999,6 +1005,10 @@ flutter:
.writeAsStringSync('''
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');
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