From c5e5e0cc36fb01fffbafa313aa194115935b7c56 Mon Sep 17 00:00:00 2001 From: Satyam Srivastav <83233310+D-extremity@users.noreply.github.com> Date: Wed, 12 Jun 2024 10:42:57 +0530 Subject: [PATCH] closes #issue136763, changed a command to generate gradle error message according to platform (#149877) Currently, the error message displayed to regenerate the lockfiles gives a Unix-like command ./gradlew, which will be incorrect for Windows environments. This PR uses globals.platform.isWindows to give the appropriate command. closes #136763 --- .../lib/src/android/gradle_errors.dart | 3 +- .../android/gradle_errors_test.dart | 51 ++++++++++++++++++- 2 files changed, 51 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 97e1ce89fd..a5db3ad039 100644 --- a/packages/flutter_tools/lib/src/android/gradle_errors.dart +++ b/packages/flutter_tools/lib/src/android/gradle_errors.dart @@ -414,8 +414,9 @@ final GradleHandledError lockFileDepMissingHandler = GradleHandledError( final File gradleFile = project.directory .childDirectory('android') .childFile('build.gradle'); + final String generatedGradleCommand = globals.platform.isWindows ? r'.\gradlew.bat' : './gradlew'; final String textInBold = globals.logger.terminal.bolden( - 'To regenerate the lockfiles run: `./gradlew :generateLockfiles` in ${gradleFile.path}\n' + 'To regenerate the lockfiles run: `$generatedGradleCommand :generateLockfiles` in ${gradleFile.path}\n' 'To remove dependency locking, remove the `dependencyLocking` from ${gradleFile.path}' ); globals.printBox( 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 ba1fe95b4a..9d832fac4e 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 @@ -782,8 +782,7 @@ Execution failed for task ':app:generateDebugFeatureTransitiveDeps'. '│ To regenerate the lockfiles run: `./gradlew :generateLockfiles` in /android/build.gradle │\n' '│ To remove dependency locking, remove the `dependencyLocking` from /android/build.gradle │\n' '└──────────────────────────────────────────────────────────────────────────────────────────┘\n' - ) - ); + )); }, overrides: { GradleUtils: () => FakeGradleUtils(), Platform: () => fakePlatform('android'), @@ -792,6 +791,54 @@ Execution failed for task ':app:generateDebugFeatureTransitiveDeps'. }); }); + testUsingContext('generates correct gradle command for Unix-like environment', + () async { + await lockFileDepMissingHandler.handler( + project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), + usesAndroidX: true, + line: '', + ); + + expect( + testLogger.statusText, + contains('\n' + '┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────┐\n' + '│ You need to update the lockfile, or disable Gradle dependency locking. │\n' + '│ To regenerate the lockfiles run: `./gradlew :generateLockfiles` in /android/build.gradle │\n' + '│ To remove dependency locking, remove the `dependencyLocking` from /android/build.gradle │\n' + '└──────────────────────────────────────────────────────────────────────────────────────────┘\n' + '')); + }, overrides: { + GradleUtils: () => FakeGradleUtils(), + Platform: () => fakePlatform('linux'), + FileSystem: () => fileSystem, + ProcessManager: () => processManager, + }); + + + testUsingContext('generates correct gradle command for windows environment', + () async { + await lockFileDepMissingHandler.handler( + project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), + usesAndroidX: true, + line: '', + ); + expect( + testLogger.statusText, + contains('\n' + '┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────┐\n' + '│ You need to update the lockfile, or disable Gradle dependency locking. │\n' + '│ To regenerate the lockfiles run: `.\\gradlew.bat :generateLockfiles` in /android/build.gradle │\n' + '│ To remove dependency locking, remove the `dependencyLocking` from /android/build.gradle │\n' + '└──────────────────────────────────────────────────────────────────────────────────────────────┘\n' + '')); + }, overrides: { + GradleUtils: () => FakeGradleUtils(), + Platform: () => fakePlatform('windows'), + FileSystem: () => fileSystem, + ProcessManager: () => processManager, + }); + group('Incompatible Kotlin version', () { testWithoutContext('pattern', () { expect(