Show custom error message when Kotlin or Gradle bump is required (#102421)
This commit is contained in:
parent
e8f8a82a7b
commit
0052566c7e
@ -12,6 +12,7 @@ import '../globals.dart' as globals;
|
|||||||
import '../project.dart';
|
import '../project.dart';
|
||||||
import '../reporting/reporting.dart';
|
import '../reporting/reporting.dart';
|
||||||
import 'android_studio.dart';
|
import 'android_studio.dart';
|
||||||
|
import 'gradle_utils.dart';
|
||||||
import 'multidex.dart';
|
import 'multidex.dart';
|
||||||
|
|
||||||
typedef GradleErrorTest = bool Function(String);
|
typedef GradleErrorTest = bool Function(String);
|
||||||
@ -78,6 +79,7 @@ final List<GradleHandledError> gradleErrors = <GradleHandledError>[
|
|||||||
incompatibleKotlinVersionHandler,
|
incompatibleKotlinVersionHandler,
|
||||||
minCompileSdkVersionHandler,
|
minCompileSdkVersionHandler,
|
||||||
jvm11RequiredHandler,
|
jvm11RequiredHandler,
|
||||||
|
outdatedGradleHandler,
|
||||||
];
|
];
|
||||||
|
|
||||||
const String _boxTitle = 'Flutter Fix';
|
const String _boxTitle = 'Flutter Fix';
|
||||||
@ -487,7 +489,7 @@ final GradleHandledError lockFileDepMissingHandler = GradleHandledError(
|
|||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
final GradleHandledError incompatibleKotlinVersionHandler = GradleHandledError(
|
final GradleHandledError incompatibleKotlinVersionHandler = GradleHandledError(
|
||||||
test: _lineMatcher(const <String>[
|
test: _lineMatcher(const <String>[
|
||||||
'Module was compiled with an incompatible version of Kotlin',
|
'was compiled with an incompatible version of Kotlin',
|
||||||
]),
|
]),
|
||||||
handler: ({
|
handler: ({
|
||||||
required String line,
|
required String line,
|
||||||
@ -509,6 +511,41 @@ final GradleHandledError incompatibleKotlinVersionHandler = GradleHandledError(
|
|||||||
eventLabel: 'incompatible-kotlin-version',
|
eventLabel: 'incompatible-kotlin-version',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final RegExp _outdatedGradlePattern = RegExp(r'The current Gradle version (.+) is not compatible with the Kotlin Gradle plugin');
|
||||||
|
|
||||||
|
@visibleForTesting
|
||||||
|
final GradleHandledError outdatedGradleHandler = GradleHandledError(
|
||||||
|
test: _outdatedGradlePattern.hasMatch,
|
||||||
|
handler: ({
|
||||||
|
required String line,
|
||||||
|
required FlutterProject project,
|
||||||
|
required bool usesAndroidX,
|
||||||
|
required bool multidexEnabled,
|
||||||
|
}) async {
|
||||||
|
final File gradleFile = project.directory
|
||||||
|
.childDirectory('android')
|
||||||
|
.childFile('build.gradle');
|
||||||
|
final File gradlePropertiesFile = project.directory
|
||||||
|
.childDirectory('android')
|
||||||
|
.childDirectory('gradle')
|
||||||
|
.childDirectory('wrapper')
|
||||||
|
.childFile('gradle-wrapper.properties');
|
||||||
|
globals.printBox(
|
||||||
|
'${globals.logger.terminal.warningMark} Your project needs to upgrade Gradle and the Android Gradle plugin.\n\n'
|
||||||
|
'To fix this issue, replace the following content:\n'
|
||||||
|
'${gradleFile.path}:\n'
|
||||||
|
' ${globals.terminal.color("- classpath 'com.android.tools.build:gradle:<current-version>'", TerminalColor.red)}\n'
|
||||||
|
' ${globals.terminal.color("+ classpath 'com.android.tools.build:gradle:$templateAndroidGradlePluginVersion'", TerminalColor.green)}\n'
|
||||||
|
'${gradlePropertiesFile.path}:\n'
|
||||||
|
' ${globals.terminal.color('- https://services.gradle.org/distributions/gradle-<current-version>-all.zip', TerminalColor.red)}\n'
|
||||||
|
' ${globals.terminal.color('+ https://services.gradle.org/distributions/gradle-$templateDefaultGradleVersion-all.zip', TerminalColor.green)}',
|
||||||
|
title: _boxTitle,
|
||||||
|
);
|
||||||
|
return GradleBuildStatus.exit;
|
||||||
|
},
|
||||||
|
eventLabel: 'outdated-gradle-version',
|
||||||
|
);
|
||||||
|
|
||||||
final RegExp _minCompileSdkVersionPattern = RegExp(r'The minCompileSdk \(([0-9]+)\) specified in a');
|
final RegExp _minCompileSdkVersionPattern = RegExp(r'The minCompileSdk \(([0-9]+)\) specified in a');
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
|
@ -36,6 +36,7 @@ void main() {
|
|||||||
incompatibleKotlinVersionHandler,
|
incompatibleKotlinVersionHandler,
|
||||||
minCompileSdkVersionHandler,
|
minCompileSdkVersionHandler,
|
||||||
jvm11RequiredHandler,
|
jvm11RequiredHandler,
|
||||||
|
outdatedGradleHandler,
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -877,6 +878,10 @@ Execution failed for task ':app:generateDebugFeatureTransitiveDeps'.
|
|||||||
incompatibleKotlinVersionHandler.test('Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.'),
|
incompatibleKotlinVersionHandler.test('Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.'),
|
||||||
isTrue,
|
isTrue,
|
||||||
);
|
);
|
||||||
|
expect(
|
||||||
|
incompatibleKotlinVersionHandler.test("class 'kotlin.Unit' was compiled with an incompatible version of Kotlin."),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('suggestion', () async {
|
testUsingContext('suggestion', () async {
|
||||||
@ -904,6 +909,51 @@ Execution failed for task ':app:generateDebugFeatureTransitiveDeps'.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group('Bump Gradle', () {
|
||||||
|
const String errorMessage = '''
|
||||||
|
A problem occurred evaluating project ':app'.
|
||||||
|
> Failed to apply plugin [id 'kotlin-android']
|
||||||
|
> The current Gradle version 4.10.2 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.1.1 or newer, or the previous version of the Kotlin plugin.
|
||||||
|
''';
|
||||||
|
|
||||||
|
testWithoutContext('pattern', () {
|
||||||
|
expect(
|
||||||
|
outdatedGradleHandler.test(errorMessage),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testUsingContext('suggestion', () async {
|
||||||
|
await outdatedGradleHandler.handler(
|
||||||
|
line: errorMessage,
|
||||||
|
project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
testLogger.statusText,
|
||||||
|
contains(
|
||||||
|
'\n'
|
||||||
|
'┌─ Flutter Fix ────────────────────────────────────────────────────────────────────┐\n'
|
||||||
|
'│ [!] Your project needs to upgrade Gradle and the Android Gradle plugin. │\n'
|
||||||
|
'│ │\n'
|
||||||
|
'│ To fix this issue, replace the following content: │\n'
|
||||||
|
'│ /android/build.gradle: │\n'
|
||||||
|
"│ - classpath 'com.android.tools.build:gradle:<current-version>' │\n"
|
||||||
|
"│ + classpath 'com.android.tools.build:gradle:7.1.2' │\n"
|
||||||
|
'│ /android/gradle/wrapper/gradle-wrapper.properties: │\n'
|
||||||
|
'│ - https://services.gradle.org/distributions/gradle-<current-version>-all.zip │\n'
|
||||||
|
'│ + https://services.gradle.org/distributions/gradle-7.4-all.zip │\n'
|
||||||
|
'└──────────────────────────────────────────────────────────────────────────────────┘\n'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
GradleUtils: () => FakeGradleUtils(),
|
||||||
|
Platform: () => fakePlatform('android'),
|
||||||
|
FileSystem: () => MemoryFileSystem.test(),
|
||||||
|
ProcessManager: () => FakeProcessManager.empty(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
group('Required compileSdkVersion', () {
|
group('Required compileSdkVersion', () {
|
||||||
const String errorMessage = '''
|
const String errorMessage = '''
|
||||||
Execution failed for task ':app:checkDebugAarMetadata'.
|
Execution failed for task ':app:checkDebugAarMetadata'.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user