From a86beafa8912609275225847198c9c0164957d09 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Thu, 27 Apr 2023 17:34:33 -0700 Subject: [PATCH] [various] Conditionalize the namespace in all Android plugins (#3836) The recent change to add `namespace` to all plugins broke builds for apps using AGP 4.1 or earlier. This conditionalizes setting the namespace based on whether the property exists at all, making it compatible with both AGP 8.0 and AGP <4.2. Updates tooling to enforce this for plugin (but not example app) build.gradle files. Fixes https://github.com/flutter/flutter/issues/125621 --- packages/camera/camera_android/CHANGELOG.md | 4 ++ .../camera_android/android/build.gradle | 5 ++- packages/camera/camera_android/pubspec.yaml | 2 +- .../android/build.gradle | 5 ++- packages/espresso/CHANGELOG.md | 4 ++ packages/espresso/android/build.gradle | 5 ++- packages/espresso/pubspec.yaml | 2 +- .../CHANGELOG.md | 4 ++ .../android/build.gradle | 5 ++- .../pubspec.yaml | 2 +- .../google_maps_flutter_android/CHANGELOG.md | 4 ++ .../android/build.gradle | 5 ++- .../google_maps_flutter_android/pubspec.yaml | 2 +- .../google_sign_in_android/CHANGELOG.md | 4 ++ .../android/build.gradle | 5 ++- .../google_sign_in_android/pubspec.yaml | 2 +- .../image_picker_android/CHANGELOG.md | 4 ++ .../image_picker_android/android/build.gradle | 5 ++- .../image_picker_android/pubspec.yaml | 2 +- .../in_app_purchase_android/CHANGELOG.md | 4 ++ .../android/build.gradle | 5 ++- .../in_app_purchase_android/pubspec.yaml | 2 +- .../local_auth_android/CHANGELOG.md | 4 ++ .../local_auth_android/android/build.gradle | 5 ++- .../local_auth_android/pubspec.yaml | 2 +- .../path_provider_android/CHANGELOG.md | 4 ++ .../android/build.gradle | 5 ++- .../path_provider_android/pubspec.yaml | 2 +- .../android/build.gradle | 5 ++- .../test_plugin/android/build.gradle | 5 ++- .../quick_actions_android/CHANGELOG.md | 4 ++ .../android/build.gradle | 5 ++- .../quick_actions_android/pubspec.yaml | 2 +- .../shared_preferences_android/CHANGELOG.md | 4 ++ .../android/build.gradle | 5 ++- .../shared_preferences_android/pubspec.yaml | 2 +- .../url_launcher_android/CHANGELOG.md | 4 ++ .../url_launcher_android/android/build.gradle | 5 ++- .../url_launcher_android/pubspec.yaml | 2 +- .../video_player_android/CHANGELOG.md | 4 ++ .../video_player_android/android/build.gradle | 5 ++- .../video_player_android/pubspec.yaml | 2 +- .../webview_flutter_android/CHANGELOG.md | 4 ++ .../android/build.gradle | 5 ++- .../webview_flutter_android/pubspec.yaml | 2 +- script/tool/lib/src/gradle_check_command.dart | 39 +++++++++++++++++-- .../tool/test/gradle_check_command_test.dart | 36 +++++++++++++++-- 47 files changed, 206 insertions(+), 38 deletions(-) diff --git a/packages/camera/camera_android/CHANGELOG.md b/packages/camera/camera_android/CHANGELOG.md index 661cafd3bb8f..91bd0fbe9a47 100644 --- a/packages/camera/camera_android/CHANGELOG.md +++ b/packages/camera/camera_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.6+2 + +* Fixes compatibility with AGP versions older than 4.2. + ## 0.10.6+1 * Adds a namespace for compatibility with AGP 8.0. diff --git a/packages/camera/camera_android/android/build.gradle b/packages/camera/camera_android/android/build.gradle index 6b437709809a..53ac70561db3 100644 --- a/packages/camera/camera_android/android/build.gradle +++ b/packages/camera/camera_android/android/build.gradle @@ -27,7 +27,10 @@ project.getTasks().withType(JavaCompile){ apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.camera' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.camera' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/camera/camera_android/pubspec.yaml b/packages/camera/camera_android/pubspec.yaml index 2b7c0c29e280..9c4fc57336c7 100644 --- a/packages/camera/camera_android/pubspec.yaml +++ b/packages/camera/camera_android/pubspec.yaml @@ -2,7 +2,7 @@ name: camera_android description: Android implementation of the camera plugin. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.10.6+1 +version: 0.10.6+2 environment: sdk: ">=2.17.0 <4.0.0" diff --git a/packages/camera/camera_android_camerax/android/build.gradle b/packages/camera/camera_android_camerax/android/build.gradle index 1ae38c243a59..d056449de871 100644 --- a/packages/camera/camera_android_camerax/android/build.gradle +++ b/packages/camera/camera_android_camerax/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.camerax' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.camerax' + } // CameraX dependencies require compilation against version 33 or later. compileSdkVersion 33 diff --git a/packages/espresso/CHANGELOG.md b/packages/espresso/CHANGELOG.md index 7204107115f1..af45fb87c88e 100644 --- a/packages/espresso/CHANGELOG.md +++ b/packages/espresso/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.0+4 + +* Fixes compatibility with AGP versions older than 4.2. + ## 0.3.0+3 * Adds `targetCompatibilty` matching `sourceCompatibility` for older toolchains. diff --git a/packages/espresso/android/build.gradle b/packages/espresso/android/build.gradle index 034779a802ce..1d28a98c477b 100644 --- a/packages/espresso/android/build.gradle +++ b/packages/espresso/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'com.example.espresso' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'com.example.espresso' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/espresso/pubspec.yaml b/packages/espresso/pubspec.yaml index ef0d6dd56707..0dffbdb5a1e9 100644 --- a/packages/espresso/pubspec.yaml +++ b/packages/espresso/pubspec.yaml @@ -3,7 +3,7 @@ description: Java classes for testing Flutter apps using Espresso. Allows driving Flutter widgets from a native Espresso test. repository: https://github.com/flutter/packages/tree/main/packages/espresso issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+espresso%22 -version: 0.3.0+3 +version: 0.3.0+4 environment: sdk: ">=2.17.0 <4.0.0" diff --git a/packages/flutter_plugin_android_lifecycle/CHANGELOG.md b/packages/flutter_plugin_android_lifecycle/CHANGELOG.md index ca354c8fd91b..1e1e0316a471 100644 --- a/packages/flutter_plugin_android_lifecycle/CHANGELOG.md +++ b/packages/flutter_plugin_android_lifecycle/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.13 + +* Fixes compatibility with AGP versions older than 4.2. + ## 2.0.12 * Adds `targetCompatibilty` matching `sourceCompatibility` for older toolchains. diff --git a/packages/flutter_plugin_android_lifecycle/android/build.gradle b/packages/flutter_plugin_android_lifecycle/android/build.gradle index 1203eb36dc62..5a1933069cc1 100644 --- a/packages/flutter_plugin_android_lifecycle/android/build.gradle +++ b/packages/flutter_plugin_android_lifecycle/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.flutter_plugin_android_lifecycle' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.flutter_plugin_android_lifecycle' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/flutter_plugin_android_lifecycle/pubspec.yaml b/packages/flutter_plugin_android_lifecycle/pubspec.yaml index d76dabdcdb1c..fd111c234da3 100644 --- a/packages/flutter_plugin_android_lifecycle/pubspec.yaml +++ b/packages/flutter_plugin_android_lifecycle/pubspec.yaml @@ -2,7 +2,7 @@ name: flutter_plugin_android_lifecycle description: Flutter plugin for accessing an Android Lifecycle within other plugins. repository: https://github.com/flutter/packages/tree/main/packages/flutter_plugin_android_lifecycle issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_plugin_android_lifecycle%22 -version: 2.0.12 +version: 2.0.13 environment: sdk: ">=2.17.0 <4.0.0" diff --git a/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md index 0e91f2df16a4..c61f15671de1 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.4.13 + +* Fixes compatibility with AGP versions older than 4.2. + ## 2.4.12 * Fixes Java warnings. diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/build.gradle b/packages/google_maps_flutter/google_maps_flutter_android/android/build.gradle index 35ba28401859..42e05a7fdc48 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/build.gradle +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.googlemaps' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.googlemaps' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml index 03914708dcfd..71ba77407625 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter_android description: Android implementation of the google_maps_flutter plugin. repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 -version: 2.4.12 +version: 2.4.13 environment: sdk: ">=2.17.0 <4.0.0" diff --git a/packages/google_sign_in/google_sign_in_android/CHANGELOG.md b/packages/google_sign_in/google_sign_in_android/CHANGELOG.md index d9082a6b948d..7aeafc1a0f01 100644 --- a/packages/google_sign_in/google_sign_in_android/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.1.14 + +* Fixes compatibility with AGP versions older than 4.2. + ## 6.1.13 * Adds `targetCompatibilty` matching `sourceCompatibility` for older toolchains. diff --git a/packages/google_sign_in/google_sign_in_android/android/build.gradle b/packages/google_sign_in/google_sign_in_android/android/build.gradle index 72c383ca7b4e..e48223dd7e7c 100644 --- a/packages/google_sign_in/google_sign_in_android/android/build.gradle +++ b/packages/google_sign_in/google_sign_in_android/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.googlesignin' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.googlesignin' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/google_sign_in/google_sign_in_android/pubspec.yaml b/packages/google_sign_in/google_sign_in_android/pubspec.yaml index 1ff448e18fa3..73904741a401 100644 --- a/packages/google_sign_in/google_sign_in_android/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_android/pubspec.yaml @@ -2,7 +2,7 @@ name: google_sign_in_android description: Android implementation of the google_sign_in plugin. repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 6.1.13 +version: 6.1.14 environment: sdk: ">=2.17.0 <4.0.0" diff --git a/packages/image_picker/image_picker_android/CHANGELOG.md b/packages/image_picker/image_picker_android/CHANGELOG.md index 51281722190b..44902aa169ff 100644 --- a/packages/image_picker/image_picker_android/CHANGELOG.md +++ b/packages/image_picker/image_picker_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.8.6+9 + +* Fixes compatibility with AGP versions older than 4.2. + ## 0.8.6+8 * Adds a namespace for compatibility with AGP 8.0. diff --git a/packages/image_picker/image_picker_android/android/build.gradle b/packages/image_picker/image_picker_android/android/build.gradle index 777a4e4676c6..08b4bb3b4d05 100644 --- a/packages/image_picker/image_picker_android/android/build.gradle +++ b/packages/image_picker/image_picker_android/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.imagepicker' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.imagepicker' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/image_picker/image_picker_android/pubspec.yaml b/packages/image_picker/image_picker_android/pubspec.yaml index 349cacc8b352..e95d14c84c9f 100755 --- a/packages/image_picker/image_picker_android/pubspec.yaml +++ b/packages/image_picker/image_picker_android/pubspec.yaml @@ -3,7 +3,7 @@ description: Android implementation of the image_picker plugin. repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22 -version: 0.8.6+8 +version: 0.8.6+9 environment: sdk: ">=2.18.0 <4.0.0" diff --git a/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md b/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md index 1348347fda76..8f1131b388f6 100644 --- a/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md +++ b/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.5+4 + +* Fixes compatibility with AGP versions older than 4.2. + ## 0.2.5+3 * Updates com.android.billingclient:billing from 5.1.0 to 5.2.0. diff --git a/packages/in_app_purchase/in_app_purchase_android/android/build.gradle b/packages/in_app_purchase/in_app_purchase_android/android/build.gradle index 2892be27936d..94acf3a86551 100644 --- a/packages/in_app_purchase/in_app_purchase_android/android/build.gradle +++ b/packages/in_app_purchase/in_app_purchase_android/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.inapppurchase' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.inapppurchase' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml b/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml index f81311196096..96426db8a932 100644 --- a/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml +++ b/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml @@ -2,7 +2,7 @@ name: in_app_purchase_android description: An implementation for the Android platform of the Flutter `in_app_purchase` plugin. This uses the Android BillingClient APIs. repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22 -version: 0.2.5+3 +version: 0.2.5+4 environment: sdk: ">=2.18.0 <4.0.0" diff --git a/packages/local_auth/local_auth_android/CHANGELOG.md b/packages/local_auth/local_auth_android/CHANGELOG.md index 1f651323ddf8..6752fc53d061 100644 --- a/packages/local_auth/local_auth_android/CHANGELOG.md +++ b/packages/local_auth/local_auth_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.27 + +* Fixes compatibility with AGP versions older than 4.2. + ## 1.0.26 * Adds `targetCompatibilty` matching `sourceCompatibility` for older toolchains. diff --git a/packages/local_auth/local_auth_android/android/build.gradle b/packages/local_auth/local_auth_android/android/build.gradle index a212f23d6f21..6c1dc9c17611 100644 --- a/packages/local_auth/local_auth_android/android/build.gradle +++ b/packages/local_auth/local_auth_android/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.localauth' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.localauth' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/local_auth/local_auth_android/pubspec.yaml b/packages/local_auth/local_auth_android/pubspec.yaml index d9cf8df4bac2..a1843ec40c7f 100644 --- a/packages/local_auth/local_auth_android/pubspec.yaml +++ b/packages/local_auth/local_auth_android/pubspec.yaml @@ -2,7 +2,7 @@ name: local_auth_android description: Android implementation of the local_auth plugin. repository: https://github.com/flutter/packages/tree/main/packages/local_auth/local_auth_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+local_auth%22 -version: 1.0.26 +version: 1.0.27 environment: sdk: ">=2.17.0 <4.0.0" diff --git a/packages/path_provider/path_provider_android/CHANGELOG.md b/packages/path_provider/path_provider_android/CHANGELOG.md index 660b3fa54986..5f5514198164 100644 --- a/packages/path_provider/path_provider_android/CHANGELOG.md +++ b/packages/path_provider/path_provider_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.27 + +* Fixes compatibility with AGP versions older than 4.2. + ## 2.0.26 * Adds a namespace for compatibility with AGP 8.0. diff --git a/packages/path_provider/path_provider_android/android/build.gradle b/packages/path_provider/path_provider_android/android/build.gradle index 09b407a5363d..0cdb3d00eaed 100644 --- a/packages/path_provider/path_provider_android/android/build.gradle +++ b/packages/path_provider/path_provider_android/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.pathprovider' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.pathprovider' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/path_provider/path_provider_android/pubspec.yaml b/packages/path_provider/path_provider_android/pubspec.yaml index 95300b1f612f..f22706b08a7d 100644 --- a/packages/path_provider/path_provider_android/pubspec.yaml +++ b/packages/path_provider/path_provider_android/pubspec.yaml @@ -2,7 +2,7 @@ name: path_provider_android description: Android implementation of the path_provider plugin. repository: https://github.com/flutter/packages/tree/main/packages/path_provider/path_provider_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+path_provider%22 -version: 2.0.26 +version: 2.0.27 environment: sdk: ">=2.17.0 <4.0.0" diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/build.gradle b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/build.gradle index 8f4a155fd666..a6a50278f9f4 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/build.gradle +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'com.example.alternate_language_test_plugin' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'com.example.alternate_language_test_plugin' + } compileSdkVersion 33 compileOptions { diff --git a/packages/pigeon/platform_tests/test_plugin/android/build.gradle b/packages/pigeon/platform_tests/test_plugin/android/build.gradle index 6ee629bf6c9c..e99796f68824 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/build.gradle +++ b/packages/pigeon/platform_tests/test_plugin/android/build.gradle @@ -25,7 +25,10 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { - namespace 'com.example.test_plugin' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'com.example.test_plugin' + } compileSdkVersion 33 compileOptions { diff --git a/packages/quick_actions/quick_actions_android/CHANGELOG.md b/packages/quick_actions/quick_actions_android/CHANGELOG.md index 3187f6aaebb2..32a0fa16d40b 100644 --- a/packages/quick_actions/quick_actions_android/CHANGELOG.md +++ b/packages/quick_actions/quick_actions_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.4 + +* Fixes compatibility with AGP versions older than 4.2. + ## 1.0.3 * Adds a namespace for compatibility with AGP 8.0. diff --git a/packages/quick_actions/quick_actions_android/android/build.gradle b/packages/quick_actions/quick_actions_android/android/build.gradle index 935c5176c27e..71bd5b2d6d21 100644 --- a/packages/quick_actions/quick_actions_android/android/build.gradle +++ b/packages/quick_actions/quick_actions_android/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.quickactions' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.quickactions' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/quick_actions/quick_actions_android/pubspec.yaml b/packages/quick_actions/quick_actions_android/pubspec.yaml index ca16d8bda96d..65f71d6b157d 100644 --- a/packages/quick_actions/quick_actions_android/pubspec.yaml +++ b/packages/quick_actions/quick_actions_android/pubspec.yaml @@ -2,7 +2,7 @@ name: quick_actions_android description: An implementation for the Android platform of the Flutter `quick_actions` plugin. repository: https://github.com/flutter/packages/tree/main/packages/quick_actions/quick_actions_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22 -version: 1.0.3 +version: 1.0.4 environment: sdk: ">=2.17.0 <4.0.0" diff --git a/packages/shared_preferences/shared_preferences_android/CHANGELOG.md b/packages/shared_preferences/shared_preferences_android/CHANGELOG.md index a14bc1d7fe65..e901898e9421 100644 --- a/packages/shared_preferences/shared_preferences_android/CHANGELOG.md +++ b/packages/shared_preferences/shared_preferences_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.1.4 + +* Fixes compatibility with AGP versions older than 4.2. + ## 2.1.3 * Adds a namespace for compatibility with AGP 8.0. diff --git a/packages/shared_preferences/shared_preferences_android/android/build.gradle b/packages/shared_preferences/shared_preferences_android/android/build.gradle index 4469e49bf73d..f3074dd3adc5 100644 --- a/packages/shared_preferences/shared_preferences_android/android/build.gradle +++ b/packages/shared_preferences/shared_preferences_android/android/build.gradle @@ -30,7 +30,10 @@ allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.sharedpreferences' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.sharedpreferences' + } compileSdkVersion 33 compileOptions { diff --git a/packages/shared_preferences/shared_preferences_android/pubspec.yaml b/packages/shared_preferences/shared_preferences_android/pubspec.yaml index e9381f4d16c0..b8d240a78265 100644 --- a/packages/shared_preferences/shared_preferences_android/pubspec.yaml +++ b/packages/shared_preferences/shared_preferences_android/pubspec.yaml @@ -2,7 +2,7 @@ name: shared_preferences_android description: Android implementation of the shared_preferences plugin repository: https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+shared_preferences%22 -version: 2.1.3 +version: 2.1.4 environment: sdk: ">=2.17.0 <4.0.0" diff --git a/packages/url_launcher/url_launcher_android/CHANGELOG.md b/packages/url_launcher/url_launcher_android/CHANGELOG.md index fdf4eb91f243..aa82c4beff45 100644 --- a/packages/url_launcher/url_launcher_android/CHANGELOG.md +++ b/packages/url_launcher/url_launcher_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.0.31 + +* Fixes compatibility with AGP versions older than 4.2. + ## 6.0.30 * Adds `targetCompatibilty` matching `sourceCompatibility` for older toolchains. diff --git a/packages/url_launcher/url_launcher_android/android/build.gradle b/packages/url_launcher/url_launcher_android/android/build.gradle index e0c2fc6a7b87..3344266b6b37 100644 --- a/packages/url_launcher/url_launcher_android/android/build.gradle +++ b/packages/url_launcher/url_launcher_android/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.urllauncher' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.urllauncher' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/url_launcher/url_launcher_android/pubspec.yaml b/packages/url_launcher/url_launcher_android/pubspec.yaml index cf35a0b73944..73a427da9dad 100644 --- a/packages/url_launcher/url_launcher_android/pubspec.yaml +++ b/packages/url_launcher/url_launcher_android/pubspec.yaml @@ -2,7 +2,7 @@ name: url_launcher_android description: Android implementation of the url_launcher plugin. repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22 -version: 6.0.30 +version: 6.0.31 environment: sdk: ">=2.18.0 <4.0.0" diff --git a/packages/video_player/video_player_android/CHANGELOG.md b/packages/video_player/video_player_android/CHANGELOG.md index 3a60162d2af0..a204cb2c6e1c 100644 --- a/packages/video_player/video_player_android/CHANGELOG.md +++ b/packages/video_player/video_player_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.4.6 + +* Fixes compatibility with AGP versions older than 4.2. + ## 2.4.5 * Adds a namespace for compatibility with AGP 8.0. diff --git a/packages/video_player/video_player_android/android/build.gradle b/packages/video_player/video_player_android/android/build.gradle index 0facb26f51ba..613b8ed3c298 100644 --- a/packages/video_player/video_player_android/android/build.gradle +++ b/packages/video_player/video_player_android/android/build.gradle @@ -27,7 +27,10 @@ project.getTasks().withType(JavaCompile){ apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.videoplayer' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.videoplayer' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/video_player/video_player_android/pubspec.yaml b/packages/video_player/video_player_android/pubspec.yaml index 7940829efa5c..dc195b440761 100644 --- a/packages/video_player/video_player_android/pubspec.yaml +++ b/packages/video_player/video_player_android/pubspec.yaml @@ -2,7 +2,7 @@ name: video_player_android description: Android implementation of the video_player plugin. repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22 -version: 2.4.5 +version: 2.4.6 environment: sdk: ">=2.18.0 <4.0.0" diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index 137f882349e1..02edbab2f67e 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.6.2 + +* Fixes compatibility with AGP versions older than 4.2. + ## 3.6.1 * Adds a namespace for compatibility with AGP 8.0. diff --git a/packages/webview_flutter/webview_flutter_android/android/build.gradle b/packages/webview_flutter/webview_flutter_android/android/build.gradle index 13eff1a9bed2..f3da461ec55f 100644 --- a/packages/webview_flutter/webview_flutter_android/android/build.gradle +++ b/packages/webview_flutter/webview_flutter_android/android/build.gradle @@ -22,7 +22,10 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - namespace 'io.flutter.plugins.webviewflutter' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'io.flutter.plugins.webviewflutter' + } compileSdkVersion 33 defaultConfig { diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 94105ff3b440..8196b3ba50c8 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_android description: A Flutter plugin that provides a WebView widget on Android. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 3.6.1 +version: 3.6.2 environment: sdk: ">=2.18.0 <4.0.0" diff --git a/script/tool/lib/src/gradle_check_command.dart b/script/tool/lib/src/gradle_check_command.dart index a3a1e7607db2..09a9d7a55f22 100644 --- a/script/tool/lib/src/gradle_check_command.dart +++ b/script/tool/lib/src/gradle_check_command.dart @@ -153,13 +153,32 @@ class GradleCheckCommand extends PackageLoopingCommand { RegExp('^\\s*namespace\\s+[\'"](.*?)[\'"]', multiLine: true); final RegExpMatch? namespaceMatch = namespaceRegex.firstMatch(gradleContents); - if (namespaceMatch == null) { - const String errorMessage = ''' -build.gradle must set a "namespace": + // For plugins, make sure the namespace is conditionalized so that it + // doesn't break client apps using AGP 4.1 and earlier (which don't have + // a namespace property, and will fail to build if it's set). + const String namespaceConditional = + 'if (project.android.hasProperty("namespace"))'; + String exampleSetNamespace = "namespace 'dev.flutter.foo'"; + if (!isExample) { + exampleSetNamespace = ''' +$namespaceConditional { + $exampleSetNamespace +}'''; + } + // Wrap the namespace command in an `android` block, adding the indentation + // to make it line up correctly. + final String exampleAndroidNamespaceBlock = ''' android { - namespace 'dev.flutter.foo' + ${exampleSetNamespace.split('\n').join('\n ')} } +'''; + + if (namespaceMatch == null) { + final String errorMessage = ''' +build.gradle must set a "namespace": + +$exampleAndroidNamespaceBlock The value must match the "package" attribute in AndroidManifest.xml, if one is present. For more information, see: @@ -170,6 +189,18 @@ https://developer.android.com/build/publish-library/prep-lib-release#choose-name '$indentation${errorMessage.split('\n').join('\n$indentation')}'); return false; } else { + if (!isExample && !gradleContents.contains(namespaceConditional)) { + final String errorMessage = ''' +build.gradle for a plugin must conditionalize "namespace": + +$exampleAndroidNamespaceBlock +'''; + + printError( + '$indentation${errorMessage.split('\n').join('\n$indentation')}'); + return false; + } + return _validateNamespaceMatchesManifest(package, isExample: isExample, namespace: namespaceMatch.group(1)!); } diff --git a/script/tool/test/gradle_check_command_test.dart b/script/tool/test/gradle_check_command_test.dart index e72d3f8f1dbb..68581c7a639a 100644 --- a/script/tool/test/gradle_check_command_test.dart +++ b/script/tool/test/gradle_check_command_test.dart @@ -41,6 +41,7 @@ void main() { bool includeTargetCompat = false, bool commentSourceLanguage = false, bool includeNamespace = true, + bool conditionalizeNamespace = true, bool commentNamespace = false, bool warningsConfigured = true, }) { @@ -69,8 +70,15 @@ java { '${commentSourceLanguage ? '// ' : ''}sourceCompatibility JavaVersion.VERSION_1_8'; final String targetCompat = '${commentSourceLanguage ? '// ' : ''}targetCompatibility JavaVersion.VERSION_1_8'; - final String namespace = - "${commentNamespace ? '// ' : ''}namespace '$_defaultFakeNamespace'"; + String namespace = + " ${commentNamespace ? '// ' : ''}namespace '$_defaultFakeNamespace'"; + if (conditionalizeNamespace) { + namespace = ''' + if (project.android.hasProperty("namespace")) { + $namespace + } +'''; + } buildGradle.writeAsStringSync(''' group 'dev.flutter.plugins.fake' @@ -87,7 +95,7 @@ apply plugin: 'com.android.library' ${includeLanguageVersion ? javaSection : ''} android { - ${includeNamespace ? namespace : ''} +${includeNamespace ? namespace : ''} compileSdkVersion 33 defaultConfig { @@ -435,6 +443,28 @@ dependencies { ); }); + test('fails when plugin namespace is not conditional', () async { + final RepositoryPackage package = + createFakePlugin('a_plugin', packagesDir, examples: []); + writeFakePluginBuildGradle(package, + includeLanguageVersion: true, conditionalizeNamespace: false); + writeFakeManifest(package); + + Error? commandError; + final List output = await runCapturingPrint( + runner, ['gradle-check'], errorHandler: (Error e) { + commandError = e; + }); + + expect(commandError, isA()); + expect( + output, + containsAllInOrder([ + contains('build.gradle for a plugin must conditionalize "namespace"'), + ]), + ); + }); + test('fails when namespace is missing', () async { final RepositoryPackage package = createFakePlugin('a_plugin', packagesDir, examples: []);