Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/camera/camera_android/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ buildFeatures {
buildConfig true
}
namespace 'io.flutter.plugins.camera'
compileSdk = 36
compileSdk = flutter.compileSdkVersion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should get a package version bump since it affected clients.


defaultConfig {
minSdkVersion 21
Expand Down
21 changes: 14 additions & 7 deletions script/tool/lib/src/gradle_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ for more details.''';
final RegExp legacySettingPattern = RegExp(r'^\s*compileSdkVersion');
final String? compileSdkLine = gradleLines
.firstWhereOrNull((String line) => linePattern.hasMatch(line));

final Pubspec pubspec = package.parsePubspec();
final VersionConstraint? flutterConstraint =
pubspec.environment['flutter'];
final Version? minFlutterVersion =
flutterConstraint != null && flutterConstraint is VersionRange
? flutterConstraint.min
: null;

if (compileSdkLine == null) {
// Equals regex not found check for method pattern.
final RegExp compileSpacePattern = RegExp(r'^\s*compileSdk');
Expand All @@ -447,13 +456,6 @@ for more details.''';
return false;
}
if (compileSdkLine.contains('flutter.compileSdkVersion')) {
final Pubspec pubspec = package.parsePubspec();
final VersionConstraint? flutterConstraint =
pubspec.environment['flutter'];
final Version? minFlutterVersion =
flutterConstraint != null && flutterConstraint is VersionRange
? flutterConstraint.min
: null;
if (minFlutterVersion == null) {
printError('${indentation}Unable to find a Flutter SDK version '
'constraint. Use of flutter.compileSdkVersion requires a minimum '
Expand All @@ -469,6 +471,11 @@ for more details.''';
return false;
}
}
if (!compileSdkLine.contains('flutter.compileSdkVersion') && minFlutterVersion! >= Version(3, 27, 0)) {
printError('${indentation}Please use flutter.compileSdkVersion instead '
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printError('${indentation}Please use flutter.compileSdkVersion instead '
printError('${indentation}Warning: please use flutter.compileSdkVersion instead '

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A useful warning requires some sort of message at the bottom of the gradle_check_command output. Will probably have to look in package_looping_command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per my comment in the other PR, a message at the bottom of the output still won't really be a useful warning most of the time. We have printWarning, which will cause a message in the summary at the end, but as it says in its docs:

  /// Warnings are not surfaced in CI summaries, so this is only useful for
  /// highlighting something when someone is already looking though the log
  /// messages. DO NOT RELY on someone noticing a warning; instead, use it for
  /// things that might be useful to someone debugging an unexpected result.

'of a hardcoded compileSdk version number');
return false;
Copy link
Contributor Author

@jesswrd jesswrd Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return false;

}
return true;
}

Expand Down
29 changes: 29 additions & 0 deletions script/tool/test/gradle_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,35 @@ dependencies {
);
});

test('fails if set to a number with Flutter >=3.27', () async {
const String packageName = 'a_package';
final RepositoryPackage package = createFakePackage(
packageName, packagesDir,
isFlutter: true, flutterConstraint: '>=3.27.0');
writeFakePluginBuildGradle(package,
includeLanguageVersion: true, compileSdk: '35');
writeFakeManifest(package);
final RepositoryPackage example = package.getExamples().first;
writeFakeExampleBuildGradles(example, pluginName: packageName);
writeFakeManifest(example, isApp: true);

Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['gradle-check'], errorHandler: (Error e) {
commandError = e;
});

expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains(
'Please use flutter.compileSdkVersion instead of a hardcoded '
'compileSdk version number'),
]),
);
});

test('fails if set to flutter.compileSdkVersion with Flutter <3.27',
() async {
const String packageName = 'a_package';
Expand Down