Skip to content

Commit

Permalink
Apply multidex config in kotlin dsl gradle file (#114660)
Browse files Browse the repository at this point in the history
* Apply multidex login in kotlin dsl gradle file

* Cleanup

* Remove plugin parameter passing

* Cleanup

* Restore dependencies block

* Analyzer

* Compiles

* Cleanup

* Cleanup
  • Loading branch information
GaryQian authored Nov 9, 2022
1 parent 530324d commit 69a542d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
20 changes: 3 additions & 17 deletions packages/flutter_tools/gradle/flutter.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,10 @@ class FlutterPlugin implements Plugin<Project> {
flutterExecutable = Paths.get(flutterRoot.absolutePath, "bin", flutterExecutableName).toFile();

if (project.hasProperty("multidex-enabled") &&
project.property("multidex-enabled").toBoolean() &&
project.android.defaultConfig.minSdkVersion <= 20) {
project.property("multidex-enabled").toBoolean()) {
String flutterMultidexKeepfile = Paths.get(flutterRoot.absolutePath, "packages", "flutter_tools",
"gradle", "flutter_multidex_keepfile.txt")
project.android {
defaultConfig {
multiDexEnabled true
manifestPlaceholders.applicationName = "io.flutter.app.FlutterMultiDexApplication"
}
buildTypes {
release {
multiDexKeepFile project.file(flutterMultidexKeepfile)
Expand All @@ -255,18 +250,9 @@ class FlutterPlugin implements Plugin<Project> {
project.dependencies {
implementation "androidx.multidex:multidex:2.0.1"
}
} else {
String baseApplicationName = "android.app.Application"
if (project.hasProperty("base-application-name")) {
baseApplicationName = project.property("base-application-name")
}
project.android {
defaultConfig {
// Setting to android.app.Application is the same as omitting the attribute.
manifestPlaceholders.applicationName = baseApplicationName
}
}
}
// Use Kotlin DSL to handle baseApplicationName logic due to Groovy dynamic dispatch bug.
project.apply from: Paths.get(flutterRoot.absolutePath, "packages", "flutter_tools", "gradle", "flutter.gradle.kts")

String flutterProguardRules = Paths.get(flutterRoot.absolutePath, "packages", "flutter_tools",
"gradle", "flutter_proguard_rules.pro")
Expand Down
33 changes: 33 additions & 0 deletions packages/flutter_tools/gradle/flutter.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

apply<FlutterPluginKts>()

class FlutterPluginKts : Plugin<Project> {
override fun apply(project: Project) {
// Use withGroovyBuilder and getProperty() to access Groovy metaprogramming.
project.withGroovyBuilder {
getProperty("android").withGroovyBuilder {
getProperty("defaultConfig").withGroovyBuilder {
if (project.hasProperty("multidex-enabled") &&
project.property("multidex-enabled").toString().toBoolean()) {
setProperty("multiDexEnabled", true)
getProperty("manifestPlaceholders").withGroovyBuilder {
setProperty("applicationName", "io.flutter.app.FlutterMultiDexApplication")
}
} else {
var baseApplicationName: String = "android.app.Application"
if (project.hasProperty("base-application-name")) {
baseApplicationName = project.property("base-application-name").toString()
}
// Setting to android.app.Application is the same as omitting the attribute.
getProperty("manifestPlaceholders").withGroovyBuilder {
setProperty("applicationName", baseApplicationName)
}
}
}
}
}
}
}

0 comments on commit 69a542d

Please sign in to comment.