Skip to content

Commit f964f15

Browse files
authored
Fix flutter build aar for modules that use a plugin (flutter#154757)
flutter#151675 bumped module templates to AGP 8.1. In doing so, I tried to work around a behavior change [that was new in AGP 8.0](https://developer.android.com/build/releases/past-releases/agp-8-0-0-release-notes): > AGP 8.0 creates no SoftwareComponent by default. Instead AGP creates SoftwareComponents only for variants that are configured to be published using the publishing DSL. by using AGP's publishing DSL to define which variants to publish in the module's ephemeral gradle files: ``` android.buildTypes.all {buildType -> if (!android.productFlavors.isEmpty()) { android.productFlavors.all{productFlavor -> android.publishing.singleVariant(productFlavor.name + buildType.name.capitalize()) { withSourcesJar() withJavadocJar() } } } else { android.publishing.singleVariant(buildType.name) { withSourcesJar() withJavadocJar() } } } ``` The problem is that this doesn't get applied to the plugin projects used by the module, so if a module uses any plugin it breaks. This PR fixes that by applying similar logic, but to each project (not just the module's project). Tested manually with https://github.com/gmackall/GrayAddToApp, and also re-enabled an old test that tested this use case as a part of the PR. Fixes: flutter#154371
1 parent 7e2de37 commit f964f15

File tree

4 files changed

+55
-16
lines changed

4 files changed

+55
-16
lines changed

.ci.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,28 @@ targets:
424424
task_name: android_views
425425
timeout: 60
426426

427+
- name: Linux build_aar_module_test
428+
bringup: true
429+
recipe: devicelab/devicelab_drone
430+
timeout: 60
431+
properties:
432+
add_recipes_cq: "true"
433+
dependencies: >-
434+
[
435+
{"dependency": "android_sdk", "version": "version:34v3"},
436+
{"dependency": "chrome_and_driver", "version": "version:125.0.6422.141"},
437+
{"dependency": "open_jdk", "version": "17"}
438+
]
439+
tags: >
440+
["devicelab","hostonly"]
441+
task_name: build_aar_module_test
442+
scheduler: luci
443+
runIf:
444+
- dev/**
445+
- packages/flutter_tools/**
446+
- bin/**
447+
- .ci.yaml
448+
427449
- name: Linux build_tests_1_5
428450
bringup: true
429451
recipe: flutter/flutter_drone

dev/devicelab/bin/tasks/build_aar_module_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ Future<void> main() async {
6565
' path: ../plugin_with_android$platformLineSep'
6666
' plugin_without_android:$platformLineSep'
6767
' path: ../plugin_without_android$platformLineSep'
68-
' webcrypto: 0.5.2$platformLineSep', // Plugin that uses NDK.
6968
);
7069
modulePubspec.writeAsStringSync(content, flush: true);
7170

packages/flutter_tools/gradle/aar_init_script.gradle

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,39 @@ allprojects {
116116
apply plugin: "maven-publish"
117117
}
118118

119+
afterProject { project ->
120+
// Exit early if either:
121+
// 1. The project doesn't have the Android Gradle plugin applied.
122+
// 2. The project has already defined which variants to publish (trying to re-define which
123+
// variants to publish will result in an error).
124+
if (!project.hasProperty("android")) {
125+
return
126+
}
127+
if (project.android.publishing.singleVariants.size() != 0) {
128+
return
129+
}
130+
131+
Closure addSingleVariants = {buildType ->
132+
if (!project.android.productFlavors.isEmpty()) {
133+
project.android.productFlavors.all{productFlavor ->
134+
project.android.publishing.singleVariant(
135+
productFlavor.name + buildType.name.capitalize()
136+
) {
137+
withSourcesJar()
138+
withJavadocJar()
139+
}
140+
}
141+
} else {
142+
project.android.publishing.singleVariant(buildType.name) {
143+
withSourcesJar()
144+
withJavadocJar()
145+
}
146+
}
147+
}
148+
149+
project.android.buildTypes.all(addSingleVariants)
150+
}
151+
119152
projectsEvaluated {
120153
assert rootProject.hasProperty("is-plugin")
121154
if (rootProject.property("is-plugin").toBoolean()) {

packages/flutter_tools/templates/module/android/library_new_embedding/Flutter.tmpl/build.gradle.tmpl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,6 @@ android {
4747
}
4848
}
4949

50-
android.buildTypes.all {buildType ->
51-
if (!android.productFlavors.isEmpty()) {
52-
android.productFlavors.all{productFlavor ->
53-
android.publishing.singleVariant(productFlavor.name + buildType.name.capitalize()) {
54-
withSourcesJar()
55-
withJavadocJar()
56-
}
57-
}
58-
} else {
59-
android.publishing.singleVariant(buildType.name) {
60-
withSourcesJar()
61-
withJavadocJar()
62-
}
63-
}
64-
}
6550

6651
flutter {
6752
source = "../.."

0 commit comments

Comments
 (0)