From 969a8750a58072997742bbbf1c73debe60e6a5b7 Mon Sep 17 00:00:00 2001 From: Gray Mackall <34871572+gmackall@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:14:56 -0700 Subject: [PATCH] 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. --- .../lib/src/android/gradle_errors.dart | 16 ++++++++++++++-- .../android/gradle_errors_test.dart | 5 ++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/android/gradle_errors.dart b/packages/flutter_tools/lib/src/android/gradle_errors.dart index 4044baab66..cedf2202ef 100644 --- a/packages/flutter_tools/lib/src/android/gradle_errors.dart +++ b/packages/flutter_tools/lib/src/android/gradle_errors.dart @@ -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; diff --git a/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart index 28cdf71e6f..4bd3d1af20 100644 --- a/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart +++ b/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart @@ -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: { GradleUtils: () => FakeGradleUtils(), Platform: () => fakePlatform('android'),