Fix flutter create warning regarding Java compatibility (#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 #152460
This commit is contained in:
Shashwat Pathak
2024-09-11 21:51:16 +05:30
committed by GitHub
parent d565781992
commit 0a9148870a
2 changed files with 26 additions and 13 deletions

View File

@@ -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=<JDK_DIRECTORY>`
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=<JDK_DIRECTORY>
''';
}

View File

@@ -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<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--no-pub', '--platforms=android', projectDir.path]);
final String expectedMessage = getIncompatibleJavaGradleAgpMessageHeader(false, templateDefaultGradleVersion, templateAndroidGradlePluginVersion, 'app');
expect(logger.warningText, contains(expectedMessage));
}, overrides: <Type, Generator>{
Java: () => FakeJava(version: const software.Version.withText(500, 0, 0, '500.0.0')), // Too high a version for template Gradle versions.
Logger: () => logger,
});
}
Future<void> _createProject(