Apply multidex config in kotlin dsl gradle file (#114660)

* Apply multidex login in kotlin dsl gradle file

* Cleanup

* Remove plugin parameter passing

* Cleanup

* Restore dependencies block

* Analyzer

* Compiles

* Cleanup

* Cleanup
This commit is contained in:
Gary Qian 2022-11-08 17:52:08 -08:00 committed by GitHub
parent 530324d232
commit 69a542dade
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 17 deletions

View file

@ -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)
@ -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")

View file

@ -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)
}
}
}
}
}
}
}