Unverified Commit 60633b60 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

[flutter_tool] Suggest how to increase the Android minSdkVersion (#82372)

parent 49249693
......@@ -73,6 +73,7 @@ final List<GradleHandledError> gradleErrors = <GradleHandledError>[
flavorUndefinedHandler,
r8FailureHandler,
androidXFailureHandler,
minSdkVersion,
];
// Permission defined error message.
......@@ -352,3 +353,44 @@ final GradleHandledError flavorUndefinedHandler = GradleHandledError(
},
eventLabel: 'flavor-undefined',
);
final RegExp _minSdkVersionPattern = RegExp(r'uses-sdk:minSdkVersion ([0-9]+) cannot be smaller than version ([0-9]+) declared in library \[\:(.+)\]');
/// Handler when a plugin requires a higher Android API level.
@visibleForTesting
final GradleHandledError minSdkVersion = GradleHandledError(
test: (String line) {
return _minSdkVersionPattern.hasMatch(line);
},
handler: ({
String line,
FlutterProject project,
bool usesAndroidX,
bool shouldBuildPluginAsAar,
}) async {
final File gradleFile = project.directory
.childDirectory('android')
.childDirectory('app')
.childFile('build.gradle');
final Match minSdkVersionMatch = _minSdkVersionPattern.firstMatch(line);
assert(minSdkVersionMatch.groupCount == 3);
globals.printStatus(
'\nThe plugin ${minSdkVersionMatch.group(3)} requires a higher Android SDK version.\n'+
globals.logger.terminal.bolden(
'Fix this issue by adding the following to the file ${gradleFile.path}:\n'
'android {\n'
' defaultConfig {\n'
' minSdkVersion ${minSdkVersionMatch.group(2)}\n'
' }\n'
'}\n\n'
)+
'Note that your app won\'t be available to users running Android SDKs below ${minSdkVersionMatch.group(2)}.\n'
'Alternatively, try to find a version of this plugin that supports these lower versions of the Android SDK.'
);
return GradleBuildStatus.exit;
},
eventLabel: 'plugin-min-sdk',
);
......@@ -29,6 +29,7 @@ void main() {
flavorUndefinedHandler,
r8FailureHandler,
androidXFailureHandler,
minSdkVersion,
])
);
});
......@@ -646,6 +647,47 @@ assembleProfile
FileSystem: () => MemoryFileSystem.test(),
});
});
group('higher minSdkVersion', () {
const String stdoutLine = 'uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:webview_flutter] /tmp/cirrus-ci-build/all_plugins/build/webview_flutter/intermediates/library_manifest/release/AndroidManifest.xml as the library might be using APIs not available in 16';
testWithoutContext('pattern', () {
expect(
minSdkVersion.test(stdoutLine),
isTrue,
);
});
testUsingContext('suggestion', () async {
await minSdkVersion.handler(
line: stdoutLine,
project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory),
);
expect(
testLogger.statusText,
contains(
'\n'
'The plugin webview_flutter requires a higher Android SDK version.\n'
'Fix this issue by adding the following to the file /android/app/build.gradle:\n'
'android {\n'
' defaultConfig {\n'
' minSdkVersion 19\n'
' }\n'
'}\n'
'\n'
'Note that your app won\'t be available to users running Android SDKs below 19.\n'
'Alternatively, try to find a version of this plugin that supports these lower versions of the Android SDK.\n'
''
)
);
}, overrides: <Type, Generator>{
GradleUtils: () => FakeGradleUtils(),
Platform: () => fakePlatform('android'),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.empty(),
});
});
}
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