Skip to content

Commit 05bb83a

Browse files
wratheusAleksandr PavlenkoAleksandr P.
authored
Skip KGP version validation for AGP built-in Kotlin (flutter#192206)
Fixes flutter#192167. ## Summary When `android.builtInKotlin=true`, Kotlin is bundled with AGP and cannot be upgraded independently. This change skips Flutter's KGP minimum-version validation for projects using AGP built-in Kotlin. ## Tests - Added a regression test for an unsupported KGP version with `android.builtInKotlin=true`. - `./gradlew test --tests 'com.flutter.gradle.DependencyVersionCheckerTest'` ## 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. - [x] I read the Tree Hygiene wiki page, which explains my responsibilities. - [x] I read and followed the Flutter Style Guide. - [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, or verified that none is needed for this internal validation change. - [x] This PR does not introduce a new feature or capability; no `flutter/website` documentation issue or PR is needed. - [x] I added new tests to check the change I am making. - [x] This is not a breaking change and does not require Data Driven Fixes. - [x] The relevant existing and new tests are passing. --------- Co-authored-by: Aleksandr Pavlenko <[email protected]> Co-authored-by: Aleksandr P. <[email protected]>
1 parent b444e78 commit 05bb83a

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,14 @@ object DependencyVersionChecker {
140140
}
141141

142142
val kgpVersion: Version? = VersionFetcher.getKGPVersion(project)
143-
if (kgpVersion != null) {
143+
val usesBuiltInKotlin = FlutterPluginUtils.isBuiltInKotlinEnabled(project, agpVersion)
144+
145+
if (kgpVersion != null && !usesBuiltInKotlin) {
144146
checkKGPVersion(kgpVersion, project)
145147
} else {
146148
project.logger.debug(
147-
"Unable to detect project Kotlin Gradle Plugin version. Skipping Kotlin min-version enforcement. " +
148-
"This is expected if the project uses AGP built-in Kotlin (android.builtInKotlin) or does not apply KGP."
149+
"Skipping Kotlin min-version enforcement because the project uses " +
150+
"AGP built-in Kotlin or does not apply KGP."
149151
)
150152
}
151153
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import org.gradle.api.Project
4141
import org.gradle.api.Task
4242
import org.gradle.api.logging.Logger
4343
import org.gradle.api.plugins.ExtraPropertiesExtension
44+
import org.gradle.api.provider.Provider
45+
import org.gradle.api.provider.ProviderFactory
4446
import org.gradle.api.tasks.TaskContainer
4547
import org.gradle.internal.extensions.core.extra
4648
import kotlin.test.Test
@@ -171,6 +173,30 @@ class DependencyVersionCheckerTest {
171173
verify(exactly = 0) { mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true) }
172174
}
173175

176+
@Test
177+
fun `AGP 9 built-in Kotlin skips KGP min version enforcement by default`() {
178+
val mockProject =
179+
MockProjectFactory.createMockProjectWithSpecifiedDependencyVersions(
180+
kgpVersion = "2.2.10",
181+
builtInKotlinProperty = null
182+
)
183+
184+
val mockExtraPropertiesExtension = mockProject.extra
185+
every { mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, false) } returns Unit
186+
val mockLogger = mockProject.logger
187+
every { mockLogger.debug(any()) } returns Unit
188+
189+
DependencyVersionChecker.checkDependencyVersions(mockProject)
190+
191+
verify {
192+
mockLogger.debug(
193+
"Skipping Kotlin min-version enforcement because the project uses " +
194+
"AGP built-in Kotlin or does not apply KGP."
195+
)
196+
}
197+
verify(exactly = 0) { mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true) }
198+
}
199+
174200
// No test for Java version in warn range, as the lowest supported Java version is also the
175201
// lowest possible.
176202
@Test
@@ -422,6 +448,7 @@ private object MockProjectFactory {
422448
gradleVersion: String = SUPPORTED_GRADLE_VERSION,
423449
agpVersion: AndroidPluginVersion = SUPPORTED_AGP_VERSION,
424450
kgpVersion: String = SUPPORTED_KGP_VERSION,
451+
builtInKotlinProperty: String? = "false",
425452
minSdkVersions: List<MinSdkVersion> = listOf(SUPPORTED_SDK_VERSION)
426453
): Project {
427454
// Java
@@ -440,6 +467,11 @@ private object MockProjectFactory {
440467
// KGP
441468
every { mockProject.hasProperty(eq("kotlin_version")) } returns true
442469
every { mockProject.properties["kotlin_version"] } returns kgpVersion
470+
val mockBuiltInKotlinProperty = mockk<Provider<String>>()
471+
every { mockBuiltInKotlinProperty.orNull } returns builtInKotlinProperty
472+
val mockProviders = mockk<ProviderFactory>()
473+
every { mockProviders.gradleProperty("android.builtInKotlin") } returns mockBuiltInKotlinProperty
474+
every { mockProject.providers } returns mockProviders
443475

444476
// Logger
445477
val mockLogger = mockk<Logger>()

0 commit comments

Comments
 (0)