Skip to content

Commit 3c0fdcb

Browse files
D-extremitypull[bot]
authored andcommitted
closes #issue136763, changed a command to generate gradle error message according to platform (flutter#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 flutter#136763
1 parent 16461aa commit 3c0fdcb

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,9 @@ final GradleHandledError lockFileDepMissingHandler = GradleHandledError(
414414
final File gradleFile = project.directory
415415
.childDirectory('android')
416416
.childFile('build.gradle');
417+
final String generatedGradleCommand = globals.platform.isWindows ? r'.\gradlew.bat' : './gradlew';
417418
final String textInBold = globals.logger.terminal.bolden(
418-
'To regenerate the lockfiles run: `./gradlew :generateLockfiles` in ${gradleFile.path}\n'
419+
'To regenerate the lockfiles run: `$generatedGradleCommand :generateLockfiles` in ${gradleFile.path}\n'
419420
'To remove dependency locking, remove the `dependencyLocking` from ${gradleFile.path}'
420421
);
421422
globals.printBox(

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

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,7 @@ Execution failed for task ':app:generateDebugFeatureTransitiveDeps'.
782782
'│ To regenerate the lockfiles run: `./gradlew :generateLockfiles` in /android/build.gradle │\n'
783783
'│ To remove dependency locking, remove the `dependencyLocking` from /android/build.gradle │\n'
784784
'└──────────────────────────────────────────────────────────────────────────────────────────┘\n'
785-
)
786-
);
785+
));
787786
}, overrides: <Type, Generator>{
788787
GradleUtils: () => FakeGradleUtils(),
789788
Platform: () => fakePlatform('android'),
@@ -792,6 +791,54 @@ Execution failed for task ':app:generateDebugFeatureTransitiveDeps'.
792791
});
793792
});
794793

794+
testUsingContext('generates correct gradle command for Unix-like environment',
795+
() async {
796+
await lockFileDepMissingHandler.handler(
797+
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
798+
usesAndroidX: true,
799+
line: '',
800+
);
801+
802+
expect(
803+
testLogger.statusText,
804+
contains('\n'
805+
'┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────┐\n'
806+
'│ You need to update the lockfile, or disable Gradle dependency locking. │\n'
807+
'│ To regenerate the lockfiles run: `./gradlew :generateLockfiles` in /android/build.gradle │\n'
808+
'│ To remove dependency locking, remove the `dependencyLocking` from /android/build.gradle │\n'
809+
'└──────────────────────────────────────────────────────────────────────────────────────────┘\n'
810+
''));
811+
}, overrides: <Type, Generator>{
812+
GradleUtils: () => FakeGradleUtils(),
813+
Platform: () => fakePlatform('linux'),
814+
FileSystem: () => fileSystem,
815+
ProcessManager: () => processManager,
816+
});
817+
818+
819+
testUsingContext('generates correct gradle command for windows environment',
820+
() async {
821+
await lockFileDepMissingHandler.handler(
822+
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
823+
usesAndroidX: true,
824+
line: '',
825+
);
826+
expect(
827+
testLogger.statusText,
828+
contains('\n'
829+
'┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────┐\n'
830+
'│ You need to update the lockfile, or disable Gradle dependency locking. │\n'
831+
'│ To regenerate the lockfiles run: `.\\gradlew.bat :generateLockfiles` in /android/build.gradle │\n'
832+
'│ To remove dependency locking, remove the `dependencyLocking` from /android/build.gradle │\n'
833+
'└──────────────────────────────────────────────────────────────────────────────────────────────┘\n'
834+
''));
835+
}, overrides: <Type, Generator>{
836+
GradleUtils: () => FakeGradleUtils(),
837+
Platform: () => fakePlatform('windows'),
838+
FileSystem: () => fileSystem,
839+
ProcessManager: () => processManager,
840+
});
841+
795842
group('Incompatible Kotlin version', () {
796843
testWithoutContext('pattern', () {
797844
expect(

0 commit comments

Comments
 (0)