From 01fc23238e9a9bae6983f3b6ae1f9df95d1a1fe7 Mon Sep 17 00:00:00 2001 From: Kishan Dhankecha Date: Tue, 14 Jan 2025 02:05:16 +0530 Subject: [PATCH] Fixed repeated strings for incompatible Gradle or AGP version in `create` command (#161223) Fixed the repeated string which shows the compatible Java version in the create command. image ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [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 documentation (doc comments with `///`). - [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. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [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 [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 --- .../lib/src/commands/create.dart | 5 +-- .../commands.shard/permeable/create_test.dart | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index f3193af08ed..fd90ef3e5b1 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -1155,9 +1155,8 @@ String getIncompatibleJavaGradleAgpMessageHeader( return ''' The configured version of Java detected may conflict with the $incompatibleDependency version in your new Flutter $projectType. -To keep the default AGP version $incompatibleDependencyVersion, download a compatible Java version -(Java 17 <= $validJavaRangeMessage Java version < Java 21). Configure this Java version -globally for Flutter by running: +To keep the default $incompatibleDependencyVersion, download a compatible Java version +$validJavaRangeMessage. Configure this Java version globally for Flutter by running: flutter config --jdk-dir= '''; diff --git a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart index 55178c75041..d6c6864158c 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart @@ -4457,6 +4457,44 @@ void main() { overrides: {Java: () => null, Logger: () => logger}, ); + testUsingContext('should return correct warning for incompatible Gradle versions', () async { + const String projectType = 'app'; + final String gradleConflict = getIncompatibleJavaGradleAgpMessageHeader( + false, + templateDefaultGradleVersion, + templateAndroidGradlePluginVersion, + projectType, + ); + + expect( + gradleConflict, + contains(''' +The configured version of Java detected may conflict with the Gradle version in your new Flutter $projectType. + +To keep the default Gradle version $templateDefaultGradleVersion, download a compatible Java version +'''), + ); + }); + + testUsingContext('should return correct warning for incompatible AGP versions', () async { + const String projectType = 'app'; + final String agpConflict = getIncompatibleJavaGradleAgpMessageHeader( + true, + templateDefaultGradleVersion, + templateAndroidGradlePluginVersion, + projectType, + ); + + expect( + agpConflict, + contains(''' +The configured version of Java detected may conflict with the Android Gradle Plugin (AGP) version in your new Flutter $projectType. + +To keep the default AGP version $templateAndroidGradlePluginVersion, download a compatible Java version +'''), + ); + }); + testUsingContext( 'should not show warning for incompatible Java/template Gradle versions when created project type is irrelevant', () async {