Skip to content

Commit 9a41f11

Browse files
Reverts "Use Gradle KTS in new Android app projects by default (flutter#154061)" (flutter#157194)
Reverts: flutter#154061 Initiated by: QuncCccccc Reason for reverting: might be the reason that cause Framework tree to red Original PR Author: bartekpacia Reviewed By: {gmackall, reidbaker} This change reverts the following previous change: This PR resolves flutter#151166
1 parent d3c54a1 commit 9a41f11

File tree

18 files changed

+112
-133
lines changed

18 files changed

+112
-133
lines changed

dev/devicelab/bin/tasks/engine_dependency_proxy_test.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,14 @@ Future<void> main() async {
2929
await runProjectTest((FlutterProject flutterProject) async {
3030
await inDirectory(path.join(flutterProject.rootPath, 'android'), () async {
3131
section('Insert gradle testing script');
32-
final File buildFile = getAndroidBuildFile(path.join(flutterProject.rootPath, 'android'));
33-
buildFile.writeAsStringSync(
32+
final File build = File(path.join(
33+
flutterProject.rootPath, 'android', 'app', 'build.gradle',
34+
));
35+
build.writeAsStringSync(
3436
'''
35-
tasks.register("printEngineMavenUrl") {
37+
task printEngineMavenUrl() {
3638
doLast {
37-
project.repositories.forEach { repo ->
38-
if (repo.name == "maven") {
39-
repo as MavenArtifactRepository
40-
logger.quiet(repo.url.toString())
41-
}
42-
}
39+
println project.repositories.find { it.name == 'maven' }.url
4340
}
4441
}
4542
''',

dev/devicelab/lib/framework/apk_utils.dart

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,18 @@ class FlutterProject {
256256
String get rootPath => path.join(parent.path, name);
257257
String get androidPath => path.join(rootPath, 'android');
258258
String get iosPath => path.join(rootPath, 'ios');
259-
File get appBuildFile => getAndroidBuildFile(androidPath);
260259

261260
Future<void> addCustomBuildType(String name, {required String initWith}) async {
262-
final File buildScript = appBuildFile;
261+
final File buildScript = File(
262+
path.join(androidPath, 'app', 'build.gradle'),
263+
);
263264

264265
buildScript.openWrite(mode: FileMode.append).write('''
265266
266267
android {
267268
buildTypes {
268-
create("$name") {
269-
initWith(getByName("$initWith"))
269+
$name {
270+
initWith $initWith
270271
}
271272
}
272273
}
@@ -287,12 +288,14 @@ android {
287288
}
288289

289290
Future<void> setMinSdkVersion(int sdkVersion) async {
290-
final File buildScript = appBuildFile;
291+
final File buildScript = File(
292+
path.join(androidPath, 'app', 'build.gradle'),
293+
);
291294

292295
buildScript.openWrite(mode: FileMode.append).write('''
293296
android {
294297
defaultConfig {
295-
minSdk = $sdkVersion
298+
minSdkVersion $sdkVersion
296299
}
297300
}
298301
''');
@@ -305,20 +308,22 @@ android {
305308
}
306309

307310
Future<void> addProductFlavors(Iterable<String> flavors) async {
308-
final File buildScript = appBuildFile;
311+
final File buildScript = File(
312+
path.join(androidPath, 'app', 'build.gradle'),
313+
);
309314

310315
final String flavorConfig = flavors.map((String name) {
311316
return '''
312-
create("$name") {
313-
applicationIdSuffix = ".$name"
314-
versionNameSuffix = "-$name"
317+
$name {
318+
applicationIdSuffix ".$name"
319+
versionNameSuffix "-$name"
315320
}
316321
''';
317322
}).join('\n');
318323

319324
buildScript.openWrite(mode: FileMode.append).write('''
320325
android {
321-
flavorDimensions.add("mode")
326+
flavorDimensions "mode"
322327
productFlavors {
323328
$flavorConfig
324329
}
@@ -327,7 +332,9 @@ android {
327332
}
328333

329334
Future<void> introduceError() async {
330-
final File buildScript = appBuildFile;
335+
final File buildScript = File(
336+
path.join(androidPath, 'app', 'build.gradle'),
337+
);
331338
await buildScript.writeAsString((await buildScript.readAsString()).replaceAll('buildTypes', 'builTypes'));
332339
}
333340

@@ -470,14 +477,3 @@ String? validateSnapshotDependency(FlutterProject project, String expectedTarget
470477
return contentSnapshot.contains('$expectedTarget ')
471478
? null : 'Dependency file should have $expectedTarget as target. Instead found $contentSnapshot';
472479
}
473-
474-
File getAndroidBuildFile(String androidPath) {
475-
final File groovyFile = File(path.join(androidPath, 'app', 'build.gradle'));
476-
final File kotlinFile = File(path.join(androidPath, 'app', 'build.gradle.kts'));
477-
478-
if (groovyFile.existsSync()) {
479-
return groovyFile;
480-
}
481-
482-
return kotlinFile;
483-
}

packages/flutter_tools/lib/src/project.dart

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -467,19 +467,7 @@ class AndroidProject extends FlutterProjectPlatform {
467467
static final RegExp _androidNamespacePattern = RegExp('android {[\\S\\s]+namespace\\s*=?\\s*[\'"](.+)[\'"]');
468468
static final RegExp _applicationIdPattern = RegExp('^\\s*applicationId\\s*=?\\s*[\'"](.*)[\'"]\\s*\$');
469469
static final RegExp _imperativeKotlinPluginPattern = RegExp('^\\s*apply plugin\\:\\s+[\'"]kotlin-android[\'"]\\s*\$');
470-
471-
/// Examples of strings that this regex matches:
472-
/// - `id "kotlin-android"`
473-
/// - `id("kotlin-android")`
474-
/// - `id ( "kotlin-android" ) `
475-
/// - `id "org.jetbrains.kotlin.android"`
476-
/// - `id("org.jetbrains.kotlin.android")`
477-
/// - `id ( "org.jetbrains.kotlin.android" )`
478-
static final List<RegExp> _declarativeKotlinPluginPatterns = <RegExp>[
479-
RegExp('^\\s*id\\s*\\(?\\s*[\'"]kotlin-android[\'"]\\s*\\)?\\s*\$'),
480-
RegExp('^\\s*id\\s*\\(?\\s*[\'"]org.jetbrains.kotlin.android[\'"]\\s*\\)?\\s*\$'),
481-
];
482-
470+
static final RegExp _declarativeKotlinPluginPattern = RegExp('^\\s*id\\s+[\'"]kotlin-android[\'"]\\s*\$');
483471

484472
/// Pattern used to find the assignment of the "group" property in Gradle.
485473
/// Expected example: `group "dev.flutter.plugin"`
@@ -575,9 +563,7 @@ class AndroidProject extends FlutterProjectPlatform {
575563
/// True, if the app project is using Kotlin.
576564
bool get isKotlin {
577565
final bool imperativeMatch = firstMatchInFile(appGradleFile, _imperativeKotlinPluginPattern) != null;
578-
final bool declarativeMatch = _declarativeKotlinPluginPatterns.any((RegExp pattern) {
579-
return (firstMatchInFile(appGradleFile, pattern) != null);
580-
});
566+
final bool declarativeMatch = firstMatchInFile(appGradleFile, _declarativeKotlinPluginPattern) != null;
581567
return imperativeMatch || declarativeMatch;
582568
}
583569

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
plugins {
2-
id("com.android.application")
3-
id("kotlin-android")
2+
id "com.android.application"
3+
id "kotlin-android"
44
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5-
id("dev.flutter.flutter-gradle-plugin")
5+
id "dev.flutter.flutter-gradle-plugin"
66
}
77

88
android {
@@ -16,7 +16,7 @@ android {
1616
}
1717

1818
kotlinOptions {
19-
jvmTarget = JavaVersion.VERSION_1_8.toString()
19+
jvmTarget = JavaVersion.VERSION_1_8
2020
}
2121

2222
defaultConfig {
@@ -34,7 +34,7 @@ android {
3434
release {
3535
// TODO: Add your own signing config for the release build.
3636
// Signing with the debug keys for now, so `flutter run --release` works.
37-
signingConfig = signingConfigs.getByName("debug")
37+
signingConfig = signingConfigs.debug
3838
}
3939
}
4040
}

packages/flutter_tools/templates/app_shared/android-java.tmpl/build.gradle.kts.tmpl

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
allprojects {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
}
6+
}
7+
8+
rootProject.buildDir = "../build"
9+
subprojects {
10+
project.buildDir = "${rootProject.buildDir}/${project.name}"
11+
}
12+
subprojects {
13+
project.evaluationDependsOn(":app")
14+
}
15+
16+
tasks.register("clean", Delete) {
17+
delete rootProject.buildDir
18+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
plugins {
2-
id("com.android.application")
3-
id("kotlin-android")
2+
id "com.android.application"
3+
id "kotlin-android"
44
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5-
id("dev.flutter.flutter-gradle-plugin")
5+
id "dev.flutter.flutter-gradle-plugin"
66
}
77

88
android {
@@ -16,7 +16,7 @@ android {
1616
}
1717

1818
kotlinOptions {
19-
jvmTarget = JavaVersion.VERSION_1_8.toString()
19+
jvmTarget = JavaVersion.VERSION_1_8
2020
}
2121

2222
defaultConfig {
@@ -34,7 +34,7 @@ android {
3434
release {
3535
// TODO: Add your own signing config for the release build.
3636
// Signing with the debug keys for now, so `flutter run --release` works.
37-
signingConfig = signingConfigs.getByName("debug")
37+
signingConfig = signingConfigs.debug
3838
}
3939
}
4040
}

packages/flutter_tools/templates/app_shared/android-kotlin.tmpl/build.gradle.kts.tmpl

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
allprojects {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
}
6+
}
7+
8+
rootProject.buildDir = "../build"
9+
subprojects {
10+
project.buildDir = "${rootProject.buildDir}/${project.name}"
11+
}
12+
subprojects {
13+
project.evaluationDependsOn(":app")
14+
}
15+
16+
tasks.register("clean", Delete) {
17+
delete rootProject.buildDir
18+
}

packages/flutter_tools/templates/app_shared/android.tmpl/settings.gradle.kts.tmpl

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)