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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:{{agpVersion}}'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:{{agpVersion}}'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,20 @@ pluginManagement {
|
||||
|
||||
includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
|
||||
}
|
||||
}
|
||||
|
||||
include ":app"
|
||||
plugins {
|
||||
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
|
||||
id "com.android.application" version "{{agpVersion}}" apply false
|
||||
}
|
||||
|
||||
apply from: "${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle/app_plugin_loader.gradle"
|
||||
include ":app"
|
||||
@@ -36,6 +36,7 @@
|
||||
"templates/app_shared/android.tmpl/app/src/main/res/values/styles.xml",
|
||||
"templates/app_shared/android.tmpl/app/src/profile/AndroidManifest.xml.tmpl",
|
||||
"templates/app_shared/android.tmpl/gradle.properties.tmpl",
|
||||
"templates/app_shared/android.tmpl/settings.gradle.tmpl",
|
||||
"templates/app_shared/android.tmpl/gradle/wrapper/gradle-wrapper.properties.tmpl",
|
||||
"templates/app_shared/android.tmpl/settings.gradle",
|
||||
"templates/app_shared/ios-objc.tmpl/Runner.xcodeproj/project.pbxproj.tmpl",
|
||||
|
||||
Reference in New Issue
Block a user