From 69a542dadec8da32550a95381df8b074cf943c09 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Tue, 8 Nov 2022 17:52:08 -0800 Subject: [PATCH] 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 --- packages/flutter_tools/gradle/flutter.gradle | 20 ++--------- .../flutter_tools/gradle/flutter.gradle.kts | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 packages/flutter_tools/gradle/flutter.gradle.kts diff --git a/packages/flutter_tools/gradle/flutter.gradle b/packages/flutter_tools/gradle/flutter.gradle index defe000c84cb..18b3f9af843c 100644 --- a/packages/flutter_tools/gradle/flutter.gradle +++ b/packages/flutter_tools/gradle/flutter.gradle @@ -237,15 +237,10 @@ class FlutterPlugin implements Plugin { 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.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") diff --git a/packages/flutter_tools/gradle/flutter.gradle.kts b/packages/flutter_tools/gradle/flutter.gradle.kts new file mode 100644 index 000000000000..78bcafb97b4b --- /dev/null +++ b/packages/flutter_tools/gradle/flutter.gradle.kts @@ -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() + +class FlutterPluginKts : Plugin { + 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) + } + } + } + } + } + } +}