Skip to content

Commit 421784e

Browse files
jesswrdsuryaKommana2662
authored andcommitted
[AGP 9] Add Unsupported AGP Version Functionality (flutter#193609)
Intentionally break builds that use unsupported (too new) AGP versions. This is in the event AGP releases a new AGP version we do not yet support. Fixes flutter#193593 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [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 in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [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. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [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 [flutter/website]: https://github.com/flutter/website [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
1 parent c114b39 commit 421784e

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

‎packages/flutter_tools/gradle/src/main/kotlin/DependencyVersionChecker.kt‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ object DependencyVersionChecker {
104104

105105
@VisibleForTesting internal val errorAGPVersion: AndroidPluginVersion = AndroidPluginVersion(8, 11, 1)
106106

107+
@VisibleForTesting internal val firstUnsupportedAGPMajorVersion: Int = 10
108+
107109
@VisibleForTesting internal val warnKGPVersion: Version = Version(2, 3, 20)
108110

109111
@VisibleForTesting internal val errorKGPVersion: Version = Version(2, 2, 20)
@@ -214,6 +216,20 @@ object DependencyVersionChecker {
214216
"\nAlternatively, use the flag \"--android-skip-build-dependency-validation\"" +
215217
" to bypass this check.\n\nPotential fix: $potentialFix"
216218

219+
@VisibleForTesting internal fun getFutureUnsupportedMajorVersionErrorMessage(
220+
dependencyName: String,
221+
versionString: String,
222+
unsupportedMajorVersion: Int,
223+
potentialFix: String
224+
): String =
225+
"Error: Your project's $dependencyName version ($versionString) is not yet " +
226+
"supported. Flutter does not support $dependencyName $unsupportedMajorVersion, " +
227+
"and support will be added in a future Flutter release. Please downgrade your " +
228+
"$dependencyName version to a version below $unsupportedMajorVersion.0.0 to " +
229+
"continue.\nAlternatively, use the flag \"--android-skip-build-dependency-validation\"" +
230+
" to bypass this check (unsupported; your build may fail).\n\n" +
231+
"Potential fix: $potentialFix"
232+
217233
@VisibleForTesting
218234
internal fun getFlavorSpecificMessage(
219235
flavorName: String?,
@@ -276,6 +292,17 @@ object DependencyVersionChecker {
276292
androidPluginVersion: AndroidPluginVersion,
277293
project: Project
278294
) {
295+
if (androidPluginVersion.major >= firstUnsupportedAGPMajorVersion) {
296+
val errorMessage: String =
297+
getFutureUnsupportedMajorVersionErrorMessage(
298+
AGP_NAME,
299+
"${androidPluginVersion.major}.${androidPluginVersion.minor}.${androidPluginVersion.micro}",
300+
firstUnsupportedAGPMajorVersion,
301+
getPotentialAGPFix(project.rootDir.path)
302+
)
303+
project.extra.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
304+
throw DependencyValidationException(errorMessage)
305+
}
279306
if (androidPluginVersion < errorAGPVersion) {
280307
val errorMessage: String =
281308
getErrorMessage(

‎packages/flutter_tools/gradle/src/test/kotlin/DependencyVersionCheckerTest.kt‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import com.flutter.gradle.DependencyVersionChecker.errorGradleVersion
1919
import com.flutter.gradle.DependencyVersionChecker.errorJavaVersion
2020
import com.flutter.gradle.DependencyVersionChecker.errorKGPVersion
2121
import com.flutter.gradle.DependencyVersionChecker.errorMinSdkVersion
22+
import com.flutter.gradle.DependencyVersionChecker.firstUnsupportedAGPMajorVersion
2223
import com.flutter.gradle.DependencyVersionChecker.getErrorMessage
2324
import com.flutter.gradle.DependencyVersionChecker.getFlavorSpecificMessage
25+
import com.flutter.gradle.DependencyVersionChecker.getFutureUnsupportedMajorVersionErrorMessage
2426
import com.flutter.gradle.DependencyVersionChecker.getPotentialAGPFix
2527
import com.flutter.gradle.DependencyVersionChecker.getPotentialGradleFix
2628
import com.flutter.gradle.DependencyVersionChecker.getPotentialKGPFix
@@ -125,6 +127,69 @@ class DependencyVersionCheckerTest {
125127
verify(exactly = 0) { mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true) }
126128
}
127129

130+
@Test
131+
fun `AGP version with unsupported major version results in DependencyValidationException`() {
132+
val exampleUnsupportedAgpVersion = AndroidPluginVersion(firstUnsupportedAGPMajorVersion, 0, 0)
133+
val mockProject =
134+
MockProjectFactory.createMockProjectWithSpecifiedDependencyVersions(agpVersion = exampleUnsupportedAgpVersion)
135+
136+
val mockExtraPropertiesExtension = mockProject.extra
137+
every { mockExtraPropertiesExtension.set(any(), any()) } returns Unit
138+
139+
val dependencyValidationException =
140+
assertFailsWith<DependencyValidationException> { DependencyVersionChecker.checkDependencyVersions(mockProject) }
141+
assertEquals(
142+
getFutureUnsupportedMajorVersionErrorMessage(
143+
AGP_NAME,
144+
"$firstUnsupportedAGPMajorVersion.0.0",
145+
firstUnsupportedAGPMajorVersion,
146+
getPotentialAGPFix(FAKE_PROJECT_ROOT_DIR)
147+
),
148+
dependencyValidationException.message
149+
)
150+
verify { mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true) }
151+
}
152+
153+
@Test
154+
fun `AGP version above unsupported major version results in DependencyValidationException`() {
155+
val exampleUnsupportedAgpVersion = AndroidPluginVersion(firstUnsupportedAGPMajorVersion, 3, 1)
156+
val mockProject =
157+
MockProjectFactory.createMockProjectWithSpecifiedDependencyVersions(agpVersion = exampleUnsupportedAgpVersion)
158+
159+
val mockExtraPropertiesExtension = mockProject.extra
160+
every { mockExtraPropertiesExtension.set(any(), any()) } returns Unit
161+
162+
val dependencyValidationException =
163+
assertFailsWith<DependencyValidationException> { DependencyVersionChecker.checkDependencyVersions(mockProject) }
164+
assertEquals(
165+
getFutureUnsupportedMajorVersionErrorMessage(
166+
AGP_NAME,
167+
"$firstUnsupportedAGPMajorVersion.3.1",
168+
firstUnsupportedAGPMajorVersion,
169+
getPotentialAGPFix(FAKE_PROJECT_ROOT_DIR)
170+
),
171+
dependencyValidationException.message
172+
)
173+
verify { mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true) }
174+
}
175+
176+
@Test
177+
fun `AGP version below unsupported major version is considered supported`() {
178+
val exampleSupportedAgpVersion = AndroidPluginVersion(firstUnsupportedAGPMajorVersion - 1, 99, 99)
179+
val mockProject =
180+
MockProjectFactory.createMockProjectWithSpecifiedDependencyVersions(agpVersion = exampleSupportedAgpVersion)
181+
182+
val mockExtraPropertiesExtension = mockProject.extra
183+
every { mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, false) } returns Unit
184+
val mockLogger = mockProject.logger
185+
every { mockLogger.error(any()) } returns Unit
186+
187+
DependencyVersionChecker.checkDependencyVersions(mockProject)
188+
189+
verify(exactly = 0) { mockLogger.error(any()) }
190+
verify(exactly = 0) { mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true) }
191+
}
192+
128193
@Test
129194
fun `KGP version in error range results in DependencyValidationException`() {
130195
val exampleErrorKgpVersion = "2.0.0"

‎packages/flutter_tools/lib/src/android/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ information known to the tool.
9999
be marked inline).
100100
- Update the test cases in [create_test.dart](../../../test/commands.shard/permeable/create_test.dart) that test for a warning for Java/AGP incompatibilities as needed
101101
(relevant tests should fail if you do not fix them preemptively).
102+
- When Flutter adds support for a new AGP major version, bump
103+
`firstUnsupportedAGPMajorVersion` in
104+
[DependencyVersionChecker.kt](../../../gradle/src/main/kotlin/DependencyVersionChecker.kt)
105+
so that builds using that major version are no longer blocked.
102106

103107
For information about the latest version, check https://developer.android.com/studio/releases/gradle-plugin#updating-gradle.
104108

0 commit comments

Comments
 (0)