[Android] Removes dev dependency plugins from release builds (#158026)
Removes plugins that are `dev_dependency`s from being dependencies of release builds of Flutter Android app projects. Fixes https://github.com/flutter/flutter/issues/157949. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
@@ -769,10 +769,18 @@ class FlutterPlugin implements Plugin<Project> {
|
||||
// Apply the "flutter" Gradle extension to plugins so that they can use it's vended
|
||||
// compile/target/min sdk values.
|
||||
pluginProject.extensions.create("flutter", FlutterExtension)
|
||||
|
||||
// Add plugin dependency to the app project.
|
||||
project.dependencies {
|
||||
api(pluginProject)
|
||||
project.android.buildTypes.each { buildType ->
|
||||
String flutterBuildMode = buildModeFor(buildType)
|
||||
if (flutterBuildMode != "release" || !pluginObject.dev_dependency) {
|
||||
// Only add dependency on dev dependencies in non-release builds.
|
||||
project.dependencies {
|
||||
api(pluginProject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Closure addEmbeddingDependencyToPlugin = { buildType ->
|
||||
String flutterBuildMode = buildModeFor(buildType)
|
||||
// In AGP 3.5, the embedding must be added as an API implementation,
|
||||
@@ -784,6 +792,12 @@ class FlutterPlugin implements Plugin<Project> {
|
||||
if (!pluginProject.hasProperty("android")) {
|
||||
return
|
||||
}
|
||||
if (flutterBuildMode == "release" && pluginObject.dev_dependency) {
|
||||
// This plugin is a dev dependency and will not be included in
|
||||
// the release build, so no need to add the embedding
|
||||
// dependency to it.
|
||||
return
|
||||
}
|
||||
// Copy build types from the app to the plugin.
|
||||
// This allows to build apps with plugins and custom build types or flavors.
|
||||
pluginProject.android.buildTypes {
|
||||
@@ -944,20 +958,29 @@ class FlutterPlugin implements Plugin<Project> {
|
||||
if (pluginProject == null) {
|
||||
return
|
||||
}
|
||||
def dependencies = pluginObject.dependencies
|
||||
assert(dependencies instanceof List<String>)
|
||||
dependencies.each { pluginDependencyName ->
|
||||
if (pluginDependencyName.empty) {
|
||||
|
||||
project.android.buildTypes.each { buildType ->
|
||||
String flutterBuildMode = buildModeFor(buildType)
|
||||
if (flutterBuildMode == "release" && pluginObject.dev_dependency) {
|
||||
// This plugin is a dev dependency will not be included in the
|
||||
// release build, so no need to add its dependencies.
|
||||
return
|
||||
}
|
||||
Project dependencyProject = project.rootProject.findProject(":$pluginDependencyName")
|
||||
if (dependencyProject == null) {
|
||||
return
|
||||
}
|
||||
// Wait for the Android plugin to load and add the dependency to the plugin project.
|
||||
pluginProject.afterEvaluate {
|
||||
pluginProject.dependencies {
|
||||
implementation(dependencyProject)
|
||||
def dependencies = pluginObject.dependencies
|
||||
assert(dependencies instanceof List<String>)
|
||||
dependencies.each { pluginDependencyName ->
|
||||
if (pluginDependencyName.empty) {
|
||||
return
|
||||
}
|
||||
Project dependencyProject = project.rootProject.findProject(":$pluginDependencyName")
|
||||
if (dependencyProject == null) {
|
||||
return
|
||||
}
|
||||
// Wait for the Android plugin to load and add the dependency to the plugin project.
|
||||
pluginProject.afterEvaluate {
|
||||
pluginProject.dependencies {
|
||||
implementation(dependencyProject)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,10 @@ class NativePluginLoader {
|
||||
* "path": "/path/to/plugin-a",
|
||||
* "dependencies": ["plugin-b", "plugin-c"],
|
||||
* "native_build": true
|
||||
* "dev_dependency": false
|
||||
* }
|
||||
*
|
||||
* Therefore the map value can either be a `String`, a `List<String>` or a `boolean`.
|
||||
* Therefore the map value can either be a `String`, a `List<String>` or a `Boolean`.
|
||||
*/
|
||||
List<Map<String, Object>> getPlugins(File flutterSourceDirectory) {
|
||||
List<Map<String, Object>> nativePlugins = []
|
||||
@@ -40,6 +41,7 @@ class NativePluginLoader {
|
||||
assert(androidPlugin.name instanceof String)
|
||||
assert(androidPlugin.path instanceof String)
|
||||
assert(androidPlugin.dependencies instanceof List<String>)
|
||||
assert(androidPlugin.dev_dependency instanceof Boolean)
|
||||
// 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
|
||||
@@ -66,18 +68,28 @@ class NativePluginLoader {
|
||||
// "path": "/path/to/plugin-a",
|
||||
// "dependencies": ["plugin-b", "plugin-c"],
|
||||
// "native_build": true
|
||||
// "dev_dependency": false
|
||||
// },
|
||||
// {
|
||||
// "name": "plugin-b",
|
||||
// "path": "/path/to/plugin-b",
|
||||
// "dependencies": ["plugin-c"],
|
||||
// "native_build": true
|
||||
// "dev_dependency": false
|
||||
// },
|
||||
// {
|
||||
// "name": "plugin-c",
|
||||
// "path": "/path/to/plugin-c",
|
||||
// "dependencies": [],
|
||||
// "native_build": true
|
||||
// "dev_dependency": false
|
||||
// },
|
||||
// {
|
||||
// "name": "plugin-d",
|
||||
// "path": "/path/to/plugin-d",
|
||||
// "dependencies": [],
|
||||
// "native_build": true
|
||||
// "dev_dependency": true
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
@@ -93,12 +105,18 @@ class NativePluginLoader {
|
||||
// {
|
||||
// "name": "plugin-c",
|
||||
// "dependencies": []
|
||||
// },
|
||||
// {
|
||||
// "name": "plugin-d",
|
||||
// "dependencies": []
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// This means, `plugin-a` depends on `plugin-b` and `plugin-c`.
|
||||
// `plugin-b` depends on `plugin-c`.
|
||||
// `plugin-c` doesn't depend on anything.
|
||||
// `plugin-d` also doesn't depend on anything, but it is a dev
|
||||
// dependency to the Flutter project, so it is marked as such.
|
||||
if (parsedFlutterPluginsDependencies) {
|
||||
return parsedFlutterPluginsDependencies
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user