@@ -7,24 +7,24 @@ import '../common/utils.dart';
7
7
import '../flutter_app.dart' ;
8
8
import 'firebase_options.dart' ;
9
9
10
- // https://regex101.com/r/Lj93lx/1
10
+ // https://regex101.com/r/Lj93lx/2
11
11
final _androidBuildGradleRegex = RegExp (
12
- r'dependencies\s*\{ ' ,
12
+ r'dependencies\s*[\{] ' ,
13
13
multiLine: true ,
14
14
);
15
- // https://regex101.com/r/OZnO1j/1
15
+ // https://regex101.com/r/OZnO1j/2
16
16
final _androidAppBuildGradleRegex = RegExp (
17
- r'''(?:(^[\s]*?apply[\s]+plugin\:[\s]+['"]{1}com\.android\.application['"]{1})|(^[\s]*?id[\s]+["']com\.android\.application["']))''' ,
17
+ r'''(?:(^[\s]*?apply[\s]+plugin\:[\s]+['"]{1}com\.android\.application['"]{1})|(^[\s]*?id[\s]+["']com\.android\.application["'])|plugins\s*\{\s*id\(['"]{1}com\.android\.application['"]{1}\) )''' ,
18
18
multiLine: true ,
19
19
);
20
- // https://regex101.com/r/ndlYVL/1
20
+ // https://regex101.com/r/ndlYVL/2
21
21
final _androidBuildGradleGoogleServicesRegex = RegExp (
22
- r'''((?<indentation>^[\s]*?)classpath\s?['"]{1}com\.google\.gms:google-services:.*?['"]{1}\s*?$)''' ,
22
+ r'''((?<indentation>^[\s]*?)(?: classpath\s?['"]{1}com\.google\.gms:google-services:.*?['"]{1}\s*?$|id\(['"]{1}com\.google\.gms\.google-services['"]{1}\)) )''' ,
23
23
multiLine: true ,
24
24
);
25
- // https://regex101.com/r/pP1k6i/1
25
+ // https://regex101.com/r/pP1k6i/2
26
26
final _androidAppBuildGradleGoogleServicesRegex = RegExp (
27
- r'''(?:(^[\s]*?apply[\s]+plugin\:[\s]+['"]{1}com\.google\.gms\.google-services['"]{1})|(^[\s]*?id[\s]+['"]com\.google\.gms\.google-services['"]))''' ,
27
+ r'''(?:(^[\s]*?apply[\s]+plugin\:[\s]+['"]{1}com\.google\.gms\.google-services['"]{1})|(^[\s]*?id[\s]+['"]com\.google\.gms\.google-services['"])|plugins\s*\{\s*id\(['"]{1}com\.google\.gms\.google-services['"]{1}\) )''' ,
28
28
multiLine: true ,
29
29
);
30
30
@@ -57,10 +57,11 @@ String _applyGradleSettingsDependency(
57
57
String version, {
58
58
bool flutterfireComments = false ,
59
59
}) {
60
- if (flutterfireComments) {
61
- return '\n $_flutterFireConfigCommentStart \n id "$dependency " version "$version " apply false\n $_flutterFireConfigCommentEnd ' ;
62
- }
63
- return '\n id "$dependency " version "$version " apply false' ;
60
+ final kotlinDslContent = flutterfireComments
61
+ ? '\n $_flutterFireConfigCommentStart \n id("$dependency ") version "$version " apply false\n $_flutterFireConfigCommentEnd '
62
+ : '\n id("$dependency ") version "$version " apply false' ;
63
+
64
+ return kotlinDslContent;
64
65
}
65
66
66
67
enum BuildGradleConfiguration {
@@ -182,28 +183,36 @@ Future<void> gradleContentUpdates(
182
183
final androidBuildGradleFile = File (
183
184
path.join (
184
185
flutterApp.androidDirectory.path,
185
- 'build.gradle' ,
186
+ 'build.gradle.kts ' ,
186
187
),
187
- );
188
+ ).existsSync ()
189
+ ? File (path.join (flutterApp.androidDirectory.path, 'build.gradle.kts' ))
190
+ : File (path.join (flutterApp.androidDirectory.path, 'build.gradle' ));
191
+
188
192
final androidBuildGradleFileContents =
189
193
androidBuildGradleFile.readAsStringSync ();
190
194
191
195
final androidAppBuildGradleFile = File (
192
196
path.join (
193
197
flutterApp.androidDirectory.path,
194
198
'app' ,
195
- 'build.gradle' ,
199
+ 'build.gradle.kts ' ,
196
200
),
197
- );
201
+ ).existsSync ()
202
+ ? File (path.join (flutterApp.androidDirectory.path, 'app' , 'build.gradle.kts' ))
203
+ : File (path.join (flutterApp.androidDirectory.path, 'app' , 'build.gradle' ));
204
+
198
205
final androidAppBuildGradleFileContents =
199
206
androidAppBuildGradleFile.readAsStringSync ();
200
207
201
208
final androidGradleSettingsFile = File (
202
209
path.join (
203
210
flutterApp.androidDirectory.path,
204
- 'settings.gradle' ,
211
+ 'settings.gradle.kts ' ,
205
212
),
206
- );
213
+ ).existsSync ()
214
+ ? File (path.join (flutterApp.androidDirectory.path, 'settings.gradle.kts' ))
215
+ : File (path.join (flutterApp.androidDirectory.path, 'settings.gradle' ));
207
216
208
217
final androidGradleSettingsFileContents =
209
218
androidGradleSettingsFile.readAsStringSync ();
0 commit comments