From ac456d28becade9bdec4b7cd09cba78f40d6bf6c Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Fri, 1 Nov 2024 15:14:50 -0700 Subject: [PATCH 01/11] first attempt --- packages/animations/example/.metadata | 24 ++++++- .../animations/example/android/.gitignore | 6 ++ .../example/android/.pluginToolsConfig.yaml | 4 -- .../example/android/app/build.gradle | 72 +++++++------------ .../android/app/src/debug/AndroidManifest.xml | 3 +- .../android/app/src/main/AndroidManifest.xml | 23 +++++- .../animations/example/MainActivity.kt | 5 +- .../res/drawable-v21/launch_background.xml | 12 ++++ .../app/src/main/res/values-night/styles.xml | 18 +++++ .../app/src/main/res/values/styles.xml | 14 +++- .../app/src/profile/AndroidManifest.xml | 3 +- .../animations/example/android/build.gradle | 23 +----- .../example/android/gradle.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 3 +- .../example/android/settings.gradle | 41 +++++------ 15 files changed, 144 insertions(+), 109 deletions(-) delete mode 100644 packages/animations/example/android/.pluginToolsConfig.yaml create mode 100644 packages/animations/example/android/app/src/main/res/drawable-v21/launch_background.xml create mode 100644 packages/animations/example/android/app/src/main/res/values-night/styles.xml diff --git a/packages/animations/example/.metadata b/packages/animations/example/.metadata index 6b34df6b1f37..706ff779c7b7 100644 --- a/packages/animations/example/.metadata +++ b/packages/animations/example/.metadata @@ -4,7 +4,27 @@ # This file should be version controlled and should not be manually edited. version: - revision: 0bced151e44ffa138e608c2e2dbff3309ab8bd75 - channel: master + revision: "603104015dd692ea3403755b55d07813d5cf8965" + channel: "stable" project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 603104015dd692ea3403755b55d07813d5cf8965 + base_revision: 603104015dd692ea3403755b55d07813d5cf8965 + - platform: android + create_revision: 603104015dd692ea3403755b55d07813d5cf8965 + base_revision: 603104015dd692ea3403755b55d07813d5cf8965 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/animations/example/android/.gitignore b/packages/animations/example/android/.gitignore index bc2100d8f75e..55afd919c659 100644 --- a/packages/animations/example/android/.gitignore +++ b/packages/animations/example/android/.gitignore @@ -5,3 +5,9 @@ gradle-wrapper.jar /gradlew.bat /local.properties GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/to/reference-keystore +key.properties +**/*.keystore +**/*.jks diff --git a/packages/animations/example/android/.pluginToolsConfig.yaml b/packages/animations/example/android/.pluginToolsConfig.yaml deleted file mode 100644 index 3b6017b7609a..000000000000 --- a/packages/animations/example/android/.pluginToolsConfig.yaml +++ /dev/null @@ -1,4 +0,0 @@ -buildFlags: - _pluginToolsConfigGlobalKey: - - "--no-tree-shake-icons" - - "--dart-define=buildmode=testing" diff --git a/packages/animations/example/android/app/build.gradle b/packages/animations/example/android/app/build.gradle index f807599056dc..5fee8c977ea2 100644 --- a/packages/animations/example/android/app/build.gradle +++ b/packages/animations/example/android/app/build.gradle @@ -1,68 +1,44 @@ -def localProperties = new Properties() -def localPropertiesFile = rootProject.file('local.properties') -if (localPropertiesFile.exists()) { - localPropertiesFile.withReader('UTF-8') { reader -> - localProperties.load(reader) - } -} - -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - -def flutterVersionCode = localProperties.getProperty('flutter.versionCode') -if (flutterVersionCode == null) { - flutterVersionCode = '1' -} - -def flutterVersionName = localProperties.getProperty('flutter.versionName') -if (flutterVersionName == null) { - flutterVersionName = '1.0' +plugins { + id "com.android.application" + id "kotlin-android" + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id "dev.flutter.flutter-gradle-plugin" } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { - namespace 'dev.flutter.packages.animations.example' - compileSdk flutter.compileSdkVersion + namespace = "dev.flutter.packages.animations.example" + compileSdk = flutter.compileSdkVersion + ndkVersion = flutter.ndkVersion - sourceSets { - main.java.srcDirs += 'src/main/kotlin' + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8 + } defaultConfig { - applicationId "dev.flutter.packages.animations.example" - minSdkVersion flutter.minSdkVersion - targetSdkVersion 32 - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId = "dev.flutter.packages.animations.example" + // You can update the following values to match your application needs. + // For more information, see: https://flutter.dev/to/review-gradle-config. + minSdk = flutter.minSdkVersion + targetSdk = flutter.targetSdkVersion + versionCode = flutter.versionCode + versionName = flutter.versionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug + signingConfig = signingConfigs.debug } } - namespace 'dev.flutter.packages.animations.example' - lint { - disable 'InvalidPackage' - } } flutter { - source '../..' -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + source = "../.." } diff --git a/packages/animations/example/android/app/src/debug/AndroidManifest.xml b/packages/animations/example/android/app/src/debug/AndroidManifest.xml index f880684a6a9c..399f6981d5d3 100644 --- a/packages/animations/example/android/app/src/debug/AndroidManifest.xml +++ b/packages/animations/example/android/app/src/debug/AndroidManifest.xml @@ -1,5 +1,6 @@ - diff --git a/packages/animations/example/android/app/src/main/AndroidManifest.xml b/packages/animations/example/android/app/src/main/AndroidManifest.xml index 3adb2679c59a..74a78b939e5e 100644 --- a/packages/animations/example/android/app/src/main/AndroidManifest.xml +++ b/packages/animations/example/android/app/src/main/AndroidManifest.xml @@ -1,15 +1,25 @@ + + @@ -21,4 +31,15 @@ android:name="flutterEmbedding" android:value="2" /> + + + + + + + diff --git a/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt b/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt index 98673b425d1f..4ed7a6686aa6 100644 --- a/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt +++ b/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt @@ -1,8 +1,5 @@ -// Copyright 2013 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. package dev.flutter.packages.animations.example import io.flutter.embedding.android.FlutterActivity -class MainActivity : FlutterActivity() {} +class MainActivity: FlutterActivity() diff --git a/packages/animations/example/android/app/src/main/res/drawable-v21/launch_background.xml b/packages/animations/example/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 000000000000..f74085f3f6a2 --- /dev/null +++ b/packages/animations/example/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/packages/animations/example/android/app/src/main/res/values-night/styles.xml b/packages/animations/example/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 000000000000..06952be745f9 --- /dev/null +++ b/packages/animations/example/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/packages/animations/example/android/app/src/main/res/values/styles.xml b/packages/animations/example/android/app/src/main/res/values/styles.xml index 00fa4417cfbe..cb1ef88056ed 100644 --- a/packages/animations/example/android/app/src/main/res/values/styles.xml +++ b/packages/animations/example/android/app/src/main/res/values/styles.xml @@ -1,8 +1,18 @@ - + + diff --git a/packages/animations/example/android/app/src/profile/AndroidManifest.xml b/packages/animations/example/android/app/src/profile/AndroidManifest.xml index f880684a6a9c..399f6981d5d3 100644 --- a/packages/animations/example/android/app/src/profile/AndroidManifest.xml +++ b/packages/animations/example/android/app/src/profile/AndroidManifest.xml @@ -1,5 +1,6 @@ - diff --git a/packages/animations/example/android/build.gradle b/packages/animations/example/android/build.gradle index 491936f2fbef..d2ffbffa4cd2 100644 --- a/packages/animations/example/android/build.gradle +++ b/packages/animations/example/android/build.gradle @@ -1,35 +1,16 @@ -buildscript { - ext.kotlin_version = '1.7.10' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:8.5.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { - // See https://github.com/flutter/flutter/blob/master/docs/ecosystem/Plugins-and-Packages-repository-structure.md#gradle-structure for more info. - def artifactRepoKey = 'ARTIFACT_HUB_REPOSITORY' - if (System.getenv().containsKey(artifactRepoKey)) { - println "Using artifact hub" - maven { url System.getenv(artifactRepoKey) } - } google() mavenCentral() } } -rootProject.buildDir = '../build' +rootProject.buildDir = "../build" subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { - project.evaluationDependsOn(':app') + project.evaluationDependsOn(":app") } tasks.register("clean", Delete) { diff --git a/packages/animations/example/android/gradle.properties b/packages/animations/example/android/gradle.properties index 94adc3a3f97a..259717082164 100644 --- a/packages/animations/example/android/gradle.properties +++ b/packages/animations/example/android/gradle.properties @@ -1,3 +1,3 @@ -org.gradle.jvmargs=-Xmx1536M +org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError android.useAndroidX=true android.enableJetifier=true diff --git a/packages/animations/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/animations/example/android/gradle/wrapper/gradle-wrapper.properties index 7aeeb11c6ee5..7bb2df6ba6ea 100644 --- a/packages/animations/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/animations/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jun 23 08:50:38 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip diff --git a/packages/animations/example/android/settings.gradle b/packages/animations/example/android/settings.gradle index 32735a3cfd4b..b9e43bd37614 100644 --- a/packages/animations/example/android/settings.gradle +++ b/packages/animations/example/android/settings.gradle @@ -1,28 +1,25 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -def plugins = new Properties() -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') -if (pluginsFile.exists()) { - pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } } -plugins.each { name, path -> - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() - include ":$name" - project(":$name").projectDir = pluginDirectory +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "8.1.0" apply false + id "org.jetbrains.kotlin.android" version "1.8.22" apply false } -// See https://github.com/flutter/flutter/blob/master/docs/ecosystem/Plugins-and-Packages-repository-structure.md#gradle-structure for more info. -buildscript { - repositories { - maven { - url "https://plugins.gradle.org/m2/" - } - } - dependencies { - classpath "gradle.plugin.com.google.cloud.artifactregistry:artifactregistry-gradle-plugin:2.2.1" - } -} -apply plugin: "com.google.cloud.artifactregistry.gradle-plugin" +include ":app" From 2da35298030a3110dfe30ec733d8d7e23d47a27d Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Fri, 1 Nov 2024 15:18:54 -0700 Subject: [PATCH 02/11] Undo changes I did not like --- packages/animations/example/android/.pluginToolsConfig.yaml | 5 +++++ .../example/android/gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 packages/animations/example/android/.pluginToolsConfig.yaml diff --git a/packages/animations/example/android/.pluginToolsConfig.yaml b/packages/animations/example/android/.pluginToolsConfig.yaml new file mode 100644 index 000000000000..a7a66380498d --- /dev/null +++ b/packages/animations/example/android/.pluginToolsConfig.yaml @@ -0,0 +1,5 @@ +buildFlags: + _pluginToolsConfigGlobalKey: + - "--no-tree-shake-icons" + - "--dart-define=buildmode=testing" + \ No newline at end of file diff --git a/packages/animations/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/animations/example/android/gradle/wrapper/gradle-wrapper.properties index 7bb2df6ba6ea..3c85cfe057a1 100644 --- a/packages/animations/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/animations/example/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip From 3a52373855b62dd0761f98c1f570f81336621361 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Fri, 1 Nov 2024 15:38:04 -0700 Subject: [PATCH 03/11] remove spaces --- packages/animations/example/android/.pluginToolsConfig.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/animations/example/android/.pluginToolsConfig.yaml b/packages/animations/example/android/.pluginToolsConfig.yaml index a7a66380498d..3b6017b7609a 100644 --- a/packages/animations/example/android/.pluginToolsConfig.yaml +++ b/packages/animations/example/android/.pluginToolsConfig.yaml @@ -2,4 +2,3 @@ buildFlags: _pluginToolsConfigGlobalKey: - "--no-tree-shake-icons" - "--dart-define=buildmode=testing" - \ No newline at end of file From eb88da3f4cbc22f4c4ca0e4213d78de7ff97e6bf Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Tue, 5 Nov 2024 10:29:10 -0800 Subject: [PATCH 04/11] Try modifying kotlin options --- packages/animations/example/android/app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/animations/example/android/app/build.gradle b/packages/animations/example/android/app/build.gradle index b6d278df149b..72e23cdc9455 100644 --- a/packages/animations/example/android/app/build.gradle +++ b/packages/animations/example/android/app/build.gradle @@ -24,7 +24,7 @@ android { } kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8 + jvmTarget = JavaVersion.VERSION_11 } defaultConfig { From 0a59b040ccd71d3b9837010789351acd270464e5 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Tue, 5 Nov 2024 10:29:49 -0800 Subject: [PATCH 05/11] remove duplicate kotlinOptions block --- packages/animations/example/android/app/build.gradle | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/animations/example/android/app/build.gradle b/packages/animations/example/android/app/build.gradle index 72e23cdc9455..7358c5b028a2 100644 --- a/packages/animations/example/android/app/build.gradle +++ b/packages/animations/example/android/app/build.gradle @@ -23,10 +23,6 @@ android { main.java.srcDirs += 'src/main/kotlin' } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_11 - } - defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId = "dev.flutter.packages.animations.example" From edde39453ecd6df5dd8f66184ceb4164ab53eb18 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Wed, 6 Nov 2024 14:36:36 -0800 Subject: [PATCH 06/11] Address review --- packages/animations/example/android/app/build.gradle | 5 ----- .../dev/flutter/packages/animations/example/MainActivity.kt | 4 ++++ packages/animations/example/android/settings.gradle | 3 +++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/animations/example/android/app/build.gradle b/packages/animations/example/android/app/build.gradle index 7358c5b028a2..fd8903bacb35 100644 --- a/packages/animations/example/android/app/build.gradle +++ b/packages/animations/example/android/app/build.gradle @@ -24,10 +24,7 @@ android { } defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId = "dev.flutter.packages.animations.example" - // You can update the following values to match your application needs. - // For more information, see: https://flutter.dev/to/review-gradle-config. minSdk = flutter.minSdkVersion targetSdk = flutter.targetSdkVersion versionCode = flutter.versionCode @@ -36,8 +33,6 @@ android { buildTypes { release { - // TODO: Add your own signing config for the release build. - // Signing with the debug keys for now, so `flutter run --release` works. signingConfig = signingConfigs.debug } } diff --git a/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt b/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt index 4ed7a6686aa6..83c7ebd2eca5 100644 --- a/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt +++ b/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt @@ -1,3 +1,7 @@ +// Copyright 2013 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. + package dev.flutter.packages.animations.example import io.flutter.embedding.android.FlutterActivity diff --git a/packages/animations/example/android/settings.gradle b/packages/animations/example/android/settings.gradle index b9e43bd37614..80ecc5e30175 100644 --- a/packages/animations/example/android/settings.gradle +++ b/packages/animations/example/android/settings.gradle @@ -16,10 +16,13 @@ pluginManagement { } } + +// See https://github.com/flutter/flutter/blob/master/docs/ecosystem/Plugins-and-Packages-repository-structure.md#gradle-structure for more info. plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version "8.1.0" apply false id "org.jetbrains.kotlin.android" version "1.8.22" apply false + id "com.google.cloud.artifactregistry.gradle-plugin" version "2.2.1" } include ":app" From 7b75557f704e83553603eb9f1183041c3dd09891 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Wed, 6 Nov 2024 16:54:06 -0800 Subject: [PATCH 07/11] Format and add back removed block --- .../dev/flutter/packages/animations/example/MainActivity.kt | 2 +- packages/animations/example/android/build.gradle | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt b/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt index 83c7ebd2eca5..7bc2b2626200 100644 --- a/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt +++ b/packages/animations/example/android/app/src/main/kotlin/dev/flutter/packages/animations/example/MainActivity.kt @@ -6,4 +6,4 @@ package dev.flutter.packages.animations.example import io.flutter.embedding.android.FlutterActivity -class MainActivity: FlutterActivity() +class MainActivity : FlutterActivity() diff --git a/packages/animations/example/android/build.gradle b/packages/animations/example/android/build.gradle index d2ffbffa4cd2..c3c4e403ee38 100644 --- a/packages/animations/example/android/build.gradle +++ b/packages/animations/example/android/build.gradle @@ -1,5 +1,11 @@ allprojects { repositories { + // See https://github.com/flutter/flutter/blob/master/docs/ecosystem/Plugins-and-Packages-repository-structure.md#gradle-structure for more info. + def artifactRepoKey = 'ARTIFACT_HUB_REPOSITORY' + if (System.getenv().containsKey(artifactRepoKey)) { + println "Using artifact hub" + maven { url System.getenv(artifactRepoKey) } + } google() mavenCentral() } From 78b5fd02228bd9074210e99f530b8f8ad28aa462 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Thu, 7 Nov 2024 14:14:10 -0800 Subject: [PATCH 08/11] Bump kotlin version and update gradle-check to accept different namespace forms --- .../example/android/settings.gradle | 2 +- script/tool/lib/src/gradle_check_command.dart | 18 ++++++--- .../tool/test/gradle_check_command_test.dart | 37 +++++++++++++++++-- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/packages/animations/example/android/settings.gradle b/packages/animations/example/android/settings.gradle index 80ecc5e30175..93284a699429 100644 --- a/packages/animations/example/android/settings.gradle +++ b/packages/animations/example/android/settings.gradle @@ -21,7 +21,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version "8.1.0" apply false - id "org.jetbrains.kotlin.android" version "1.8.22" apply false + id "org.jetbrains.kotlin.android" version "1.9.0" apply false id "com.google.cloud.artifactregistry.gradle-plugin" version "2.2.1" } diff --git a/script/tool/lib/src/gradle_check_command.dart b/script/tool/lib/src/gradle_check_command.dart index ab6545054c31..9cdca529a402 100644 --- a/script/tool/lib/src/gradle_check_command.dart +++ b/script/tool/lib/src/gradle_check_command.dart @@ -327,12 +327,16 @@ plugins { /// compatibility with apps that use AGP 8+. bool _validateNamespace(RepositoryPackage package, String gradleContents, {required bool isExample}) { - final RegExp namespaceRegex = + final RegExp namespaceBlockRegex = RegExp('^\\s*namespace\\s+[\'"](.*?)[\'"]', multiLine: true); - final RegExpMatch? namespaceMatch = - namespaceRegex.firstMatch(gradleContents); - - if (namespaceMatch == null) { + final RegExpMatch? namespaceBlockMatch = + namespaceBlockRegex.firstMatch(gradleContents); + final RegExp namespaceDeclarationRegex = + RegExp('namespace = (\'|")(.*)(\'|")'); + final RegExpMatch? namespaceDeclarationMatch = + namespaceDeclarationRegex.firstMatch(gradleContents); + + if (namespaceBlockMatch == null && namespaceDeclarationMatch == null) { const String errorMessage = ''' build.gradle must set a "namespace": @@ -350,7 +354,9 @@ https://developer.android.com/build/publish-library/prep-lib-release#choose-name return false; } else { return _validateNamespaceMatchesManifest(package, - isExample: isExample, namespace: namespaceMatch.group(1)!); + isExample: isExample, + namespace: (namespaceBlockMatch?.group(1) ?? + namespaceDeclarationMatch?.group(2))!); } } diff --git a/script/tool/test/gradle_check_command_test.dart b/script/tool/test/gradle_check_command_test.dart index 457f3f40b02b..6c1a661e7c9c 100644 --- a/script/tool/test/gradle_check_command_test.dart +++ b/script/tool/test/gradle_check_command_test.dart @@ -255,6 +255,7 @@ include ":app" RepositoryPackage package, { required bool includeNamespace, required bool commentNamespace, + required bool includeNameSpaceAsDeclaration, }) { final File buildGradle = package .platformDirectory(FlutterPlatform.android) @@ -263,7 +264,7 @@ include ":app" buildGradle.createSync(recursive: true); final String namespace = - "${commentNamespace ? '// ' : ''}namespace '$_defaultFakeNamespace'"; + "${commentNamespace ? '// ' : ''}namespace ${includeNameSpaceAsDeclaration ? '= ' : ''}'$_defaultFakeNamespace'"; buildGradle.writeAsStringSync(''' def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { @@ -303,6 +304,7 @@ dependencies { required String pluginName, bool includeNamespace = true, bool commentNamespace = false, + bool includeNameSpaceAsDeclaration = false, bool warningsConfigured = true, String? kotlinVersion, bool includeBuildArtifactHub = true, @@ -317,7 +319,9 @@ dependencies { includeArtifactHub: includeBuildArtifactHub, ); writeFakeExampleAppBuildGradle(package, - includeNamespace: includeNamespace, commentNamespace: commentNamespace); + includeNamespace: includeNamespace, + commentNamespace: commentNamespace, + includeNameSpaceAsDeclaration: includeNameSpaceAsDeclaration); writeFakeExampleTopLevelSettingsGradle( package, includeArtifactHub: includeSettingsArtifactHub, @@ -330,6 +334,7 @@ dependencies { required String pluginName, bool includeNamespace = true, bool commentNamespace = false, + bool includeNameSpaceAsDeclaration = false, bool warningsConfigured = true, String? kotlinVersion, required bool includeBuildArtifactHub, @@ -344,7 +349,9 @@ dependencies { includeArtifactHub: includeBuildArtifactHub, ); writeFakeExampleAppBuildGradle(package, - includeNamespace: includeNamespace, commentNamespace: commentNamespace); + includeNamespace: includeNamespace, + commentNamespace: commentNamespace, + includeNameSpaceAsDeclaration: includeNameSpaceAsDeclaration); writeFakeExampleSettingsGradle( package, includeArtifactHub: includeSettingsArtifactHub, @@ -659,6 +666,30 @@ dependencies { ); }); + test('passes when namespace is declared with "=" declaration', () async { + const String pluginName = 'a_plugin'; + final RepositoryPackage package = createFakePlugin(pluginName, packagesDir); + writeFakePluginBuildGradle(package, includeLanguageVersion: true); + writeFakeManifest(package); + final RepositoryPackage example = package.getExamples().first; + writeFakeExampleBuildGradles(example, + pluginName: pluginName, includeNameSpaceAsDeclaration: true); + writeFakeManifest(example, isApp: true); + + final List output = await runCapturingPrint( + runner, ['gradle-check'], errorHandler: (Error e) { + print((e as ToolExit).stackTrace); + }); + + expect( + output, + containsAllInOrder( + [ + contains('Validating android/app/build.gradle'), + ], + )); + }); + test('fails if gradle-driven lint-warnings-as-errors is missing', () async { const String pluginName = 'a_plugin'; final RepositoryPackage plugin = From 5677d9edf74f78eb7c37f5bd884e0d2966c81b42 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Fri, 8 Nov 2024 09:13:45 -0800 Subject: [PATCH 09/11] Remove second regex --- script/tool/lib/src/gradle_check_command.dart | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/script/tool/lib/src/gradle_check_command.dart b/script/tool/lib/src/gradle_check_command.dart index 9cdca529a402..62d59ded0649 100644 --- a/script/tool/lib/src/gradle_check_command.dart +++ b/script/tool/lib/src/gradle_check_command.dart @@ -327,16 +327,12 @@ plugins { /// compatibility with apps that use AGP 8+. bool _validateNamespace(RepositoryPackage package, String gradleContents, {required bool isExample}) { - final RegExp namespaceBlockRegex = - RegExp('^\\s*namespace\\s+[\'"](.*?)[\'"]', multiLine: true); - final RegExpMatch? namespaceBlockMatch = - namespaceBlockRegex.firstMatch(gradleContents); - final RegExp namespaceDeclarationRegex = - RegExp('namespace = (\'|")(.*)(\'|")'); - final RegExpMatch? namespaceDeclarationMatch = - namespaceDeclarationRegex.firstMatch(gradleContents); - - if (namespaceBlockMatch == null && namespaceDeclarationMatch == null) { + final RegExp nameSpaceRegex = + RegExp('^\\s*namespace\\s+=?\\s*[\'"](.*?)[\'"]', multiLine: true); + final RegExpMatch? nameSpaceRegexMatch = + nameSpaceRegex.firstMatch(gradleContents); + + if (nameSpaceRegexMatch == null) { const String errorMessage = ''' build.gradle must set a "namespace": @@ -354,9 +350,7 @@ https://developer.android.com/build/publish-library/prep-lib-release#choose-name return false; } else { return _validateNamespaceMatchesManifest(package, - isExample: isExample, - namespace: (namespaceBlockMatch?.group(1) ?? - namespaceDeclarationMatch?.group(2))!); + isExample: isExample, namespace: nameSpaceRegexMatch.group(1)!); } } From 557c32e3cad616d1ebfaaf6d4721fc1f25dc8152 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Fri, 8 Nov 2024 09:17:32 -0800 Subject: [PATCH 10/11] Add comment with examples --- script/tool/lib/src/gradle_check_command.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/script/tool/lib/src/gradle_check_command.dart b/script/tool/lib/src/gradle_check_command.dart index 62d59ded0649..97f818015a28 100644 --- a/script/tool/lib/src/gradle_check_command.dart +++ b/script/tool/lib/src/gradle_check_command.dart @@ -327,6 +327,10 @@ plugins { /// compatibility with apps that use AGP 8+. bool _validateNamespace(RepositoryPackage package, String gradleContents, {required bool isExample}) { + // Regex to validate that either of the following namespace definitions + // are found (where the single quotes can be single or double): + // - namespace 'dev.flutter.foo' + // - namespace = 'dev.flutter.foo' final RegExp nameSpaceRegex = RegExp('^\\s*namespace\\s+=?\\s*[\'"](.*?)[\'"]', multiLine: true); final RegExpMatch? nameSpaceRegexMatch = From f76db659e45117396fc10746ef7f5d779e9d1743 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Fri, 8 Nov 2024 10:48:54 -0800 Subject: [PATCH 11/11] Bump back up AGP version --- packages/animations/example/android/settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/animations/example/android/settings.gradle b/packages/animations/example/android/settings.gradle index 93284a699429..c223212e4e05 100644 --- a/packages/animations/example/android/settings.gradle +++ b/packages/animations/example/android/settings.gradle @@ -20,7 +20,7 @@ pluginManagement { // See https://github.com/flutter/flutter/blob/master/docs/ecosystem/Plugins-and-Packages-repository-structure.md#gradle-structure for more info. plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "8.1.0" apply false + id "com.android.application" version "8.5.1" apply false id "org.jetbrains.kotlin.android" version "1.9.0" apply false id "com.google.cloud.artifactregistry.gradle-plugin" version "2.2.1" }