diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index 9b21bbb7f7..992c6914b7 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -959,19 +959,17 @@ used. // AGP template version incompatible with Java version. final gradle.JavaAgpCompat? minimumCompatibleAgpVersion = gradle.getMinimumAgpVersionForJavaVersion(globals.logger, javaV: javaVersion); final String compatibleAgpVersionMessage = minimumCompatibleAgpVersion == null ? '' : ' (minimum compatible AGP version: ${minimumCompatibleAgpVersion.agpMin})'; - final String gradleBuildFilePaths = ' - ${_getBuildGradleConfigurationFilePaths(projectType, projectDirPath)!.join('\n - ')}'; + final String gradleBuildFilePaths = ' ${_getBuildGradleConfigurationFilePaths(projectType, projectDirPath)!.join('\n - ')}'; globals.printWarning(''' $incompatibleVersionsAndRecommendedOptionMessage -Alternatively, to continue using your configured Java version, update the AGP -version specified in the following files to a compatible AGP -version$compatibleAgpVersionMessage as necessary: +Alternatively, to continue using your current Java version, update the AGP +version in the following file(s) to a compatible version$compatibleAgpVersionMessage: $gradleBuildFilePaths -See -https://developer.android.com/build/releases/gradle-plugin for details on -compatible Java/AGP versions. +For details on compatible Java and AGP versions, see +https://developer.android.com/build/releases/gradle-plugin ''', emphasis: true ); @@ -994,12 +992,11 @@ String getIncompatibleJavaGradleAgpMessageHeader( return ''' The configured version of Java detected may conflict with the $incompatibleDependency version in your new Flutter $projectType. -[RECOMMENDED] If so, to keep the default $incompatibleDependencyVersion, make -sure to download a compatible Java version -$validJavaRangeMessage. -You may configure this compatible Java version by running: -`flutter config --jdk-dir=` -Note that this is a global configuration for Flutter. +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: + + 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 aa0a1ff115..1c5408fd0d 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart @@ -3926,6 +3926,22 @@ void main() { ), ProcessManager: () => fakeProcessManager, }); + + testUsingContext('flutter create should show the incompatible java AGP message', () async { + Cache.flutterRoot = '../..'; + + final CreateCommand command = CreateCommand(); + final CommandRunner runner = createTestCommandRunner(command); + + await runner.run(['create', '--no-pub', '--platforms=android', projectDir.path]); + + final String expectedMessage = getIncompatibleJavaGradleAgpMessageHeader(false, templateDefaultGradleVersion, templateAndroidGradlePluginVersion, 'app'); + + expect(logger.warningText, contains(expectedMessage)); + }, overrides: { + Java: () => FakeJava(version: const software.Version.withText(500, 0, 0, '500.0.0')), // Too high a version for template Gradle versions. + Logger: () => logger, + }); } Future _createProject(