Refactor "app plugin loader" Gradle Plugin so it can be applied using the declarative plugins {} block (#127897)
This PR fixes #125009.
This commit is contained in:
@@ -2,35 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// This file is included from `<app>/android/settings.gradle`,
|
||||
// so it can be versioned with the Flutter SDK.
|
||||
// This file exists solely for the compatibility with projects that have
|
||||
// not migrated to the declarative apply of the Flutter App Plugin Loader Gradle Plugin.
|
||||
|
||||
import groovy.json.JsonSlurper
|
||||
|
||||
def flutterProjectRoot = rootProject.projectDir.parentFile
|
||||
|
||||
// If this logic is changed, also change the logic in module_plugin_loader.gradle.
|
||||
def pluginsFile = new File(flutterProjectRoot, '.flutter-plugins-dependencies')
|
||||
if (!pluginsFile.exists()) {
|
||||
return
|
||||
}
|
||||
|
||||
def object = new JsonSlurper().parseText(pluginsFile.text)
|
||||
assert object instanceof Map
|
||||
assert object.plugins instanceof Map
|
||||
assert object.plugins.android instanceof List
|
||||
// Includes the Flutter plugins that support the Android platform.
|
||||
object.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
|
||||
}
|
||||
def pluginDirectory = new File(androidPlugin.path, 'android')
|
||||
assert pluginDirectory.exists()
|
||||
include ":${androidPlugin.name}"
|
||||
project(":${androidPlugin.name}").projectDir = pluginDirectory
|
||||
}
|
||||
def pathToThisDirectory = buildscript.sourceFile.parentFile
|
||||
apply from: "$pathToThisDirectory/src/main/groovy/app_plugin_loader.groovy"
|
||||
|
||||
@@ -3,12 +3,8 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
plugins {
|
||||
`groovy-gradle-plugin`
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
`java-gradle-plugin`
|
||||
`groovy`
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +18,10 @@ gradlePlugin {
|
||||
id = "dev.flutter.flutter-gradle-plugin"
|
||||
implementationClass = "FlutterPlugin"
|
||||
}
|
||||
create("flutterAppPluginLoaderPlugin") {
|
||||
id = "dev.flutter.flutter-plugin-loader"
|
||||
implementationClass = "FlutterAppPluginLoaderPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
7
packages/flutter_tools/gradle/settings.gradle.kts
Normal file
7
packages/flutter_tools/gradle/settings.gradle.kts
Normal file
@@ -0,0 +1,7 @@
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import groovy.json.JsonSlurper
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.initialization.Settings
|
||||
|
||||
apply plugin: FlutterAppPluginLoaderPlugin
|
||||
|
||||
class FlutterAppPluginLoaderPlugin implements Plugin<Settings> {
|
||||
// This string must match _kFlutterPluginsHasNativeBuildKey defined in
|
||||
// packages/flutter_tools/lib/src/flutter_plugins.dart.
|
||||
private final String nativeBuildKey = 'native_build'
|
||||
|
||||
@Override
|
||||
void apply(Settings settings) {
|
||||
def flutterProjectRoot = settings.settingsDir.parentFile
|
||||
|
||||
// If this logic is changed, also change the logic in module_plugin_loader.gradle.
|
||||
def pluginsFile = new File(flutterProjectRoot, '.flutter-plugins-dependencies')
|
||||
if (!pluginsFile.exists()) {
|
||||
return
|
||||
}
|
||||
|
||||
def object = new JsonSlurper().parseText(pluginsFile.text)
|
||||
assert object instanceof Map
|
||||
assert object.plugins instanceof Map
|
||||
assert object.plugins.android instanceof List
|
||||
// Includes the Flutter plugins that support the Android platform.
|
||||
object.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(nativeBuildKey) ? androidPlugin[nativeBuildKey] : true
|
||||
if (!needsBuild) {
|
||||
return
|
||||
}
|
||||
def pluginDirectory = new File(androidPlugin.path, 'android')
|
||||
assert pluginDirectory.exists()
|
||||
settings.include(":${androidPlugin.name}")
|
||||
settings.project(":${androidPlugin.name}").projectDir = pluginDirectory
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user