Skip to content

Commit 69a542d

Browse files
authored
Apply multidex config in kotlin dsl gradle file (flutter#114660)
* Apply multidex login in kotlin dsl gradle file * Cleanup * Remove plugin parameter passing * Cleanup * Restore dependencies block * Analyzer * Compiles * Cleanup * Cleanup
1 parent 530324d commit 69a542d

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

packages/flutter_tools/gradle/flutter.gradle

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,10 @@ class FlutterPlugin implements Plugin<Project> {
237237
flutterExecutable = Paths.get(flutterRoot.absolutePath, "bin", flutterExecutableName).toFile();
238238

239239
if (project.hasProperty("multidex-enabled") &&
240-
project.property("multidex-enabled").toBoolean() &&
241-
project.android.defaultConfig.minSdkVersion <= 20) {
240+
project.property("multidex-enabled").toBoolean()) {
242241
String flutterMultidexKeepfile = Paths.get(flutterRoot.absolutePath, "packages", "flutter_tools",
243242
"gradle", "flutter_multidex_keepfile.txt")
244243
project.android {
245-
defaultConfig {
246-
multiDexEnabled true
247-
manifestPlaceholders.applicationName = "io.flutter.app.FlutterMultiDexApplication"
248-
}
249244
buildTypes {
250245
release {
251246
multiDexKeepFile project.file(flutterMultidexKeepfile)
@@ -255,18 +250,9 @@ class FlutterPlugin implements Plugin<Project> {
255250
project.dependencies {
256251
implementation "androidx.multidex:multidex:2.0.1"
257252
}
258-
} else {
259-
String baseApplicationName = "android.app.Application"
260-
if (project.hasProperty("base-application-name")) {
261-
baseApplicationName = project.property("base-application-name")
262-
}
263-
project.android {
264-
defaultConfig {
265-
// Setting to android.app.Application is the same as omitting the attribute.
266-
manifestPlaceholders.applicationName = baseApplicationName
267-
}
268-
}
269253
}
254+
// Use Kotlin DSL to handle baseApplicationName logic due to Groovy dynamic dispatch bug.
255+
project.apply from: Paths.get(flutterRoot.absolutePath, "packages", "flutter_tools", "gradle", "flutter.gradle.kts")
270256

271257
String flutterProguardRules = Paths.get(flutterRoot.absolutePath, "packages", "flutter_tools",
272258
"gradle", "flutter_proguard_rules.pro")
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
apply<FlutterPluginKts>()
6+
7+
class FlutterPluginKts : Plugin<Project> {
8+
override fun apply(project: Project) {
9+
// Use withGroovyBuilder and getProperty() to access Groovy metaprogramming.
10+
project.withGroovyBuilder {
11+
getProperty("android").withGroovyBuilder {
12+
getProperty("defaultConfig").withGroovyBuilder {
13+
if (project.hasProperty("multidex-enabled") &&
14+
project.property("multidex-enabled").toString().toBoolean()) {
15+
setProperty("multiDexEnabled", true)
16+
getProperty("manifestPlaceholders").withGroovyBuilder {
17+
setProperty("applicationName", "io.flutter.app.FlutterMultiDexApplication")
18+
}
19+
} else {
20+
var baseApplicationName: String = "android.app.Application"
21+
if (project.hasProperty("base-application-name")) {
22+
baseApplicationName = project.property("base-application-name").toString()
23+
}
24+
// Setting to android.app.Application is the same as omitting the attribute.
25+
getProperty("manifestPlaceholders").withGroovyBuilder {
26+
setProperty("applicationName", baseApplicationName)
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)