@@ -43,6 +43,8 @@ void main() {
43
43
bool includeNamespace = true ,
44
44
bool commentNamespace = false ,
45
45
bool warningsConfigured = true ,
46
+ bool useDeprecatedCompileSdkVersion = false ,
47
+ String compileSdk = '33' ,
46
48
}) {
47
49
final File buildGradle = package
48
50
.platformDirectory (FlutterPlatform .android)
@@ -88,7 +90,7 @@ apply plugin: 'com.android.library'
88
90
${includeLanguageVersion ? javaSection : '' }
89
91
android {
90
92
${includeNamespace ? namespace : '' }
91
- compileSdk 33
93
+ ${ useDeprecatedCompileSdkVersion ? 'compileSdkVersion' : ' compileSdk' } $ compileSdk
92
94
93
95
defaultConfig {
94
96
minSdkVersion 30
@@ -989,4 +991,111 @@ dependencies {
989
991
);
990
992
});
991
993
});
994
+
995
+ group ('compileSdk check' , () {
996
+ test ('passes if set to a number' , () async {
997
+ const String packageName = 'a_package' ;
998
+ final RepositoryPackage package =
999
+ createFakePackage (packageName, packagesDir, isFlutter: true );
1000
+ writeFakePluginBuildGradle (package,
1001
+ includeLanguageVersion: true , compileSdk: '35' );
1002
+ writeFakeManifest (package);
1003
+ final RepositoryPackage example = package.getExamples ().first;
1004
+ writeFakeExampleBuildGradles (example, pluginName: packageName);
1005
+ writeFakeManifest (example, isApp: true );
1006
+
1007
+ final List <String > output =
1008
+ await runCapturingPrint (runner, < String > ['gradle-check' ]);
1009
+
1010
+ expect (
1011
+ output,
1012
+ containsAllInOrder (< Matcher > [
1013
+ contains ('Validating android/build.gradle' ),
1014
+ ]),
1015
+ );
1016
+ });
1017
+
1018
+ test ('passes if set to flutter.compileSdkVersion with Flutter 3.27+' ,
1019
+ () async {
1020
+ const String packageName = 'a_package' ;
1021
+ final RepositoryPackage package = createFakePackage (
1022
+ packageName, packagesDir,
1023
+ isFlutter: true , flutterConstraint: '>=3.27.0' );
1024
+ writeFakePluginBuildGradle (package,
1025
+ includeLanguageVersion: true ,
1026
+ compileSdk: 'flutter.compileSdkVersion' );
1027
+ writeFakeManifest (package);
1028
+ final RepositoryPackage example = package.getExamples ().first;
1029
+ writeFakeExampleBuildGradles (example, pluginName: packageName);
1030
+ writeFakeManifest (example, isApp: true );
1031
+
1032
+ final List <String > output =
1033
+ await runCapturingPrint (runner, < String > ['gradle-check' ]);
1034
+
1035
+ expect (
1036
+ output,
1037
+ containsAllInOrder (< Matcher > [
1038
+ contains ('Validating android/build.gradle' ),
1039
+ ]),
1040
+ );
1041
+ });
1042
+
1043
+ test ('fails if set to flutter.compileSdkVersion with Flutter <3.27' ,
1044
+ () async {
1045
+ const String packageName = 'a_package' ;
1046
+ final RepositoryPackage package = createFakePackage (
1047
+ packageName, packagesDir,
1048
+ isFlutter: true , flutterConstraint: '>=3.24.0' );
1049
+ writeFakePluginBuildGradle (package,
1050
+ includeLanguageVersion: true ,
1051
+ compileSdk: 'flutter.compileSdkVersion' );
1052
+ writeFakeManifest (package);
1053
+ final RepositoryPackage example = package.getExamples ().first;
1054
+ writeFakeExampleBuildGradles (example, pluginName: packageName);
1055
+ writeFakeManifest (example, isApp: true );
1056
+
1057
+ Error ? commandError;
1058
+ final List <String > output = await runCapturingPrint (
1059
+ runner, < String > ['gradle-check' ], errorHandler: (Error e) {
1060
+ commandError = e;
1061
+ });
1062
+
1063
+ expect (commandError, isA <ToolExit >());
1064
+ expect (
1065
+ output,
1066
+ containsAllInOrder (< Matcher > [
1067
+ contains ('Use of flutter.compileSdkVersion requires a minimum '
1068
+ 'Flutter version of 3.27, but this package currently supports '
1069
+ '3.24.0' ),
1070
+ ]),
1071
+ );
1072
+ });
1073
+
1074
+ test ('fails if uses the legacy key' , () async {
1075
+ const String packageName = 'a_package' ;
1076
+ final RepositoryPackage package =
1077
+ createFakePackage (packageName, packagesDir, isFlutter: true );
1078
+ writeFakePluginBuildGradle (package,
1079
+ includeLanguageVersion: true , useDeprecatedCompileSdkVersion: true );
1080
+ writeFakeManifest (package);
1081
+ final RepositoryPackage example = package.getExamples ().first;
1082
+ writeFakeExampleBuildGradles (example, pluginName: packageName);
1083
+ writeFakeManifest (example, isApp: true );
1084
+
1085
+ Error ? commandError;
1086
+ final List <String > output = await runCapturingPrint (
1087
+ runner, < String > ['gradle-check' ], errorHandler: (Error e) {
1088
+ commandError = e;
1089
+ });
1090
+
1091
+ expect (commandError, isA <ToolExit >());
1092
+ expect (
1093
+ output,
1094
+ containsAllInOrder (< Matcher > [
1095
+ contains ('Please replace the deprecated "compileSdkVersion" setting '
1096
+ 'with the newer "compileSdk"' ),
1097
+ ]),
1098
+ );
1099
+ });
1100
+ });
992
1101
}
0 commit comments