Skip to content

Commit 0a91488

Browse files
Fix flutter create warning regarding Java compatibility (flutter#152836)
This PR modifies the warning message regarding Java compatibility to make it consistent with the Flutter style guide. **Current message looks like this** ``` [RECOMMENDED] If so, to keep the default AGP version 8.1.0, make sure to download a compatible Java version (Java 17 <= compatible Java version < Java 21). You may configure this compatible Java version by running: `flutter config --jdk-dir=<JDK_DIRECTORY>` Note that this is a global configuration for Flutter. Alternatively, to continue using your configured Java version, update the AGP version specified in the following files to a compatible AGP version (minimum compatible AGP version: 7.0) as necessary: - /home/user/project/testproj/android/build.gradle See https://developer.android.com/build/releases/gradle-plugin for details on compatible Java/AGP versions. ``` **After Modification** ``` To keep the default AGP version 8.1.0, download a compatible Java version (Java 17 <= compatible Java version < Java 21). Configure this Java version globally for Flutter by running: flutter config --jdk-dir=<JDK_DIRECTORY> Alternatively, to continue using your current Java version, update the AGP version in the following file(s) to a compatible version (minimum AGP version: 7.0): /home/user/project/testproj/android/build.gradle For details on compatible Java and AGP versions, see https://developer.android.com/build/releases/gradle-plugin ``` Fixes flutter#152460
1 parent d565781 commit 0a91488

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

packages/flutter_tools/lib/src/commands/create.dart

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -959,19 +959,17 @@ used.
959959
// AGP template version incompatible with Java version.
960960
final gradle.JavaAgpCompat? minimumCompatibleAgpVersion = gradle.getMinimumAgpVersionForJavaVersion(globals.logger, javaV: javaVersion);
961961
final String compatibleAgpVersionMessage = minimumCompatibleAgpVersion == null ? '' : ' (minimum compatible AGP version: ${minimumCompatibleAgpVersion.agpMin})';
962-
final String gradleBuildFilePaths = ' - ${_getBuildGradleConfigurationFilePaths(projectType, projectDirPath)!.join('\n - ')}';
962+
final String gradleBuildFilePaths = ' ${_getBuildGradleConfigurationFilePaths(projectType, projectDirPath)!.join('\n - ')}';
963963

964964
globals.printWarning('''
965965
$incompatibleVersionsAndRecommendedOptionMessage
966966
967-
Alternatively, to continue using your configured Java version, update the AGP
968-
version specified in the following files to a compatible AGP
969-
version$compatibleAgpVersionMessage as necessary:
967+
Alternatively, to continue using your current Java version, update the AGP
968+
version in the following file(s) to a compatible version$compatibleAgpVersionMessage:
970969
$gradleBuildFilePaths
971970
972-
See
973-
https://developer.android.com/build/releases/gradle-plugin for details on
974-
compatible Java/AGP versions.
971+
For details on compatible Java and AGP versions, see
972+
https://developer.android.com/build/releases/gradle-plugin
975973
''',
976974
emphasis: true
977975
);
@@ -994,12 +992,11 @@ String getIncompatibleJavaGradleAgpMessageHeader(
994992
return '''
995993
The configured version of Java detected may conflict with the $incompatibleDependency version in your new Flutter $projectType.
996994
997-
[RECOMMENDED] If so, to keep the default $incompatibleDependencyVersion, make
998-
sure to download a compatible Java version
999-
$validJavaRangeMessage.
1000-
You may configure this compatible Java version by running:
1001-
`flutter config --jdk-dir=<JDK_DIRECTORY>`
1002-
Note that this is a global configuration for Flutter.
995+
To keep the default AGP version $incompatibleDependencyVersion, download a compatible Java version
996+
(Java 17 <= $validJavaRangeMessage Java version < Java 21). Configure this Java version
997+
globally for Flutter by running:
998+
999+
flutter config --jdk-dir=<JDK_DIRECTORY>
10031000
''';
10041001
}
10051002

packages/flutter_tools/test/commands.shard/permeable/create_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3926,6 +3926,22 @@ void main() {
39263926
),
39273927
ProcessManager: () => fakeProcessManager,
39283928
});
3929+
3930+
testUsingContext('flutter create should show the incompatible java AGP message', () async {
3931+
Cache.flutterRoot = '../..';
3932+
3933+
final CreateCommand command = CreateCommand();
3934+
final CommandRunner<void> runner = createTestCommandRunner(command);
3935+
3936+
await runner.run(<String>['create', '--no-pub', '--platforms=android', projectDir.path]);
3937+
3938+
final String expectedMessage = getIncompatibleJavaGradleAgpMessageHeader(false, templateDefaultGradleVersion, templateAndroidGradlePluginVersion, 'app');
3939+
3940+
expect(logger.warningText, contains(expectedMessage));
3941+
}, overrides: <Type, Generator>{
3942+
Java: () => FakeJava(version: const software.Version.withText(500, 0, 0, '500.0.0')), // Too high a version for template Gradle versions.
3943+
Logger: () => logger,
3944+
});
39293945
}
39303946

39313947
Future<void> _createProject(

0 commit comments

Comments
 (0)