Skip to content

Commit 969a875

Browse files
authored
Provide more information in 'unsupported class file' gradle error (#136756)
Fixes flutter/flutter#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 flutter/flutter#131354, because I think it is a bad idea to introduce branching in how we handle this error with some specialized regexp.
1 parent 474a856 commit 969a875

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

packages/flutter_tools/lib/src/android/gradle_errors.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,24 @@ final GradleHandledError incompatibleJavaAndGradleVersionsHandler = GradleHandle
685685
required bool usesAndroidX,
686686
required bool multidexEnabled,
687687
}) async {
688+
final File gradlePropertiesFile = project.directory
689+
.childDirectory('android')
690+
.childDirectory('gradle')
691+
.childDirectory('wrapper')
692+
.childFile('gradle-wrapper.properties');
688693
// TODO(reidbaker): Replace URL with constant defined in
689694
// https://github.com/flutter/flutter/pull/123916.
690695
globals.printBox(
691696
"${globals.logger.terminal.warningMark} Your project's Gradle version "
692-
'is incompatible with the Java version that Flutter is using for Gradle.\n\n'
693-
'To fix this issue, consult the migration guide at docs.flutter.dev/go/android-java-gradle-error.',
697+
'is incompatible with the Java version that Flutter is using for Gradle.\n\n'
698+
'If you recently upgraded Android Studio, consult the migration guide '
699+
'at docs.flutter.dev/go/android-java-gradle-error.\n\n'
700+
'Otherwise, to fix this issue, first, check the Java version used by Flutter by '
701+
'running `flutter doctor --verbose`.\n\n'
702+
'Then, update the Gradle version specified in ${gradlePropertiesFile.path} '
703+
'to be compatible with that Java version. '
704+
'See the link below for more information on compatible Java/Gradle versions:\n'
705+
'https://docs.gradle.org/current/userguide/compatibility.html#java\n\n',
694706
title: _boxTitle,
695707
);
696708
return GradleBuildStatus.exit;

packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,9 +1376,12 @@ Could not compile build file '…/example/android/build.gradle'.
13761376
multidexEnabled: true,
13771377
);
13781378

1379-
// Ensure the error notes the incompatible Gradle/AGP/Java versions and links to related resources.
1379+
// Ensure the error notes the incompatible Gradle/AGP/Java versions, links to related resources,
1380+
// and a portion of the path to where to change their gradle version.
13801381
expect(testLogger.statusText, contains('Gradle version is incompatible with the Java version'));
13811382
expect(testLogger.statusText, contains('docs.flutter.dev/go/android-java-gradle-error'));
1383+
expect(testLogger.statusText, contains('gradle-wrapper.properties'));
1384+
expect(testLogger.statusText, contains('https://docs.gradle.org/current/userguide/compatibility.html#java'));
13821385
}, overrides: <Type, Generator>{
13831386
GradleUtils: () => FakeGradleUtils(),
13841387
Platform: () => fakePlatform('android'),

0 commit comments

Comments
 (0)