Skip to content

Commit 7d26978

Browse files
jesswrdsuryaKommana2662
authored andcommitted
[tool] Narrow Scope of AGP DSL Flutter Fix Message (flutter#193610)
`useNewAgpDslErrorHandler` matched any line containing "> Failed to apply plugin 'dev.flutter.flutter-gradle-plugin'". Gradle prints that line for every exception thrown while applying the Flutter Gradle plugin, so the android.newDsl Flutter Fix box was also shown for unrelated failures such as unsupported Gradle, Java, AGP, or KGP version errors. The handler now only matches the "> java.lang.NullPointerException (no error message)" line that is specific to the new DSL failure. Also renames the handler's test, which duplicated the kotlin-android test name, and adds matcher tests. Fixes flutter#193865 Related to flutter#193609 Related to 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. - [ ] 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 eaa301e commit 7d26978

2 files changed

Lines changed: 60 additions & 5 deletions

File tree

‎packages/flutter_tools/lib/src/android/gradle_errors.dart‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,15 @@ To resolve this, migrate to built-in Kotlin.
717717
/// Handler when using the new AGP DSL interfaces. Starting AGP 9+, only the new
718718
/// DSL interfaces are used. This results in a failure because we still depend
719719
/// on old DSL types.
720+
///
721+
/// This only matches the `NullPointerException` line. Gradle prints
722+
/// `> Failed to apply plugin 'dev.flutter.flutter-gradle-plugin'` for every
723+
/// exception thrown while applying the Flutter Gradle plugin (for example,
724+
/// unsupported dependency version errors), so matching that line would show
725+
/// this box for unrelated failures.
720726
@visibleForTesting
721727
final useNewAgpDslErrorHandler = GradleHandledError(
722-
test: _lineMatcher(const <String>[
723-
"> Failed to apply plugin 'dev.flutter.flutter-gradle-plugin'",
724-
'> java.lang.NullPointerException (no error message)',
725-
]),
728+
test: _lineMatcher(const <String>['> java.lang.NullPointerException (no error message)']),
726729
handler:
727730
({required String line, required FlutterProject project, required bool usesAndroidX}) async {
728731
final File appGradleFile = project.android.appGradleFile;

‎packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1703,8 +1703,60 @@ An exception occurred applying plugin request [id: 'kotlin-android']
17031703
},
17041704
);
17051705

1706+
group('new AGP DSL error', () {
1707+
const useNewAgpDslErrorExample = r'''
1708+
FAILURE: Build failed with an exception.
1709+
1710+
* Where:
1711+
Build file '/Users/jesswon/Desktop/fresh_flutter_app/android/app/build.gradle.kts'
1712+
1713+
* What went wrong:
1714+
An exception occurred applying plugin request [id: 'dev.flutter.flutter-gradle-plugin']
1715+
> Failed to apply plugin 'dev.flutter.flutter-gradle-plugin'.
1716+
> java.lang.NullPointerException (no error message)
1717+
''';
1718+
1719+
testWithoutContext('matches the new AGP DSL failure', () {
1720+
expect(formatTestErrorMessage(useNewAgpDslErrorExample, useNewAgpDslErrorHandler), isTrue);
1721+
});
1722+
1723+
testWithoutContext('does not match unsupported dependency version errors', () {
1724+
const unsupportedAgpVersionErrorExample = r'''
1725+
FAILURE: Build failed with an exception.
1726+
1727+
* Where:
1728+
Build file '/path/to/my_app/android/app/build.gradle.kts' line: 1
1729+
1730+
* What went wrong:
1731+
An exception occurred applying plugin request [id: 'dev.flutter.flutter-gradle-plugin']
1732+
> Failed to apply plugin 'dev.flutter.flutter-gradle-plugin'.
1733+
> Error: Your project's Android Gradle Plugin version (10.0.0) is not yet supported. Flutter does not support Android Gradle Plugin 10, and support will be added in a future Flutter release. Please downgrade your Android Gradle Plugin version to a version below 10.0.0 to continue.
1734+
Alternatively, use the flag "--android-skip-build-dependency-validation" to bypass this check (unsupported; your build may fail).
1735+
''';
1736+
expect(
1737+
formatTestErrorMessage(unsupportedAgpVersionErrorExample, useNewAgpDslErrorHandler),
1738+
isFalse,
1739+
);
1740+
});
1741+
1742+
testWithoutContext('does not match other errors thrown while applying the plugin', () {
1743+
const minimumGradleVersionErrorExample = r'''
1744+
FAILURE: Build failed with an exception.
1745+
1746+
* What went wrong:
1747+
An exception occurred applying plugin request [id: 'dev.flutter.flutter-gradle-plugin']
1748+
> Failed to apply plugin 'dev.flutter.flutter-gradle-plugin'.
1749+
> Error: Your project's Gradle version (8.13.0) is lower than Flutter's minimum supported version of 8.14.0. Please upgrade your Gradle version.
1750+
''';
1751+
expect(
1752+
formatTestErrorMessage(minimumGradleVersionErrorExample, useNewAgpDslErrorHandler),
1753+
isFalse,
1754+
);
1755+
});
1756+
});
1757+
17061758
testUsingContext(
1707-
'Failure to apply kotlin-android plugin',
1759+
'Failure to apply Flutter Gradle plugin with the new AGP DSL',
17081760
() async {
17091761
const useNewAgpDslErrorHandlerExample = r'''
17101762
FAILURE: Build failed with an exception.

0 commit comments

Comments
 (0)