From 4690dc4055d08ad60117480864c6db4a4e55d6d5 Mon Sep 17 00:00:00 2001 From: jesswrd Date: Wed, 23 Jul 2025 11:16:52 -0700 Subject: [PATCH 1/7] revert hardcoded compilesdk back to flutter.compileSdkVersion --- packages/camera/camera_android/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera_android/android/build.gradle b/packages/camera/camera_android/android/build.gradle index c081c3d47d6..685caaa3238 100644 --- a/packages/camera/camera_android/android/build.gradle +++ b/packages/camera/camera_android/android/build.gradle @@ -31,7 +31,7 @@ buildFeatures { buildConfig true } namespace 'io.flutter.plugins.camera' - compileSdk = 36 + compileSdk = flutter.compileSdkVersion defaultConfig { minSdkVersion 21 From f8f999c72bbe2cade347e4b287c1d093936e8215 Mon Sep 17 00:00:00 2001 From: jesswrd Date: Wed, 23 Jul 2025 14:37:31 -0700 Subject: [PATCH 2/7] added check for hardcoding compilesdk version number --- script/tool/lib/src/gradle_check_command.dart | 21 +++++++++----- .../tool/test/gradle_check_command_test.dart | 29 +++++++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/script/tool/lib/src/gradle_check_command.dart b/script/tool/lib/src/gradle_check_command.dart index 130d428b776..387403d124e 100644 --- a/script/tool/lib/src/gradle_check_command.dart +++ b/script/tool/lib/src/gradle_check_command.dart @@ -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'); @@ -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 ' @@ -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 ' + 'of a hardcoded compileSdk version number'); + return false; + } return true; } diff --git a/script/tool/test/gradle_check_command_test.dart b/script/tool/test/gradle_check_command_test.dart index 63c766d0a32..6a23e5bcd28 100644 --- a/script/tool/test/gradle_check_command_test.dart +++ b/script/tool/test/gradle_check_command_test.dart @@ -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 output = await runCapturingPrint( + runner, ['gradle-check'], errorHandler: (Error e) { + commandError = e; + }); + + expect(commandError, isA()); + expect( + output, + containsAllInOrder([ + 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'; From 1e12eec77f4785c91c7cfd4caf6506213c05864d Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Mon, 22 Sep 2025 14:41:14 -0700 Subject: [PATCH 3/7] Bump version --- packages/camera/camera_android/CHANGELOG.md | 4 ++++ packages/camera/camera_android/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera_android/CHANGELOG.md b/packages/camera/camera_android/CHANGELOG.md index c43f2ab7e91..737a601ac7c 100644 --- a/packages/camera/camera_android/CHANGELOG.md +++ b/packages/camera/camera_android/CHANGELOG.md @@ -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. diff --git a/packages/camera/camera_android/pubspec.yaml b/packages/camera/camera_android/pubspec.yaml index b9a0da19604..c9dc7d3ee8c 100644 --- a/packages/camera/camera_android/pubspec.yaml +++ b/packages/camera/camera_android/pubspec.yaml @@ -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 From 72c63df075c7c75aa6d5963f7f7611dad655f22d Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Mon, 29 Sep 2025 06:59:41 -0700 Subject: [PATCH 4/7] add check for below min flutter sdk version --- script/tool/lib/src/gradle_check_command.dart | 42 +++++++++++++------ .../tool/test/gradle_check_command_test.dart | 27 +++++++----- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/script/tool/lib/src/gradle_check_command.dart b/script/tool/lib/src/gradle_check_command.dart index 387403d124e..c6e541b7a37 100644 --- a/script/tool/lib/src/gradle_check_command.dart +++ b/script/tool/lib/src/gradle_check_command.dart @@ -429,14 +429,6 @@ for more details.'''; 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'); @@ -456,6 +448,13 @@ 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 ' @@ -470,11 +469,28 @@ for more details.'''; 'version to at least 3.27.'); return false; } - } - if (!compileSdkLine.contains('flutter.compileSdkVersion') && minFlutterVersion! >= Version(3, 27, 0)) { - printError('${indentation}Please use flutter.compileSdkVersion instead ' - 'of a hardcoded compileSdk version number'); - return false; + } else { + // Extract compileSdkVersion and check if it higher than flutter.compileSdkVersion. + final RegExp numericVersionPattern = RegExp(r'=\s*(\d+)'); + final RegExpMatch? versionMatch = + numericVersionPattern.firstMatch(compileSdkLine); + + if (versionMatch != null) { + final int compileSdkVersion = int.parse(versionMatch.group(1)!); + const int minCompileSdkVersion = 36; + + if (compileSdkVersion < minCompileSdkVersion) { + printError( + '${indentation}compileSdk version $compileSdkVersion is too low. ' + 'Minimum required version is $minCompileSdkVersion. ' + "${indentation}Please update this package's compileSdkVersion to at least " + '$minCompileSdkVersion or use flutter.compileSdkVersion.'); + return false; + } + } else { + printError('${indentation}Unable to parse compileSdk version number.'); + return false; + } } return true; } diff --git a/script/tool/test/gradle_check_command_test.dart b/script/tool/test/gradle_check_command_test.dart index 6a23e5bcd28..f363980677b 100644 --- a/script/tool/test/gradle_check_command_test.dart +++ b/script/tool/test/gradle_check_command_test.dart @@ -45,7 +45,7 @@ void main() { bool warningsConfigured = true, bool useDeprecatedCompileSdkVersion = false, bool usePropertyAssignment = true, - String compileSdk = '33', + String compileSdk = '36', }) { final File buildGradle = package .platformDirectory(FlutterPlatform.android) @@ -997,12 +997,13 @@ dependencies { }); group('compileSdk check', () { - test('passes if set to a number', () async { + test('passes if set to a version higher than flutter.compileSdkVersio', + () async { const String packageName = 'a_package'; final RepositoryPackage package = createFakePackage(packageName, packagesDir, isFlutter: true); writeFakePluginBuildGradle(package, - includeLanguageVersion: true, compileSdk: '35'); + includeLanguageVersion: true, compileSdk: '37'); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; writeFakeExampleBuildGradles(example, pluginName: packageName); @@ -1044,13 +1045,16 @@ dependencies { ); }); - test('fails if set to a number with Flutter >=3.27', () async { + test('fails if set to a version lower than flutter.compileSdkVersion', + () async { const String packageName = 'a_package'; - final RepositoryPackage package = createFakePackage( - packageName, packagesDir, - isFlutter: true, flutterConstraint: '>=3.27.0'); + final RepositoryPackage package = + createFakePackage(packageName, packagesDir, isFlutter: true); + // Current flutter.compileSdkVersion is 36. + const String minCompileSdkVersion = '36'; + const String testCompileSdkVersion = '35'; writeFakePluginBuildGradle(package, - includeLanguageVersion: true, compileSdk: '35'); + includeLanguageVersion: true, compileSdk: testCompileSdkVersion); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; writeFakeExampleBuildGradles(example, pluginName: packageName); @@ -1066,9 +1070,10 @@ dependencies { expect( output, containsAllInOrder([ - contains( - 'Please use flutter.compileSdkVersion instead of a hardcoded ' - 'compileSdk version number'), + contains('compileSdk version $testCompileSdkVersion is too low. ' + 'Minimum required version is $minCompileSdkVersion.'), + // "Please update this package's compileSdkVersion to at least " + // '$minCompileSdkVersion or use flutter.compileSdkVersion.') ]), ); }); From 2d838769d40da8242d61f1153bf7d0f96d6242de Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Mon, 29 Sep 2025 07:07:52 -0700 Subject: [PATCH 5/7] test for main message --- script/tool/lib/src/gradle_check_command.dart | 2 +- script/tool/test/gradle_check_command_test.dart | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/script/tool/lib/src/gradle_check_command.dart b/script/tool/lib/src/gradle_check_command.dart index c6e541b7a37..79c28512413 100644 --- a/script/tool/lib/src/gradle_check_command.dart +++ b/script/tool/lib/src/gradle_check_command.dart @@ -482,7 +482,7 @@ for more details.'''; if (compileSdkVersion < minCompileSdkVersion) { printError( '${indentation}compileSdk version $compileSdkVersion is too low. ' - 'Minimum required version is $minCompileSdkVersion. ' + 'Minimum required version is $minCompileSdkVersion.\n' "${indentation}Please update this package's compileSdkVersion to at least " '$minCompileSdkVersion or use flutter.compileSdkVersion.'); return false; diff --git a/script/tool/test/gradle_check_command_test.dart b/script/tool/test/gradle_check_command_test.dart index f363980677b..df3713d448b 100644 --- a/script/tool/test/gradle_check_command_test.dart +++ b/script/tool/test/gradle_check_command_test.dart @@ -997,11 +997,12 @@ dependencies { }); group('compileSdk check', () { - test('passes if set to a version higher than flutter.compileSdkVersio', + test('passes if set to a version higher than flutter.compileSdkVersion', () async { const String packageName = 'a_package'; final RepositoryPackage package = createFakePackage(packageName, packagesDir, isFlutter: true); + // Current flutter.compileSdkVersion is 36. writeFakePluginBuildGradle(package, includeLanguageVersion: true, compileSdk: '37'); writeFakeManifest(package); @@ -1071,9 +1072,7 @@ dependencies { output, containsAllInOrder([ contains('compileSdk version $testCompileSdkVersion is too low. ' - 'Minimum required version is $minCompileSdkVersion.'), - // "Please update this package's compileSdkVersion to at least " - // '$minCompileSdkVersion or use flutter.compileSdkVersion.') + 'Minimum required version is $minCompileSdkVersion.'), ]), ); }); From ef09abb4d1779de8d4a29e5f4af167d6892c94e1 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Mon, 29 Sep 2025 08:11:48 -0700 Subject: [PATCH 6/7] format --- script/tool/test/gradle_check_command_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/tool/test/gradle_check_command_test.dart b/script/tool/test/gradle_check_command_test.dart index df3713d448b..58415220218 100644 --- a/script/tool/test/gradle_check_command_test.dart +++ b/script/tool/test/gradle_check_command_test.dart @@ -1072,7 +1072,7 @@ dependencies { output, containsAllInOrder([ contains('compileSdk version $testCompileSdkVersion is too low. ' - 'Minimum required version is $minCompileSdkVersion.'), + 'Minimum required version is $minCompileSdkVersion.'), ]), ); }); From 459ef39e768c678e4b91c14e4182fc72f188b30d Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Mon, 29 Sep 2025 12:00:07 -0700 Subject: [PATCH 7/7] fix typo --- script/tool/lib/src/gradle_check_command.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/tool/lib/src/gradle_check_command.dart b/script/tool/lib/src/gradle_check_command.dart index 70f3db8fba3..a797cf95f88 100644 --- a/script/tool/lib/src/gradle_check_command.dart +++ b/script/tool/lib/src/gradle_check_command.dart @@ -469,7 +469,7 @@ for more details.'''; return false; } } else { - // Extract compileSdkVersion and check if it higher than flutter.compileSdkVersion. + // Extract compileSdkVersion and check if it is higher than flutter.compileSdkVersion. final RegExp numericVersionPattern = RegExp(r'=\s*(\d+)'); final RegExpMatch? versionMatch = numericVersionPattern.firstMatch(compileSdkLine);