Provide more information in 'unsupported class file' gradle error (#136756)
Fixes https://github.com/flutter/flutter/issues/130808. Short context is that the migration guide doesn't help when a user has a newer java version than 17, and this tells them how to fix the error in that situation. This is an alternative to https://github.com/flutter/flutter/pull/131354, because I think it is a bad idea to introduce branching in how we handle this error with some specialized regexp.
This commit is contained in:
@@ -685,12 +685,24 @@ final GradleHandledError incompatibleJavaAndGradleVersionsHandler = GradleHandle
|
||||
required bool usesAndroidX,
|
||||
required bool multidexEnabled,
|
||||
}) async {
|
||||
final File gradlePropertiesFile = project.directory
|
||||
.childDirectory('android')
|
||||
.childDirectory('gradle')
|
||||
.childDirectory('wrapper')
|
||||
.childFile('gradle-wrapper.properties');
|
||||
// TODO(reidbaker): Replace URL with constant defined in
|
||||
// https://github.com/flutter/flutter/pull/123916.
|
||||
globals.printBox(
|
||||
"${globals.logger.terminal.warningMark} Your project's Gradle version "
|
||||
'is incompatible with the Java version that Flutter is using for Gradle.\n\n'
|
||||
'To fix this issue, consult the migration guide at docs.flutter.dev/go/android-java-gradle-error.',
|
||||
'is incompatible with the Java version that Flutter is using for Gradle.\n\n'
|
||||
'If you recently upgraded Android Studio, consult the migration guide '
|
||||
'at docs.flutter.dev/go/android-java-gradle-error.\n\n'
|
||||
'Otherwise, to fix this issue, first, check the Java version used by Flutter by '
|
||||
'running `flutter doctor --verbose`.\n\n'
|
||||
'Then, update the Gradle version specified in ${gradlePropertiesFile.path} '
|
||||
'to be compatible with that Java version. '
|
||||
'See the link below for more information on compatible Java/Gradle versions:\n'
|
||||
'https://docs.gradle.org/current/userguide/compatibility.html#java\n\n',
|
||||
title: _boxTitle,
|
||||
);
|
||||
return GradleBuildStatus.exit;
|
||||
|
||||
@@ -1376,9 +1376,12 @@ Could not compile build file '…/example/android/build.gradle'.
|
||||
multidexEnabled: true,
|
||||
);
|
||||
|
||||
// Ensure the error notes the incompatible Gradle/AGP/Java versions and links to related resources.
|
||||
// Ensure the error notes the incompatible Gradle/AGP/Java versions, links to related resources,
|
||||
// and a portion of the path to where to change their gradle version.
|
||||
expect(testLogger.statusText, contains('Gradle version is incompatible with the Java version'));
|
||||
expect(testLogger.statusText, contains('docs.flutter.dev/go/android-java-gradle-error'));
|
||||
expect(testLogger.statusText, contains('gradle-wrapper.properties'));
|
||||
expect(testLogger.statusText, contains('https://docs.gradle.org/current/userguide/compatibility.html#java'));
|
||||
}, overrides: <Type, Generator>{
|
||||
GradleUtils: () => FakeGradleUtils(),
|
||||
Platform: () => fakePlatform('android'),
|
||||
|
||||
Reference in New Issue
Block a user