Unverified Commit 683590d1 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Add suggestion for compileSdkVersion warning (#95369)

parent f5a1fedb
...@@ -76,6 +76,7 @@ final List<GradleHandledError> gradleErrors = <GradleHandledError>[ ...@@ -76,6 +76,7 @@ final List<GradleHandledError> gradleErrors = <GradleHandledError>[
lockFileDepMissing, lockFileDepMissing,
multidexErrorHandler, multidexErrorHandler,
incompatibleKotlinVersionHandler, incompatibleKotlinVersionHandler,
minCompileSdkVersionHandler,
]; ];
const String _boxTitle = 'Flutter Fix'; const String _boxTitle = 'Flutter Fix';
...@@ -505,3 +506,34 @@ final GradleHandledError incompatibleKotlinVersionHandler = GradleHandledError( ...@@ -505,3 +506,34 @@ final GradleHandledError incompatibleKotlinVersionHandler = GradleHandledError(
}, },
eventLabel: 'incompatible-kotlin-version', eventLabel: 'incompatible-kotlin-version',
); );
final RegExp _minCompileSdkVersionPattern = RegExp(r'The minCompileSdk \(([0-9]+)\) specified in a');
@visibleForTesting
final GradleHandledError minCompileSdkVersionHandler = GradleHandledError(
test: _minCompileSdkVersionPattern.hasMatch,
handler: ({
required String line,
required FlutterProject project,
required bool usesAndroidX,
required bool multidexEnabled,
}) async {
final Match? minSdkVersionMatch = _minCompileSdkVersionPattern.firstMatch(line);
assert(minSdkVersionMatch?.groupCount == 1);
final File gradleFile = project.directory
.childDirectory('android')
.childDirectory('app')
.childFile('build.gradle');
globals.printBox(
'${globals.logger.terminal.warningMark} Your project requires a higher compileSdkVersion.\n'
'Fix this issue by bumping the compileSdkVersion in ${gradleFile.path}:\n'
'android {\n'
' compileSdkVersion ${minSdkVersionMatch?.group(1)}\n'
'}',
title: _boxTitle,
);
return GradleBuildStatus.exit;
},
eventLabel: 'min-compile-sdk-version',
);
...@@ -34,6 +34,7 @@ void main() { ...@@ -34,6 +34,7 @@ void main() {
lockFileDepMissing, lockFileDepMissing,
multidexErrorHandler, multidexErrorHandler,
incompatibleKotlinVersionHandler, incompatibleKotlinVersionHandler,
minCompileSdkVersionHandler,
]) ])
); );
}); });
...@@ -907,6 +908,59 @@ Execution failed for task ':app:generateDebugFeatureTransitiveDeps'. ...@@ -907,6 +908,59 @@ Execution failed for task ':app:generateDebugFeatureTransitiveDeps'.
ProcessManager: () => FakeProcessManager.empty(), ProcessManager: () => FakeProcessManager.empty(),
}); });
}); });
group('Required compileSdkVersion', () {
const String errorMessage = '''
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> One or more issues found when checking AAR metadata values:
The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.window:window-java:1.0.0-beta04.
AAR metadata file: ~/.gradle/caches/transforms-3/2adc32c5b3f24bed763d33fbfb203338/transformed/jetified-window-java-1.0.0-beta04/META-INF/com/android/build/gradle/aar-metadata.properties.
The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.window:window:1.0.0-beta04.
AAR metadata file: ~/.gradle/caches/transforms-3/88f7e476ef68cecca729426edff955b5/transformed/jetified-window-1.0.0-beta04/META-INF/com/android/build/gradle/aar-metadata.properties.
''';
testWithoutContext('pattern', () {
expect(
minCompileSdkVersionHandler.test(errorMessage),
isTrue,
);
});
testUsingContext('suggestion', () async {
await minCompileSdkVersionHandler.handler(
line: errorMessage,
project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory),
);
expect(
testLogger.statusText,
contains(
'\n'
'┌─ Flutter Fix ─────────────────────────────────────────────────────────────────┐\n'
'│ [!] Your project requires a higher compileSdkVersion. │\n'
'│ Fix this issue by bumping the compileSdkVersion in /android/app/build.gradle: │\n'
'│ android { │\n'
'│ compileSdkVersion 31 │\n'
'│ } │\n'
'└───────────────────────────────────────────────────────────────────────────────┘\n'
)
);
}, overrides: <Type, Generator>{
GradleUtils: () => FakeGradleUtils(),
Platform: () => fakePlatform('android'),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.empty(),
});
});
} }
bool formatTestErrorMessage(String errorMessage, GradleHandledError error) { bool formatTestErrorMessage(String errorMessage, GradleHandledError error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment