Repository navigation
Commit 9a813a8
authored
[CP-beta][FGP] Report the real error when applying kotlin-android fails (#195691)
This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request)
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.
### Issue Link:
#181557
### Impact Description:
Cherry-pick of #195080 (also tracks #189236 and #180137).
On Flutter 3.50 beta (`flutter-3.50-candidate.0`), when an Android project sets `android.newDsl=true` while `android.builtInKotlin=false`, `FlutterPluginUtils.detectApplyingKotlinGradlePlugin` catches all exceptions from `pluginManager.apply("kotlin-android")`. Instead of surfacing the Kotlin Gradle Plugin's actual incompatibility message (`The 'org.jetbrains.kotlin.android' plugin is not compatible with AGP's 9.0 new DSL` along with instructions to set `android.builtInKotlin=true` or `android.newDsl=false`), Flutter Gradle Plugin prints `"Applying the Kotlin Android Plugin (KGP) was unsuccessful. KGP was not found on the classpath."` and the build fails later with an unrelated script compilation error (`Unresolved reference: kotlin` / `compilerOptions`). Narrowing the catch to `UnknownPluginException` surfaces KGP's real error and remediation guidance to developers adopting AGP 9's new DSL in 3.50.
### Changelog Description:
[flutter/181557](#181557): Android builds with `android.newDsl=true` and `android.builtInKotlin=false` misreport a missing Kotlin Gradle Plugin instead of the actual incompatibility error.
### Workaround:
Set `android.builtInKotlin=true` (after migrating off `org.jetbrains.kotlin.android`) or `android.newDsl=false` in `android/gradle.properties`; however, without this fix the build output misleads developers into debugging a missing KGP classpath dependency instead of the `builtInKotlin`/`newDsl` mismatch.
### Risk:
What is the risk level of this cherry-pick?
### Test Coverage:
Are you confident that your fix is well-tested by automated tests?
### Validation Steps:
1. Create a new Flutter Android app (`flutter create my_app`) using AGP 9.x.
2. Set `android.builtInKotlin=false` and `android.newDsl=true` in `android/gradle.properties`.
3. Run `flutter build apk` and verify that Gradle reports KGP's real error (`The 'org.jetbrains.kotlin.android' plugin is not compatible with AGP's 9.0 new DSL` with remediation steps) instead of `"KGP was not found on the classpath."` (also covered by unit tests in `FlutterPluginUtilsTest.kt`).1 parent 4474c2f commit 9a813a8
2 files changed
Lines changed: 40 additions & 5 deletions
File tree
- packages/flutter_tools/gradle/src
- main/kotlin
- test/kotlin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
583 | 584 | | |
584 | 585 | | |
585 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
586 | 590 | | |
587 | 591 | | |
588 | | - | |
| 592 | + | |
589 | 593 | | |
590 | 594 | | |
591 | 595 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
1818 | 1819 | | |
1819 | 1820 | | |
1820 | 1821 | | |
1821 | | - | |
1822 | | - | |
| 1822 | + | |
| 1823 | + | |
1823 | 1824 | | |
1824 | 1825 | | |
1825 | 1826 | | |
| |||
1837 | 1838 | | |
1838 | 1839 | | |
1839 | 1840 | | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
1840 | 1871 | | |
1841 | 1872 | | |
1842 | 1873 | | |
| |||
1930 | 1961 | | |
1931 | 1962 | | |
1932 | 1963 | | |
1933 | | - | |
1934 | | - | |
| 1964 | + | |
| 1965 | + | |
1935 | 1966 | | |
1936 | 1967 | | |
1937 | 1968 | | |
| |||
0 commit comments