Skip to content

Commit

Permalink
Revert "Fix how Gradle resolves Android plugin" (#98050)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Garcia authored Feb 8, 2022
1 parent 0ee8e0e commit d2b5f34
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 168 deletions.
1 change: 0 additions & 1 deletion packages/flutter_tools/gradle/app_plugin_loader.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ assert object instanceof Map
assert object.plugins instanceof Map
assert object.plugins.android instanceof List
// Includes the Flutter plugins that support the Android platform.
// This logic must be kept in sync with the logic in flutter.gradle.
object.plugins.android.each { androidPlugin ->
assert androidPlugin.name instanceof String
assert androidPlugin.path instanceof String
Expand Down
74 changes: 27 additions & 47 deletions packages/flutter_tools/gradle/flutter.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FlutterExtension {
* Specifies the relative directory to the Flutter project directory.
* In an app project, this is ../.. since the app's build.gradle is under android/app.
*/
String source = '../..'
String source

/** Allows to override the target file. Otherwise, the target is lib/main.dart. */
String target
Expand Down Expand Up @@ -418,7 +418,7 @@ class FlutterPlugin implements Plugin<Project> {

/**
* Compares semantic versions ignoring labels.
*
*
* If the versions are equal (ignoring labels), returns one of the two strings arbitrarily.
*
* If minor or patch are omitted (non-conformant to semantic versioning), they are considered zero.
Expand Down Expand Up @@ -459,9 +459,6 @@ class FlutterPlugin implements Plugin<Project> {

getPluginList().each { plugin ->
Project pluginProject = project.rootProject.findProject(plugin.key)
if (pluginProject == null) {
return
}
pluginProject.afterEvaluate {
int pluginCompileSdkVersion = pluginProject.android.compileSdkVersion.substring(8) as int
maxPluginCompileSdkVersion = Math.max(pluginCompileSdkVersion, maxPluginCompileSdkVersion)
Expand All @@ -479,7 +476,15 @@ class FlutterPlugin implements Plugin<Project> {
}
}
}
}
}
}

/**
* Returns `true` if the given path contains an `android/build.gradle` file.
*/
private Boolean doesSupportAndroidPlatform(String path) {
File editableAndroidProject = new File(path, 'android' + File.separator + 'build.gradle')
return editableAndroidProject.exists()
}

/**
Expand All @@ -490,7 +495,8 @@ class FlutterPlugin implements Plugin<Project> {
private void configurePluginDependencies(Object dependencyObject) {
assert dependencyObject.name instanceof String
Project pluginProject = project.rootProject.findProject(":${dependencyObject.name}")
if (pluginProject == null) {
if (pluginProject == null ||
!doesSupportAndroidPlatform(pluginProject.projectDir.parentFile.path)) {
return
}
assert dependencyObject.dependencies instanceof List
Expand All @@ -500,7 +506,8 @@ class FlutterPlugin implements Plugin<Project> {
return
}
Project dependencyProject = project.rootProject.findProject(":$pluginDependencyName")
if (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.
Expand All @@ -512,27 +519,17 @@ class FlutterPlugin implements Plugin<Project> {
}
}

/** Gets the list of plugins that support the Android platform. */
private Properties getPluginList() {
Map meta = getDependenciesMetadata()
File pluginsFile = new File(project.projectDir.parentFile.parentFile, '.flutter-plugins')
Properties allPlugins = readPropertiesIfExist(pluginsFile)
Properties androidPlugins = new Properties()
if (meta == null) {
return androidPlugins
}
assert meta.plugins instanceof Map
assert meta.plugins.android instanceof List

// This logic must be kept in sync with the logic in app_plugin_loader.gradle.
meta.plugins.android.each { androidPlugin ->
assert androidPlugin.name instanceof String
assert androidPlugin.path instanceof String
// Skip plugins that have no native build (such as a Dart-only implementation
// of a federated plugin).
def needsBuild = androidPlugin.containsKey('native_build') ? androidPlugin['native_build'] : true
if (!needsBuild) {
return
allPlugins.each { name, path ->
if (doesSupportAndroidPlatform(path)) {
androidPlugins.setProperty(name, path)
}
androidPlugins.setProperty(androidPlugin.name, androidPlugin.path)
// TODO(amirh): log an error if this plugin was specified to be an Android
// plugin according to the new schema, and was missing a build.gradle file.
// https://github.com/flutter/flutter/issues/40784
}
return androidPlugins
}
Expand Down Expand Up @@ -560,31 +557,14 @@ class FlutterPlugin implements Plugin<Project> {
// This means, `plugin-a` depends on `plugin-b` and `plugin-c`.
// `plugin-b` depends on `plugin-c`.
// `plugin-c` doesn't depend on anything.
Map meta = getDependenciesMetadata()
if (meta == null) {
return []
}
assert meta.dependencyGraph instanceof List
return meta.dependencyGraph
}

private Map parsedFlutterPluginsDependencies

/**
* Parses <project-src>/.flutter-plugins-dependencies
*/
private Map getDependenciesMetadata() {
if (parsedFlutterPluginsDependencies) {
return parsedFlutterPluginsDependencies
}
File pluginsDependencyFile = new File(getFlutterSourceDirectory(), '.flutter-plugins-dependencies')
File pluginsDependencyFile = new File(project.projectDir.parentFile.parentFile, '.flutter-plugins-dependencies')
if (pluginsDependencyFile.exists()) {
def object = new JsonSlurper().parseText(pluginsDependencyFile.text)
assert object instanceof Map
parsedFlutterPluginsDependencies = object
return object
assert object.dependencyGraph instanceof List
return object.dependencyGraph
}
return null
return []
}

private static String toCammelCase(List<String> parts) {
Expand Down

This file was deleted.

0 comments on commit d2b5f34

Please sign in to comment.