Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.10+8

* Restores compileSdk version to flutter.compileSdkVersion.

## 0.10.10+7

* Updates minimum supported SDK version to Flutter 3.35.
Expand Down
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

defaultConfig {
minSdkVersion 24
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Android implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22

version: 0.10.10+7
version: 0.10.10+8

environment:
sdk: ^3.9.0
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
Collaborator

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Taking this over--how about we keep the printError and just return false? The validation will fail then they can look through the logs to see the reason why.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Some context got lost here; this thread in the original PR explains the problem with making it an error to use a value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Understood. I added a check for lower that flutter.compileSdkVersion. Of course, that isn't great because it relies on a hard coded version of that value and not the actual value itself, so we would have to update the command every time flutter.compileSdkVersion is used, so more maintenance burden. But, I'm okay keeping it.

Also, I considered adding a check for version == flutter.compileSdkVersion but I don't think that's a major value add, but let me know if you disagree.

'of a hardcoded compileSdk version number');
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