From 87459c4fdca702cc2bab9fa81e7ae97bae5f242d Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Fri, 7 Apr 2023 11:07:53 -0700 Subject: [PATCH] [various] Enable warnings as errors, and all warnings, for Android lint (#3648) For all Android plugins: - Enable all warnings for `lint` - Treat all warnings as errors for `lint` This significantly increases the scope of issues that we'll catch in CI. To allow enabling this without having to make tons of fixes first, so that we get the incremental benefit immediately, this adds new baselines for all plugins. We can incrementally clean those baselines up over time. (In practice we haven't prioritized that, but it would be good to start paying down that technical debt incrementally at some point.) See https://github.com/flutter/flutter/issues/88011 --- .../camera_android/android/build.gradle | 2 + .../camera_android/android/lint-baseline.xml | 3126 ++++++++++++- .../android/build.gradle | 6 +- .../android/lint-baseline.xml | 1434 ++++++ packages/espresso/android/build.gradle | 2 + packages/espresso/android/lint-baseline.xml | 2453 +++++++++- .../android/build.gradle | 3 + .../android/lint-baseline.xml | 15 + .../android/build.gradle | 3 + .../android/lint-baseline.xml | 202 + .../android/build.gradle | 3 + .../android/lint-baseline.xml | 730 +++ .../image_picker_android/android/build.gradle | 3 + .../android/lint-baseline.xml | 400 ++ .../android/build.gradle | 3 + .../android/lint-baseline.xml | 81 + .../local_auth_android/android/build.gradle | 2 + .../android/lint-baseline.xml | 508 +- .../android/build.gradle | 3 + .../android/lint-baseline.xml | 114 + .../android/build.gradle | 3 + .../android/lint-baseline.xml | 81 + .../android/build.gradle | 2 + .../android/lint-baseline.xml | 52 +- .../url_launcher_android/android/build.gradle | 3 + .../android/lint-baseline.xml | 147 + .../video_player_android/android/build.gradle | 3 + .../android/lint-baseline.xml | 653 +++ .../android/build.gradle | 6 +- .../android/lint-baseline.xml | 4107 +++++++++++++++++ script/tool/lib/src/lint_android_command.dart | 69 +- .../tool/test/lint_android_command_test.dart | 86 +- 32 files changed, 13996 insertions(+), 309 deletions(-) create mode 100644 packages/camera/camera_android_camerax/android/lint-baseline.xml create mode 100644 packages/flutter_plugin_android_lifecycle/android/lint-baseline.xml create mode 100644 packages/google_maps_flutter/google_maps_flutter_android/android/lint-baseline.xml create mode 100644 packages/google_sign_in/google_sign_in_android/android/lint-baseline.xml create mode 100644 packages/image_picker/image_picker_android/android/lint-baseline.xml create mode 100644 packages/in_app_purchase/in_app_purchase_android/android/lint-baseline.xml create mode 100644 packages/path_provider/path_provider_android/android/lint-baseline.xml create mode 100644 packages/quick_actions/quick_actions_android/android/lint-baseline.xml create mode 100644 packages/url_launcher/url_launcher_android/android/lint-baseline.xml create mode 100644 packages/video_player/video_player_android/android/lint-baseline.xml create mode 100644 packages/webview_flutter/webview_flutter_android/android/lint-baseline.xml diff --git a/packages/camera/camera_android/android/build.gradle b/packages/camera/camera_android/android/build.gradle index 476386ba6d2b..8e2775a0e263 100644 --- a/packages/camera/camera_android/android/build.gradle +++ b/packages/camera/camera_android/android/build.gradle @@ -35,6 +35,8 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' baseline file("lint-baseline.xml") } diff --git a/packages/camera/camera_android/android/lint-baseline.xml b/packages/camera/camera_android/android/lint-baseline.xml index 4ddaafa87988..b0fc2e758dff 100644 --- a/packages/camera/camera_android/android/lint-baseline.xml +++ b/packages/camera/camera_android/android/lint-baseline.xml @@ -1,114 +1,3106 @@ - + + + + + + file="src/main/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManager.java" + line="250" + column="5"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations" + errorLine1=" public static FocusMode getValueForString(String modeStr) {" + errorLine2=" ~~~~~~~~~"> + file="src/main/java/io/flutter/plugins/camera/features/autofocus/FocusMode.java" + line="18" + column="17"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations" + errorLine1=" public static FocusMode getValueForString(String modeStr) {" + errorLine2=" ~~~~~~"> + file="src/main/java/io/flutter/plugins/camera/features/autofocus/FocusMode.java" + line="18" + column="45"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations" + errorLine1=" public static FocusMode getValueForString(String modeStr) {" + errorLine2=" ~~~~~~~~~"> + file="src/main/java/io/flutter/plugins/camera/types/FocusMode.java" + line="18" + column="17"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations" + errorLine1=" public static FocusMode getValueForString(String modeStr) {" + errorLine2=" ~~~~~~"> + file="src/main/java/io/flutter/plugins/camera/types/FocusMode.java" + line="18" + column="45"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations" + errorLine1=" CameraProperties cameraProperties, SensorOrientationFeature sensorOrientationFeature) {" + errorLine2=" ~~~~~~~~~~~~~~~~"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations" + errorLine1=" public void setValue(NoiseReductionMode value) {" + errorLine2=" ~~~~~~~~~~~~~~~~~~"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations" + errorLine1=" public void setValue(Integer value) {" + errorLine2=" ~~~~~~~"> + file="src/main/java/io/flutter/plugins/camera/features/sensororientation/SensorOrientationFeature.java" + line="56" + column="24"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations" + errorLine1=" public void updateBuilder(CaptureRequest.Builder requestBuilder) {" + errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~"> + file="src/main/java/io/flutter/plugins/camera/features/sensororientation/SensorOrientationFeature.java" + line="66" + column="29"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations" + errorLine1=" public DeviceOrientationManager getDeviceOrientationManager() {" + errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~"> + + + + + + + + + column="10"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/camera/camera_android_camerax/android/build.gradle b/packages/camera/camera_android_camerax/android/build.gradle index 336e16009893..492d1374b8a7 100644 --- a/packages/camera/camera_android_camerax/android/build.gradle +++ b/packages/camera/camera_android_camerax/android/build.gradle @@ -49,8 +49,10 @@ android { } lintOptions { - disable 'AndroidGradlePluginVersion' - disable 'GradleDependency' + checkAllWarnings true + warningsAsErrors true + disable 'AndroidGradlePluginVersion', 'GradleDependency', 'InvalidPackage' + baseline file("lint-baseline.xml") } } diff --git a/packages/camera/camera_android_camerax/android/lint-baseline.xml b/packages/camera/camera_android_camerax/android/lint-baseline.xml new file mode 100644 index 000000000000..1142794741a6 --- /dev/null +++ b/packages/camera/camera_android_camerax/android/lint-baseline.xml @@ -0,0 +1,1434 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/espresso/android/build.gradle b/packages/espresso/android/build.gradle index c4d8b149c349..2aac3452e03c 100644 --- a/packages/espresso/android/build.gradle +++ b/packages/espresso/android/build.gradle @@ -29,6 +29,8 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' baseline file("lint-baseline.xml") } diff --git a/packages/espresso/android/lint-baseline.xml b/packages/espresso/android/lint-baseline.xml index 19b349f044bf..c07e756707eb 100644 --- a/packages/espresso/android/lint-baseline.xml +++ b/packages/espresso/android/lint-baseline.xml @@ -1,5 +1,5 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + file="src/main/java/androidx/test/espresso/flutter/internal/idgenerator/IdException.java" + line="20" + column="22"/> + + + + + + + + + + + + + + + + + + + + + + + + + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public WidgetMatcher getAncestorMatcher() {" + errorLine2=" ~~~~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/matcher/IsDescendantOfMatcher.java" + line="47" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public WidgetMatcher getWidgetMatcher() {" + errorLine2=" ~~~~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/matcher/IsDescendantOfMatcher.java" + line="52" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" protected boolean matchesSafely(WidgetInfo widget) {" + errorLine2=" ~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/matcher/IsDescendantOfMatcher.java" + line="62" + column="35"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public void describeTo(Description description) {" + errorLine2=" ~~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/matcher/IsDescendantOfMatcher.java" + line="68" + column="26"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" protected boolean matchesSafely(WidgetInfo widget) {" + errorLine2=" ~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/matcher/IsExistingMatcher.java" + line="23" + column="35"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public void describeTo(Description description) {" + errorLine2=" ~~~~~~~~~~~"> + + + + + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public JsonRpcClient(OkHttpClient client, URI webSocketUri) {" + errorLine2=" ~~~"> + file="src/main/java/androidx/test/espresso/flutter/internal/jsonrpc/JsonRpcClient.java" + line="45" + column="45"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public ListenableFuture<JsonRpcResponse> request(JsonRpcRequest request) {" + errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/internal/jsonrpc/JsonRpcClient.java" + line="74" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public ListenableFuture<JsonRpcResponse> request(JsonRpcRequest request) {" + errorLine2=" ~~~~~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/internal/jsonrpc/JsonRpcClient.java" + line="74" + column="52"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public static JsonRpcRequest fromJson(String jsonString) {" + errorLine2=" ~~~~~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/internal/jsonrpc/message/JsonRpcRequest.java" + line="51" + column="17"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public static JsonRpcRequest fromJson(String jsonString) {" + errorLine2=" ~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/internal/jsonrpc/message/JsonRpcRequest.java" + line="51" + column="41"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public String getVersion() {" + errorLine2=" ~~~~~~"> + line="86" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public String getId() {" + errorLine2=" ~~~~~~"> + line="95" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public String getMethod() {" + errorLine2=" ~~~~~~"> + line="104" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public JsonObject getParams() {" + errorLine2=" ~~~~~~~~~~"> + line="109" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public String toJson() {" + errorLine2=" ~~~~~~"> + line="118" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public Builder(String method) {" + errorLine2=" ~~~~~~"> + line="172" + column="20"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public Builder setId(@Nullable String id) {" + errorLine2=" ~~~~~~~"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + line="49" + column="17"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public static JsonRpcResponse fromJson(String jsonString) {" + errorLine2=" ~~~~~~"> + line="49" + column="42"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public JsonRpcResponse(String id) {" + errorLine2=" ~~~~~~"> + line="62" + column="26"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public String getVersion() {" + errorLine2=" ~~~~~~"> + line="72" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public String getId() {" + errorLine2=" ~~~~~~"> + line="77" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public void setId(String id) {" + errorLine2=" ~~~~~~"> + line="86" + column="21"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public JsonObject getResult() {" + errorLine2=" ~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/internal/jsonrpc/message/JsonRpcResponse.java" + line="91" + column="10"/> + + + + + + + + + + + + + + + + + + + + + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" protected String actionId;" + errorLine2=" ~~~~~~"> + line="30" + column="13"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public Future<Void> perform(" + errorLine2=" ~~~~~~~~~~~~"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public Future<WidgetInfo> perform(" + errorLine2=" ~~~~~~~~~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/action/WidgetInfoFetcher.java" + line="21" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" protected String matcherId;" + errorLine2=" ~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/api/WidgetMatcher.java" + line="31" + column="13"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public String getText() {" + errorLine2=" ~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/matcher/WithTextMatcher.java" + line="31" + column="10"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" protected boolean matchesSafely(WidgetInfo widget) {" + errorLine2=" ~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/matcher/WithTextMatcher.java" + line="41" + column="35"/> + id="UnknownNullness" + message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations" + errorLine1=" public void describeTo(Description description) {" + errorLine2=" ~~~~~~~~~~~"> + file="src/main/java/androidx/test/espresso/flutter/matcher/WithTextMatcher.java" + line="46" + column="26"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/flutter_plugin_android_lifecycle/android/build.gradle b/packages/flutter_plugin_android_lifecycle/android/build.gradle index 708eaff41758..8431e0bc2c8c 100644 --- a/packages/flutter_plugin_android_lifecycle/android/build.gradle +++ b/packages/flutter_plugin_android_lifecycle/android/build.gradle @@ -30,7 +30,10 @@ android { consumerProguardFiles 'proguard.txt' } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' + baseline file("lint-baseline.xml") } dependencies { diff --git a/packages/flutter_plugin_android_lifecycle/android/lint-baseline.xml b/packages/flutter_plugin_android_lifecycle/android/lint-baseline.xml new file mode 100644 index 000000000000..0c5fc18e5a6f --- /dev/null +++ b/packages/flutter_plugin_android_lifecycle/android/lint-baseline.xml @@ -0,0 +1,15 @@ + + + + + + + + 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 fef368e278b6..61b79a90a37f 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 @@ -29,7 +29,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' + baseline file("lint-baseline.xml") } dependencies { diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/lint-baseline.xml b/packages/google_maps_flutter/google_maps_flutter_android/android/lint-baseline.xml new file mode 100644 index 000000000000..092b2d57e775 --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/lint-baseline.xml @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 ef56fb68f41e..e7e0f043d9e7 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 @@ -29,7 +29,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' + baseline file("lint-baseline.xml") } diff --git a/packages/google_sign_in/google_sign_in_android/android/lint-baseline.xml b/packages/google_sign_in/google_sign_in_android/android/lint-baseline.xml new file mode 100644 index 000000000000..c59558ae18a2 --- /dev/null +++ b/packages/google_sign_in/google_sign_in_android/android/lint-baseline.xml @@ -0,0 +1,730 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/image_picker/image_picker_android/android/build.gradle b/packages/image_picker/image_picker_android/android/build.gradle index 3af3ba471df1..c4fb379533fa 100644 --- a/packages/image_picker/image_picker_android/android/build.gradle +++ b/packages/image_picker/image_picker_android/android/build.gradle @@ -29,7 +29,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' + baseline file("lint-baseline.xml") } dependencies { implementation 'androidx.core:core:1.9.0' diff --git a/packages/image_picker/image_picker_android/android/lint-baseline.xml b/packages/image_picker/image_picker_android/android/lint-baseline.xml new file mode 100644 index 000000000000..765a6ca914b7 --- /dev/null +++ b/packages/image_picker/image_picker_android/android/lint-baseline.xml @@ -0,0 +1,400 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 95a744d08eea..4385ad821f5e 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 @@ -29,7 +29,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' + baseline file("lint-baseline.xml") } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/packages/in_app_purchase/in_app_purchase_android/android/lint-baseline.xml b/packages/in_app_purchase/in_app_purchase_android/android/lint-baseline.xml new file mode 100644 index 000000000000..03eeb9568858 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_android/android/lint-baseline.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/local_auth/local_auth_android/android/build.gradle b/packages/local_auth/local_auth_android/android/build.gradle index 8e116709d6cc..6bd8e4d845d8 100644 --- a/packages/local_auth/local_auth_android/android/build.gradle +++ b/packages/local_auth/local_auth_android/android/build.gradle @@ -29,6 +29,8 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' baseline file("lint-baseline.xml") } diff --git a/packages/local_auth/local_auth_android/android/lint-baseline.xml b/packages/local_auth/local_auth_android/android/lint-baseline.xml index e89eaadb3e6d..3f0a47a6824d 100644 --- a/packages/local_auth/local_auth_android/android/lint-baseline.xml +++ b/packages/local_auth/local_auth_android/android/lint-baseline.xml @@ -1,5 +1,5 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/path_provider/path_provider_android/android/build.gradle b/packages/path_provider/path_provider_android/android/build.gradle index 96558c4248b6..7e348233d342 100644 --- a/packages/path_provider/path_provider_android/android/build.gradle +++ b/packages/path_provider/path_provider_android/android/build.gradle @@ -29,7 +29,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' + baseline file("lint-baseline.xml") } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/packages/path_provider/path_provider_android/android/lint-baseline.xml b/packages/path_provider/path_provider_android/android/lint-baseline.xml new file mode 100644 index 000000000000..4ae0352f93c6 --- /dev/null +++ b/packages/path_provider/path_provider_android/android/lint-baseline.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/quick_actions/quick_actions_android/android/build.gradle b/packages/quick_actions/quick_actions_android/android/build.gradle index 269f44d66d6b..a668fb053871 100644 --- a/packages/quick_actions/quick_actions_android/android/build.gradle +++ b/packages/quick_actions/quick_actions_android/android/build.gradle @@ -29,7 +29,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' + baseline file("lint-baseline.xml") } dependencies { diff --git a/packages/quick_actions/quick_actions_android/android/lint-baseline.xml b/packages/quick_actions/quick_actions_android/android/lint-baseline.xml new file mode 100644 index 000000000000..2df302dcb73c --- /dev/null +++ b/packages/quick_actions/quick_actions_android/android/lint-baseline.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/shared_preferences/shared_preferences_android/android/build.gradle b/packages/shared_preferences/shared_preferences_android/android/build.gradle index 9893ba6219f4..905150edf786 100644 --- a/packages/shared_preferences/shared_preferences_android/android/build.gradle +++ b/packages/shared_preferences/shared_preferences_android/android/build.gradle @@ -37,6 +37,8 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' baseline file("lint-baseline.xml") } diff --git a/packages/shared_preferences/shared_preferences_android/android/lint-baseline.xml b/packages/shared_preferences/shared_preferences_android/android/lint-baseline.xml index 6b2f35f5a151..ca2bc158739f 100644 --- a/packages/shared_preferences/shared_preferences_android/android/lint-baseline.xml +++ b/packages/shared_preferences/shared_preferences_android/android/lint-baseline.xml @@ -1,5 +1,5 @@ - + @@ -63,7 +63,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~"> @@ -74,8 +74,52 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~"> + + + + + + + + + + + + + + + + diff --git a/packages/url_launcher/url_launcher_android/android/build.gradle b/packages/url_launcher/url_launcher_android/android/build.gradle index d066fde7b176..0b34862c6468 100644 --- a/packages/url_launcher/url_launcher_android/android/build.gradle +++ b/packages/url_launcher/url_launcher_android/android/build.gradle @@ -29,7 +29,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' + baseline file("lint-baseline.xml") } diff --git a/packages/url_launcher/url_launcher_android/android/lint-baseline.xml b/packages/url_launcher/url_launcher_android/android/lint-baseline.xml new file mode 100644 index 000000000000..fa3c2e350b48 --- /dev/null +++ b/packages/url_launcher/url_launcher_android/android/lint-baseline.xml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/video_player/video_player_android/android/build.gradle b/packages/video_player/video_player_android/android/build.gradle index 73b73526f617..9145f6c8b316 100644 --- a/packages/video_player/video_player_android/android/build.gradle +++ b/packages/video_player/video_player_android/android/build.gradle @@ -34,7 +34,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' + baseline file("lint-baseline.xml") } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/packages/video_player/video_player_android/android/lint-baseline.xml b/packages/video_player/video_player_android/android/lint-baseline.xml new file mode 100644 index 000000000000..4649a80f7b92 --- /dev/null +++ b/packages/video_player/video_player_android/android/lint-baseline.xml @@ -0,0 +1,653 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/webview_flutter/webview_flutter_android/android/build.gradle b/packages/webview_flutter/webview_flutter_android/android/build.gradle index f50f273ab2b2..540c208a1895 100644 --- a/packages/webview_flutter/webview_flutter_android/android/build.gradle +++ b/packages/webview_flutter/webview_flutter_android/android/build.gradle @@ -30,10 +30,10 @@ android { } lintOptions { - // See https://sites.google.com/a/android.com/tools/tips/lint-checks for all available - // android lint checks. - error 'ViewConstructor' + checkAllWarnings true + warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' + baseline file("lint-baseline.xml") } dependencies { diff --git a/packages/webview_flutter/webview_flutter_android/android/lint-baseline.xml b/packages/webview_flutter/webview_flutter_android/android/lint-baseline.xml new file mode 100644 index 000000000000..10821e05e8b3 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/lint-baseline.xml @@ -0,0 +1,4107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/script/tool/lib/src/lint_android_command.dart b/script/tool/lib/src/lint_android_command.dart index f146b2d4fbbe..3fe25eec2835 100644 --- a/script/tool/lib/src/lint_android_command.dart +++ b/script/tool/lib/src/lint_android_command.dart @@ -39,11 +39,28 @@ class LintAndroidCommand extends PackageLoopingCommand { } bool failed = false; + + // Ensure that the plugin has a strict Gradle-driven lint configuration, so + // that this test actually catches most issues. + if (!_mainGradleHasLintConfig(package)) { + failed = true; + printError('This plugin is not configured to enable all Gradle-driven ' + 'lint warnings and treat them as errors. ' + 'Please add the following to the lintOptions section of ' + 'android/build.gradle:'); + print(''' + checkAllWarnings true + warningsAsErrors true +'''); + } + for (final RepositoryPackage example in package.getExamples()) { final GradleProject project = GradleProject(example, processRunner: processRunner, platform: platform); if (!project.isConfigured()) { + // TODO(stuartmorgan): Replace this with a --config-only build once + // that's available on stable. return PackageResult.fail(['Build examples before linting']); } @@ -61,25 +78,13 @@ class LintAndroidCommand extends PackageLoopingCommand { failed = true; } - // In addition to running the Gradle lint step, also ensure that the - // example project is configured to build with javac lints enabled and + // In addition to running the Gradle-driven lint step, also ensure that + // the example project is configured to build with javac lints enabled and // treated as errors. - final List gradleBuildContents = example - .platformDirectory(FlutterPlatform.android) - .childFile('build.gradle') - .readAsLinesSync(); - // The check here is intentionally somewhat loose, to allow for the - // possibility of variations (e.g., not using Xlint:all in some cases, or - // passing other arguments). - if (!gradleBuildContents.any( - (String line) => line.contains('project(":$packageName")')) || - !gradleBuildContents.any((String line) => - line.contains('options.compilerArgs') && - line.contains('-Xlint') && - line.contains('-Werror'))) { + if (!_exampleGradleHasJavacLintConfig(example, packageName)) { failed = true; printError('The example ' - '${getRelativePosixPath(example.directory, from: package.directory)} ' + '"${getRelativePosixPath(example.directory, from: package.directory)}" ' 'is not configured to treat javac lints and warnings as errors. ' 'Please add the following to its build.gradle:'); print(''' @@ -96,4 +101,36 @@ gradle.projectsEvaluated { return failed ? PackageResult.fail() : PackageResult.success(); } + + /// Returns whether the plugin project is configured to enable all Gradle + /// lints and treat them as errors. + bool _mainGradleHasLintConfig(RepositoryPackage package) { + final List gradleBuildContents = package + .platformDirectory(FlutterPlatform.android) + .childFile('build.gradle') + .readAsLinesSync(); + return gradleBuildContents + .any((String line) => line.contains('checkAllWarnings true')) && + gradleBuildContents + .any((String line) => line.contains('warningsAsErrors true')); + } + + /// Returns whether the example project is configured to build with javac + /// lints enabled and treated as errors. + bool _exampleGradleHasJavacLintConfig( + RepositoryPackage example, String pluginPackageName) { + final List gradleBuildContents = example + .platformDirectory(FlutterPlatform.android) + .childFile('build.gradle') + .readAsLinesSync(); + // The check here is intentionally somewhat loose, to allow for the + // possibility of variations (e.g., not using Xlint:all in some cases, or + // passing other arguments). + return gradleBuildContents.any( + (String line) => line.contains('project(":$pluginPackageName")')) && + gradleBuildContents.any((String line) => + line.contains('options.compilerArgs') && + line.contains('-Xlint') && + line.contains('-Werror')); + } } diff --git a/script/tool/test/lint_android_command_test.dart b/script/tool/test/lint_android_command_test.dart index ee1db42f1041..614e60d105a1 100644 --- a/script/tool/test/lint_android_command_test.dart +++ b/script/tool/test/lint_android_command_test.dart @@ -37,7 +37,46 @@ void main() { runner.addCommand(command); }); - void writeFakeBuildGradle(RepositoryPackage example, String pluginName, + void writeFakePluginBuildGradle(RepositoryPackage plugin, + {bool warningsConfigured = true}) { + const String warningConfig = ''' + lintOptions { + checkAllWarnings true + warningsAsErrors true + disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' + baseline file("lint-baseline.xml") + } +'''; + final File gradleFile = plugin + .platformDirectory(FlutterPlatform.android) + .childFile('build.gradle'); + gradleFile.createSync(recursive: true); + gradleFile.writeAsStringSync(''' +android { + compileSdkVersion 33 + + defaultConfig { + minSdkVersion 16 + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } +${warningsConfigured ? warningConfig : ''} + testOptions { + unitTests.returnDefaultValues = true + unitTests.all { + testLogging { + events "passed", "skipped", "failed", "standardOut", "standardError" + outputs.upToDateWhen {false} + showStandardStreams = true + } + } + } +} + +'''); + } + + void writeFakeExampleBuildGradle( + RepositoryPackage example, String pluginName, {bool warningsConfigured = true}) { final String warningConfig = ''' gradle.projectsEvaluated { @@ -78,7 +117,8 @@ ${warningsConfigured ? warningConfig : ''} ], platformSupport: { platformAndroid: const PlatformDetails(PlatformSupport.inline) }); - writeFakeBuildGradle(plugin.getExamples().first, 'plugin1'); + writeFakePluginBuildGradle(plugin); + writeFakeExampleBuildGradle(plugin.getExamples().first, 'plugin1'); final Directory androidDir = plugin.getExamples().first.platformDirectory(FlutterPlatform.android); @@ -116,8 +156,9 @@ ${warningsConfigured ? warningConfig : ''} platformSupport: { platformAndroid: const PlatformDetails(PlatformSupport.inline) }); + writeFakePluginBuildGradle(plugin); for (final RepositoryPackage example in plugin.getExamples()) { - writeFakeBuildGradle(example, 'plugin1'); + writeFakeExampleBuildGradle(example, 'plugin1'); } final Iterable exampleAndroidDirs = plugin.getExamples().map( @@ -148,10 +189,11 @@ ${warningsConfigured ? warningConfig : ''} }); test('fails if gradlew is missing', () async { - createFakePlugin('plugin1', packagesDir, + final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir, platformSupport: { platformAndroid: const PlatformDetails(PlatformSupport.inline) }); + writeFakePluginBuildGradle(plugin); Error? commandError; final List output = await runCapturingPrint( @@ -176,7 +218,8 @@ ${warningsConfigured ? warningConfig : ''} ], platformSupport: { platformAndroid: const PlatformDetails(PlatformSupport.inline) }); - writeFakeBuildGradle(plugin.getExamples().first, 'plugin1'); + writeFakePluginBuildGradle(plugin); + writeFakeExampleBuildGradle(plugin.getExamples().first, 'plugin1'); final String gradlewPath = plugin .getExamples() @@ -204,6 +247,34 @@ ${warningsConfigured ? warningConfig : ''} )); }); + test('fails if gradle-driven lint-warnings-as-errors is missing', () async { + final RepositoryPackage plugin = + createFakePlugin('plugin1', packagesDir, extraFiles: [ + 'example/android/gradlew', + ], platformSupport: { + platformAndroid: const PlatformDetails(PlatformSupport.inline) + }); + writeFakePluginBuildGradle(plugin, warningsConfigured: false); + writeFakeExampleBuildGradle(plugin.getExamples().first, 'plugin1'); + + Error? commandError; + final List output = await runCapturingPrint( + runner, ['lint-android'], errorHandler: (Error e) { + commandError = e; + }); + + expect(commandError, isA()); + expect( + output, + containsAllInOrder( + [ + contains('This plugin is not configured to enable all ' + 'Gradle-driven lint warnings and treat them as errors.'), + contains('The following packages had errors:'), + ], + )); + }); + test('fails if javac lint-warnings-as-errors is missing', () async { final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir, extraFiles: [ @@ -211,7 +282,8 @@ ${warningsConfigured ? warningConfig : ''} ], platformSupport: { platformAndroid: const PlatformDetails(PlatformSupport.inline) }); - writeFakeBuildGradle(plugin.getExamples().first, 'plugin1', + writeFakePluginBuildGradle(plugin); + writeFakeExampleBuildGradle(plugin.getExamples().first, 'plugin1', warningsConfigured: false); Error? commandError; @@ -225,7 +297,7 @@ ${warningsConfigured ? warningConfig : ''} output, containsAllInOrder( [ - contains('The example example is not configured to treat javac ' + contains('The example "example" is not configured to treat javac ' 'lints and warnings as errors.'), contains('The following packages had errors:'), ],