Unverified Commit d6e435a7 authored by Reid Baker's avatar Reid Baker Committed by GitHub

Part 1/n migration steps for kotlin migration (#140452)

Following https://developer.android.com/build/migrate-to-kotlin-dsl
1/n Add parentheses to method calls 

Should be a no-op change. If you see a behavioral change please flag it.
parent 9003f138
......@@ -183,9 +183,9 @@ class FlutterPlugin implements Plugin<Project> {
def gradlew = (OperatingSystem.current().isWindows()) ?
"${rootProject.projectDir}/gradlew.bat" : "${rootProject.projectDir}/gradlew"
rootProject.exec {
workingDir rootProject.projectDir
executable gradlew
args ":${subproject.name}:dependencies", "--write-locks"
workingDir(rootProject.projectDir)
executable(gradlew)
args(":${subproject.name}:dependencies", "--write-locks")
}
}
}
......@@ -217,7 +217,7 @@ class FlutterPlugin implements Plugin<Project> {
rootProject.allprojects {
repositories {
maven {
url repository
url(repository)
}
}
}
......@@ -233,11 +233,11 @@ class FlutterPlugin implements Plugin<Project> {
splits {
abi {
// Enables building multiple APKs per ABI.
enable true
enable(true)
// Resets the list of ABIs that Gradle should create APKs for to none.
reset()
// Specifies that we do not want to also generate a universal APK that includes all ABIs.
universalApk false
universalApk(false)
}
}
}
......@@ -256,7 +256,7 @@ class FlutterPlugin implements Plugin<Project> {
if (shouldSplitPerAbi()) {
splits {
abi {
include abiValue
include(abiValue)
}
}
}
......@@ -273,12 +273,12 @@ class FlutterPlugin implements Plugin<Project> {
project.android {
buildTypes {
release {
multiDexKeepFile project.file(flutterMultidexKeepfile)
multiDexKeepFile(project.file(flutterMultidexKeepfile))
}
}
}
project.dependencies {
implementation "androidx.multidex:multidex:2.0.1"
implementation("androidx.multidex:multidex:2.0.1")
}
}
// Use Kotlin DSL to handle baseApplicationName logic due to Groovy dynamic dispatch bug.
......@@ -289,7 +289,7 @@ class FlutterPlugin implements Plugin<Project> {
project.android.buildTypes {
// Add profile build type.
profile {
initWith debug
initWith(debug)
if (it.hasProperty("matchingFallbacks")) {
matchingFallbacks = ["debug", "release"]
}
......@@ -302,13 +302,13 @@ class FlutterPlugin implements Plugin<Project> {
release {
// Enables code shrinking, obfuscation, and optimization for only
// your project's release build type.
minifyEnabled true
minifyEnabled(true)
// Enables resource shrinking, which is performed by the Android Gradle plugin.
// The resource shrinker can't be used for libraries.
shrinkResources isBuiltAsApp(project)
shrinkResources(isBuiltAsApp(project))
// Fallback to `android/app/proguard-rules.pro`.
// This way, custom Proguard rules can be configured as needed.
proguardFiles project.android.getDefaultProguardFile("proguard-android.txt"), flutterProguardRules, "proguard-rules.pro"
proguardFiles(project.android.getDefaultProguardFile("proguard-android.txt"), flutterProguardRules, "proguard-rules.pro")
}
}
}
......@@ -330,7 +330,7 @@ class FlutterPlugin implements Plugin<Project> {
}
localEngineHost = engineHostOut.name
}
project.android.buildTypes.all this.&addFlutterDependencies
project.android.buildTypes.all(this.&addFlutterDependencies)
}
private static Boolean shouldShrinkResources(Project project) {
......@@ -394,8 +394,8 @@ class FlutterPlugin implements Plugin<Project> {
* Finally, the project's `settings.gradle` loads each plugin's android directory as a subproject.
*/
private void configurePlugins() {
getPluginList().each this.&configurePluginProject
getPluginDependencies().each this.&configurePluginDependencies
getPluginList().each(this.&configurePluginProject)
getPluginDependencies().each(this.&configurePluginDependencies)
}
/** Adds the plugin project dependency to the app project. */
......@@ -407,7 +407,7 @@ class FlutterPlugin implements Plugin<Project> {
}
// Add plugin dependency to the app project.
project.dependencies {
api pluginProject
api(pluginProject)
}
Closure addEmbeddingDependencyToPlugin = { buildType ->
String flutterBuildMode = buildModeFor(buildType)
......@@ -445,7 +445,7 @@ class FlutterPlugin implements Plugin<Project> {
project.logger.quiet("For more information about build configuration, see $kWebsiteDeploymentAndroidBuildConfig.")
}
project.android.buildTypes.all addEmbeddingDependencyToPlugin
project.android.buildTypes.all(addEmbeddingDependencyToPlugin)
}
}
......@@ -544,15 +544,15 @@ class FlutterPlugin implements Plugin<Project> {
* making the Gradle plugin project A depend on the Gradle plugin project B.
*/
private void configurePluginDependencies(Object dependencyObject) {
assert dependencyObject.name instanceof String
assert(dependencyObject.name instanceof String)
Project pluginProject = project.rootProject.findProject(":${dependencyObject.name}")
if (pluginProject == null ||
!doesSupportAndroidPlatform(pluginProject.projectDir.parentFile.path)) {
return
}
assert dependencyObject.dependencies instanceof List
assert(dependencyObject.dependencies instanceof List)
dependencyObject.dependencies.each { pluginDependencyName ->
assert pluginDependencyName instanceof String
assert(pluginDependencyName instanceof String)
if (pluginDependencyName.empty) {
return
}
......@@ -564,7 +564,7 @@ class FlutterPlugin implements Plugin<Project> {
// Wait for the Android plugin to load and add the dependency to the plugin project.
pluginProject.afterEvaluate {
pluginProject.dependencies {
implementation dependencyProject
implementation(dependencyProject)
}
}
}
......@@ -578,9 +578,9 @@ class FlutterPlugin implements Plugin<Project> {
if (doesSupportAndroidPlatform(path)) {
androidPlugins.setProperty(name, path)
}
// TODO(amirh): log an error if this plugin was specified to be an Android
// plugin according to the new schema, and was missing a build.gradle file.
// https://github.com/flutter/flutter/issues/40784
// TODO(amirh): log an error if this plugin was specified to be an Android
// plugin according to the new schema, and was missing a build.gradle file.
// https://github.com/flutter/flutter/issues/40784
}
return androidPlugins
}
......@@ -611,8 +611,8 @@ class FlutterPlugin implements Plugin<Project> {
File pluginsDependencyFile = new File(project.projectDir.parentFile.parentFile, '.flutter-plugins-dependencies')
if (pluginsDependencyFile.exists()) {
def object = new JsonSlurper().parseText(pluginsDependencyFile.text)
assert object instanceof Map
assert object.dependencyGraph instanceof List
assert(object instanceof Map)
assert(object.dependencyGraph instanceof List)
return object.dependencyGraph
}
return []
......@@ -694,7 +694,7 @@ class FlutterPlugin implements Plugin<Project> {
if (!useLocalEngine()) {
return true;
}
assert project.hasProperty('local-engine-build-mode')
assert(project.hasProperty('local-engine-build-mode'))
// Don't configure dependencies for a build mode that the local engine
// doesn't support.
return project.property('local-engine-build-mode') == flutterBuildMode
......@@ -1066,36 +1066,36 @@ class FlutterPlugin implements Plugin<Project> {
// into a separate variable `verbose verboseValue` or prefix with
// `this` (`verbose this.isVerbose()`).
FlutterTask compileTask = project.tasks.create(name: taskName, type: FlutterTask) {
flutterRoot this.flutterRoot
flutterExecutable this.flutterExecutable
buildMode variantBuildMode
minSdkVersion variant.mergedFlavor.minSdkVersion.apiLevel
localEngine this.localEngine
localEngineHost this.localEngineHost
localEngineSrcPath this.localEngineSrcPath
targetPath getFlutterTarget()
verbose this.isVerbose()
fastStart this.isFastStart()
fileSystemRoots fileSystemRootsValue
fileSystemScheme fileSystemSchemeValue
trackWidgetCreation trackWidgetCreationValue
flutterRoot(this.flutterRoot)
flutterExecutable(this.flutterExecutable)
buildMode(variantBuildMode)
minSdkVersion(variant.mergedFlavor.minSdkVersion.apiLevel)
localEngine(this.localEngine)
localEngineHost(this.localEngineHost)
localEngineSrcPath(this.localEngineSrcPath)
targetPath(getFlutterTarget())
verbose(this.isVerbose())
fastStart(this.isFastStart())
fileSystemRoots(fileSystemRootsValue)
fileSystemScheme(fileSystemSchemeValue)
trackWidgetCreation(trackWidgetCreationValue)
targetPlatformValues = targetPlatforms
sourceDir getFlutterSourceDirectory()
intermediateDir project.file("${project.buildDir}/$INTERMEDIATES_DIR/flutter/${variant.name}/")
frontendServerStarterPath frontendServerStarterPathValue
extraFrontEndOptions extraFrontEndOptionsValue
extraGenSnapshotOptions extraGenSnapshotOptionsValue
splitDebugInfo splitDebugInfoValue
treeShakeIcons treeShakeIconsOptionsValue
dartObfuscation dartObfuscationValue
dartDefines dartDefinesValue
bundleSkSLPath bundleSkSLPathValue
performanceMeasurementFile performanceMeasurementFileValue
codeSizeDirectory codeSizeDirectoryValue
deferredComponents deferredComponentsValue
validateDeferredComponents validateDeferredComponentsValue
isAndroidLibrary isAndroidLibraryValue
flavor flavorValue
sourceDir(getFlutterSourceDirectory())
intermediateDir(project.file("${project.buildDir}/$INTERMEDIATES_DIR/flutter/${variant.name}/"))
frontendServerStarterPath(frontendServerStarterPathValue)
extraFrontEndOptions(extraFrontEndOptionsValue)
extraGenSnapshotOptions(extraGenSnapshotOptionsValue)
splitDebugInfo(splitDebugInfoValue)
treeShakeIcons(treeShakeIconsOptionsValue)
dartObfuscation(dartObfuscationValue)
dartDefines(dartDefinesValue)
bundleSkSLPath(bundleSkSLPathValue)
performanceMeasurementFile(performanceMeasurementFileValue)
codeSizeDirectory(codeSizeDirectoryValue)
deferredComponents(deferredComponentsValue)
validateDeferredComponents(validateDeferredComponentsValue)
isAndroidLibrary(isAndroidLibraryValue)
flavor(flavorValue)
}
File libJar = project.file("${project.buildDir}/$INTERMEDIATES_DIR/flutter/${variant.name}/libs.jar")
Task packFlutterAppAotTask = project.tasks.create(name: "packLibs${FLUTTER_BUILD_PREFIX}${variant.name.capitalize()}", type: Jar) {
......@@ -1120,13 +1120,13 @@ class FlutterPlugin implements Plugin<Project> {
name: "copyFlutterAssets${variant.name.capitalize()}",
type: Copy,
) {
dependsOn compileTask
with compileTask.assets
dependsOn(compileTask)
with(compileTask.assets)
def currentGradleVersion = project.getGradle().getGradleVersion()
// See https://docs.gradle.org/current/javadoc/org/gradle/api/file/ConfigurableFilePermissions.html
// See https://github.com/flutter/flutter/pull/50047
if (compareVersionStrings(currentGradleVersion, '8.3') >= 0 ) {
if (compareVersionStrings(currentGradleVersion, '8.3') >= 0) {
filePermissions {
user {
read = true
......@@ -1136,21 +1136,21 @@ class FlutterPlugin implements Plugin<Project> {
} else {
// See https://docs.gradle.org/8.2/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:fileMode
// See https://github.com/flutter/flutter/pull/50047
fileMode 0644
fileMode(0644)
}
if (isUsedAsSubproject) {
dependsOn packageAssets
dependsOn cleanPackageAssets
into packageAssets.outputDir
dependsOn(packageAssets)
dependsOn(cleanPackageAssets)
into(packageAssets.outputDir)
return
}
// `variant.mergeAssets` will be removed at the end of 2019.
def mergeAssets = variant.hasProperty("mergeAssetsProvider") ?
variant.mergeAssetsProvider.get() : variant.mergeAssets
dependsOn mergeAssets
dependsOn "clean${mergeAssets.name.capitalize()}"
dependsOn(mergeAssets)
dependsOn("clean${mergeAssets.name.capitalize()}")
mergeAssets.mustRunAfter("clean${mergeAssets.name.capitalize()}")
into mergeAssets.outputDir
into(mergeAssets.outputDir)
}
if (!isUsedAsSubproject) {
def variantOutput = variant.outputs.first()
......@@ -1163,12 +1163,12 @@ class FlutterPlugin implements Plugin<Project> {
// See https://docs.gradle.org/8.1/userguide/validation_problems.html#implicit_dependency.
def compressAssetsTask = project.tasks.findByName("compress${variant.name.capitalize()}Assets")
if (compressAssetsTask) {
compressAssetsTask.dependsOn copyFlutterAssetsTask
compressAssetsTask.dependsOn(copyFlutterAssetsTask)
}
def bundleAarTask = project.tasks.findByName("bundle${variant.name.capitalize()}Aar")
if (bundleAarTask) {
bundleAarTask.dependsOn copyFlutterAssetsTask
bundleAarTask.dependsOn(copyFlutterAssetsTask)
}
return copyFlutterAssetsTask
......@@ -1224,7 +1224,7 @@ class FlutterPlugin implements Plugin<Project> {
}
// Copy the native assets created by build.dart and placed here by flutter assemble.
def nativeAssetsDir = "${project.buildDir}/../native_assets/android/jniLibs/lib/"
project.android.sourceSets.main.jniLibs.srcDir nativeAssetsDir
project.android.sourceSets.main.jniLibs.srcDir(nativeAssetsDir)
}
configurePlugins()
detectLowCompileSdkVersionOrNdkVersion()
......@@ -1233,10 +1233,10 @@ class FlutterPlugin implements Plugin<Project> {
// Flutter host module project (Add-to-app).
String hostAppProjectName = project.rootProject.hasProperty('flutter.hostAppProjectName') ? project.rootProject.property('flutter.hostAppProjectName') : "app"
Project appProject = project.rootProject.findProject(":${hostAppProjectName}")
assert appProject != null : "Project :${hostAppProjectName} doesn't exist. To customize the host app project name, set `flutter.hostAppProjectName=<project-name>` in gradle.properties."
assert(appProject != null) : "Project :${hostAppProjectName} doesn't exist. To customize the host app project name, set `flutter.hostAppProjectName=<project-name>` in gradle.properties."
// Wait for the host app project configuration.
appProject.afterEvaluate {
assert appProject.android != null
assert(appProject.android != null)
project.android.libraryVariants.all { libraryVariant ->
Task copyFlutterAssetsTask
appProject.android.applicationVariants.all { appProjectVariant ->
......@@ -1273,7 +1273,7 @@ class FlutterPlugin implements Plugin<Project> {
Task mergeAssets = project
.tasks
.findByPath(":${hostAppProjectName}:merge${appProjectVariant.name.capitalize()}Assets")
assert mergeAssets
assert(mergeAssets)
mergeAssets.dependsOn(copyFlutterAssetsTask)
}
}
......@@ -1303,11 +1303,14 @@ class FlutterPlugin implements Plugin<Project> {
// If we got this far then all the common indices are identical, so whichever version is longer must be more recent
return firstVersion.size() <=> secondVersion.size()
}
}
class AppLinkSettings {
String applicationId
Set<Deeplink> deeplinks
}
class Deeplink {
......@@ -1414,9 +1417,9 @@ abstract class BaseFlutterTask extends DefaultTask {
ruleNames = targetPlatformValues.collect { "android_aot_bundle_${buildMode}_$it" }
}
project.exec {
logging.captureStandardError LogLevel.ERROR
executable flutterExecutable.absolutePath
workingDir sourceDir
logging.captureStandardError(LogLevel.ERROR)
executable(flutterExecutable.absolutePath)
workingDir(sourceDir)
if (localEngine != null) {
args "--local-engine", localEngine
args "--local-engine-src-path", localEngineSrcPath
......@@ -1429,59 +1432,59 @@ abstract class BaseFlutterTask extends DefaultTask {
} else {
args "--quiet"
}
args "assemble"
args "--no-version-check"
args "--depfile", "${intermediateDir}/flutter_build.d"
args "--output", "${intermediateDir}"
args("assemble")
args("--no-version-check")
args("--depfile", "${intermediateDir}/flutter_build.d")
args("--output", "${intermediateDir}")
if (performanceMeasurementFile != null) {
args "--performance-measurement-file=${performanceMeasurementFile}"
args("--performance-measurement-file=${performanceMeasurementFile}")
}
if (!fastStart || buildMode != "debug") {
args "-dTargetFile=${targetPath}"
args("-dTargetFile=${targetPath}")
} else {
args "-dTargetFile=${Paths.get(flutterRoot.absolutePath, "examples", "splash", "lib", "main.dart")}"
args("-dTargetFile=${Paths.get(flutterRoot.absolutePath, "examples", "splash", "lib", "main.dart")}")
}
args "-dTargetPlatform=android"
args "-dBuildMode=${buildMode}"
args("-dTargetPlatform=android")
args("-dBuildMode=${buildMode}")
if (trackWidgetCreation != null) {
args "-dTrackWidgetCreation=${trackWidgetCreation}"
args("-dTrackWidgetCreation=${trackWidgetCreation}")
}
if (splitDebugInfo != null) {
args "-dSplitDebugInfo=${splitDebugInfo}"
args("-dSplitDebugInfo=${splitDebugInfo}")
}
if (treeShakeIcons == true) {
args "-dTreeShakeIcons=true"
args("-dTreeShakeIcons=true")
}
if (dartObfuscation == true) {
args "-dDartObfuscation=true"
args("-dDartObfuscation=true")
}
if (dartDefines != null) {
args "--DartDefines=${dartDefines}"
args("--DartDefines=${dartDefines}")
}
if (bundleSkSLPath != null) {
args "-dBundleSkSLPath=${bundleSkSLPath}"
args("-dBundleSkSLPath=${bundleSkSLPath}")
}
if (codeSizeDirectory != null) {
args "-dCodeSizeDirectory=${codeSizeDirectory}"
args("-dCodeSizeDirectory=${codeSizeDirectory}")
}
if (flavor != null) {
args "-dFlavor=${flavor}"
args("-dFlavor=${flavor}")
}
if (extraGenSnapshotOptions != null) {
args "--ExtraGenSnapshotOptions=${extraGenSnapshotOptions}"
args("--ExtraGenSnapshotOptions=${extraGenSnapshotOptions}")
}
if (frontendServerStarterPath != null) {
args "-dFrontendServerStarterPath=${frontendServerStarterPath}"
args("-dFrontendServerStarterPath=${frontendServerStarterPath}")
}
if (extraFrontEndOptions != null) {
args "--ExtraFrontEndOptions=${extraFrontEndOptions}"
args("--ExtraFrontEndOptions=${extraFrontEndOptions}")
}
args "-dAndroidArchs=${targetPlatformValues.join(' ')}"
args "-dMinSdkVersion=${minSdkVersion}"
args("-dAndroidArchs=${targetPlatformValues.join(' ')}")
args("-dMinSdkVersion=${minSdkVersion}")
if (isAndroidLibrary != null) {
args "-dIsAndroidLibrary=${isAndroidLibrary ? "true" : "false"}"
args("-dIsAndroidLibrary=${isAndroidLibrary ? "true" : "false"}")
}
args ruleNames
args(ruleNames)
}
}
}
......@@ -1500,19 +1503,19 @@ class FlutterTask extends BaseFlutterTask {
@Internal
CopySpec getAssets() {
return project.copySpec {
from "${intermediateDir}"
include "flutter_assets/**" // the working dir and its files
from("${intermediateDir}")
include("flutter_assets/**") // the working dir and its files
}
}
@Internal
CopySpec getSnapshots() {
return project.copySpec {
from "${intermediateDir}"
from("${intermediateDir}")
if (buildMode == 'release' || buildMode == 'profile') {
targetPlatformValues.each {
include "${PLATFORM_ARCH_MAP[targetArch]}/app.so"
include("${PLATFORM_ARCH_MAP[targetArch]}/app.so")
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment