gradle_errors.dart 22.6 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:meta/meta.dart';

7 8
import '../base/error_handling_io.dart';
import '../base/file_system.dart';
9
import '../base/process.dart';
10
import '../base/terminal.dart';
11
import '../globals.dart' as globals;
12 13
import '../project.dart';
import '../reporting/reporting.dart';
14
import 'gradle_utils.dart';
15 16 17 18

typedef GradleErrorTest = bool Function(String);

/// A Gradle error handled by the tool.
19
class GradleHandledError {
20
  const GradleHandledError({
21 22
    required this.test,
    required this.handler,
23 24 25 26 27 28 29 30 31
    this.eventLabel,
  });

  /// The test function.
  /// Returns [true] if the current error message should be handled.
  final GradleErrorTest test;

  /// The handler function.
  final Future<GradleBuildStatus> Function({
32 33 34
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
35 36
  }) handler;

37
  /// The [BuildEvent] label is named gradle-[eventLabel].
38 39
  /// If not empty, the build event is logged along with
  /// additional metadata such as the attempt number.
40
  final String? eventLabel;
41 42 43
}

/// The status of the Gradle build.
44
enum GradleBuildStatus {
45 46 47 48 49 50
  /// The tool cannot recover from the failure and should exit.
  exit,
  /// The tool can retry the exact same build.
  retry,
}

51 52
/// Returns a simple test function that evaluates to `true` if at least one of
/// `errorMessages` is contained in the error message.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
GradleErrorTest _lineMatcher(List<String> errorMessages) {
  return (String line) {
    return errorMessages.any((String errorMessage) => line.contains(errorMessage));
  };
}

/// The list of Gradle errors that the tool can handle.
///
/// The handlers are executed in the order in which they appear in the list.
///
/// Only the first error handler for which the [test] function returns [true]
/// is handled. As a result, sort error handlers based on how strict the [test]
/// function is to eliminate false positives.
final List<GradleHandledError> gradleErrors = <GradleHandledError>[
  licenseNotAcceptedHandler,
  networkErrorHandler,
  permissionDeniedErrorHandler,
  flavorUndefinedHandler,
  r8FailureHandler,
72 73 74
  minSdkVersionHandler,
  transformInputIssueHandler,
  lockFileDepMissingHandler,
75
  incompatibleKotlinVersionHandler,
76
  minCompileSdkVersionHandler,
77
  jvm11RequiredHandler,
78
  outdatedGradleHandler,
79
  sslExceptionHandler,
80
  zipExceptionHandler,
81
  incompatibleJavaAndGradleVersionsHandler,
82
  remoteTerminatedHandshakeHandler,
83
  couldNotOpenCacheDirectoryHandler,
84 85
];

86 87
const String _boxTitle = 'Flutter Fix';

88 89 90 91 92 93 94
// Permission defined error message.
@visibleForTesting
final GradleHandledError permissionDeniedErrorHandler = GradleHandledError(
  test: _lineMatcher(const <String>[
    'Permission denied',
  ]),
  handler: ({
95 96 97
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
98
  }) async {
99 100
    globals.printBox(
      '${globals.logger.terminal.warningMark} Gradle does not have execution permission.\n'
101 102
      'You should change the ownership of the project directory to your user, '
      'or move the project to a directory with execute permissions.',
103
      title: _boxTitle,
104 105 106 107 108 109
    );
    return GradleBuildStatus.exit;
  },
  eventLabel: 'permission-denied',
);

110 111
/// Gradle crashes for several known reasons when downloading that are not
/// actionable by Flutter.
112 113 114
@visibleForTesting
final GradleHandledError networkErrorHandler = GradleHandledError(
  test: _lineMatcher(const <String>[
115 116
    "> Could not get resource 'http",
    'java.io.FileNotFoundException',
117
    'java.io.FileNotFoundException: https://downloads.gradle.org',
118
    'java.io.IOException: Server returned HTTP response code: 502',
119
    'java.io.IOException: Unable to tunnel through proxy',
120
    'java.lang.RuntimeException: Timeout of',
121 122
    'java.net.ConnectException: Connection timed out',
    'java.net.SocketException: Connection reset',
123 124 125 126
    'java.util.zip.ZipException: error in opening zip file',
    'javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake',
  ]),
  handler: ({
127 128 129
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
130
  }) async {
131
    globals.printError(
132 133
      '${globals.logger.terminal.warningMark} '
      'Gradle threw an error while downloading artifacts from the network.'
134
    );
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    return GradleBuildStatus.retry;
  },
  eventLabel: 'network',
);

/// Handles corrupted jar or other types of zip files.
///
/// If a terminal is attached, this handler prompts the user if they would like to
/// delete the $HOME/.gradle directory prior to retrying the build.
///
/// If this handler runs on a bot (e.g. a CI bot), the $HOME/.gradle is automatically deleted.
///
/// See also:
///  * https://github.com/flutter/flutter/issues/51195
///  * https://github.com/flutter/flutter/issues/89959
///  * https://docs.gradle.org/current/userguide/directory_layout.html#dir:gradle_user_home
@visibleForTesting
final GradleHandledError zipExceptionHandler = GradleHandledError(
  test: _lineMatcher(const <String>[
    'java.util.zip.ZipException: error in opening zip file',
  ]),
  handler: ({
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
  }) async {
    globals.printError(
      '${globals.logger.terminal.warningMark} '
      'Your .gradle directory under the home directory might be corrupted.'
    );
    bool shouldDeleteUserGradle = await globals.botDetector.isRunningOnBot;
    if (!shouldDeleteUserGradle && globals.terminal.stdinHasTerminal) {
      try {
        final String selection = await globals.terminal.promptForCharInput(
          <String>['y', 'n'],
          logger: globals.logger,
          prompt: 'Do you want to delete the .gradle directory under the home directory?',
          defaultChoiceIndex: 0,
        );
        shouldDeleteUserGradle = selection == 'y';
175
      } on StateError catch (e) {
176 177 178 179 180 181 182
        globals.printError(
          e.message,
          indent: 0,
        );
      }
    }
    if (shouldDeleteUserGradle) {
183
      final String? homeDir = globals.platform.environment['HOME'];
184 185 186 187 188 189 190 191 192 193
      if (homeDir == null) {
        globals.logger.printStatus("Could not delete .gradle directory because there isn't a HOME env variable");
        return GradleBuildStatus.retry;
      }
      final Directory userGradle = globals.fs.directory(globals.fs.path.join(homeDir, '.gradle'));
      globals.logger.printStatus('Deleting ${userGradle.path}');
      try {
        ErrorHandlingFileSystem.deleteIfExists(userGradle, recursive: true);
      } on FileSystemException catch (err) {
        globals.printTrace('Failed to delete Gradle cache: $err');
194 195
      }
    }
196 197
    return GradleBuildStatus.retry;
  },
198
  eventLabel: 'zip-exception',
199 200 201 202 203 204 205 206 207
);

// R8 failure.
@visibleForTesting
final GradleHandledError r8FailureHandler = GradleHandledError(
  test: _lineMatcher(const <String>[
    'com.android.tools.r8',
  ]),
  handler: ({
208 209 210
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
211
  }) async {
212 213 214 215 216 217
    globals.printBox(
      '${globals.logger.terminal.warningMark} The shrinker may have failed to optimize the Java bytecode.\n'
      'To disable the shrinker, pass the `--no-shrink` flag to this command.\n'
      'To learn more, see: https://developer.android.com/studio/build/shrink-code',
      title: _boxTitle,
    );
218 219 220 221 222 223 224 225 226 227 228 229 230 231
    return GradleBuildStatus.exit;
  },
  eventLabel: 'r8',
);

/// Handle Gradle error thrown when Gradle needs to download additional
/// Android SDK components (e.g. Platform Tools), and the license
/// for that component has not been accepted.
@visibleForTesting
final GradleHandledError licenseNotAcceptedHandler = GradleHandledError(
  test: _lineMatcher(const <String>[
    'You have not accepted the license agreements of the following SDK components',
  ]),
  handler: ({
232 233 234
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
235 236
  }) async {
    const String licenseNotAcceptedMatcher =
237
      r'You have not accepted the license agreements of the following SDK components:\s*\[(.+)\]';
238 239

    final RegExp licenseFailure = RegExp(licenseNotAcceptedMatcher, multiLine: true);
240
    final Match? licenseMatch = licenseFailure.firstMatch(line);
241
    globals.printBox(
242
      '${globals.logger.terminal.warningMark} Unable to download needed Android SDK components, as the '
243
      'following licenses have not been accepted: '
244
      '${licenseMatch?.group(1)}\n\n'
245
      'To resolve this, please run the following command in a Terminal:\n'
246 247
      'flutter doctor --android-licenses',
      title: _boxTitle,
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
    );
    return GradleBuildStatus.exit;
  },
  eventLabel: 'license-not-accepted',
);

final RegExp _undefinedTaskPattern = RegExp(r'Task .+ not found in root project.');

final RegExp _assembleTaskPattern = RegExp(r'assemble(\S+)');

/// Handler when a flavor is undefined.
@visibleForTesting
final GradleHandledError flavorUndefinedHandler = GradleHandledError(
  test: (String line) {
    return _undefinedTaskPattern.hasMatch(line);
  },
  handler: ({
265 266 267
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
268
  }) async {
269
    final RunResult tasksRunResult = await globals.processUtils.run(
270
      <String>[
271
        globals.gradleUtils!.getExecutable(project),
272 273 274 275 276 277
        'app:tasks' ,
        '--all',
        '--console=auto',
      ],
      throwOnError: true,
      workingDirectory: project.android.hostAppGradleRoot.path,
278
      environment: globals.java?.environment,
279 280 281
    );
    // Extract build types and product flavors.
    final Set<String> variants = <String>{};
282
    for (final String task in tasksRunResult.stdout.split('\n')) {
283
      final Match? match = _assembleTaskPattern.matchAsPrefix(task);
284
      if (match != null) {
285
        final String variant = match.group(1)!.toLowerCase();
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
        if (!variant.endsWith('test')) {
          variants.add(variant);
        }
      }
    }
    final Set<String> productFlavors = <String>{};
    for (final String variant1 in variants) {
      for (final String variant2 in variants) {
        if (variant2.startsWith(variant1) && variant2 != variant1) {
          final String buildType = variant2.substring(variant1.length);
          if (variants.contains(buildType)) {
            productFlavors.add(variant1);
          }
        }
      }
    }
302 303
    final String errorMessage = '${globals.logger.terminal.warningMark}  Gradle project does not define a task suitable for the requested build.';
    final File buildGradle = project.directory.childDirectory('android').childDirectory('app').childFile('build.gradle');
304
    if (productFlavors.isEmpty) {
305 306 307
      globals.printBox(
        '$errorMessage\n\n'
        'The ${buildGradle.absolute.path} file does not define '
308
        'any custom product flavors. '
309 310
        'You cannot use the --flavor option.',
        title: _boxTitle,
311 312
      );
    } else {
313 314 315 316 317 318
      globals.printBox(
        '$errorMessage\n\n'
        'The ${buildGradle.absolute.path} file defines product '
        'flavors: ${productFlavors.join(', ')}. '
        'You must specify a --flavor option to select one of them.',
        title: _boxTitle,
319 320 321 322 323 324
      );
    }
    return GradleBuildStatus.exit;
  },
  eventLabel: 'flavor-undefined',
);
325 326 327 328 329 330


final RegExp _minSdkVersionPattern = RegExp(r'uses-sdk:minSdkVersion ([0-9]+) cannot be smaller than version ([0-9]+) declared in library \[\:(.+)\]');

/// Handler when a plugin requires a higher Android API level.
@visibleForTesting
331
final GradleHandledError minSdkVersionHandler = GradleHandledError(
332 333 334 335
  test: (String line) {
    return _minSdkVersionPattern.hasMatch(line);
  },
  handler: ({
336 337 338
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
339
  }) async {
340
    final File gradleFile = project.directory
341
        .childDirectory('android')
342 343
        .childDirectory('app')
        .childFile('build.gradle');
344

345 346
    final Match? minSdkVersionMatch = _minSdkVersionPattern.firstMatch(line);
    assert(minSdkVersionMatch?.groupCount == 3);
347

348
    final String textInBold = globals.logger.terminal.bolden(
349 350 351 352 353 354
      'Fix this issue by adding the following to the file ${gradleFile.path}:\n'
      'android {\n'
      '  defaultConfig {\n'
      '    minSdkVersion ${minSdkVersionMatch?.group(2)}\n'
      '  }\n'
      '}\n'
355
    );
356
    globals.printBox(
357
      'The plugin ${minSdkVersionMatch?.group(3)} requires a higher Android SDK version.\n'
358
      '$textInBold\n'
359 360
      'Following this change, your app will not be available to users running Android SDKs below ${minSdkVersionMatch?.group(2)}.\n'
      'Consider searching for a version of this plugin that supports these lower versions of the Android SDK instead.\n'
361
      'For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration',
362
      title: _boxTitle,
363 364 365 366 367
    );
    return GradleBuildStatus.exit;
  },
  eventLabel: 'plugin-min-sdk',
);
368 369 370 371

/// Handler when https://issuetracker.google.com/issues/141126614 or
/// https://github.com/flutter/flutter/issues/58247 is triggered.
@visibleForTesting
372
final GradleHandledError transformInputIssueHandler = GradleHandledError(
373 374 375 376
  test: (String line) {
    return line.contains('https://issuetracker.google.com/issues/158753935');
  },
  handler: ({
377 378 379
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
380 381 382 383 384
  }) async {
    final File gradleFile = project.directory
        .childDirectory('android')
        .childDirectory('app')
        .childFile('build.gradle');
385
    final String textInBold = globals.logger.terminal.bolden(
386 387 388 389 390 391 392
      'Fix this issue by adding the following to the file ${gradleFile.path}:\n'
      'android {\n'
      '  lintOptions {\n'
      '    checkReleaseBuilds false\n'
      '  }\n'
      '}'
    );
393
    globals.printBox(
394
      'This issue appears to be https://github.com/flutter/flutter/issues/58247.\n'
395 396
      '$textInBold',
      title: _boxTitle,
397 398 399 400 401
    );
    return GradleBuildStatus.exit;
  },
  eventLabel: 'transform-input-issue',
);
402 403 404

/// Handler when a dependency is missing in the lockfile.
@visibleForTesting
405
final GradleHandledError lockFileDepMissingHandler = GradleHandledError(
406 407 408 409
  test: (String line) {
    return line.contains('which is not part of the dependency lock state');
  },
  handler: ({
410 411 412
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
413 414 415 416
  }) async {
    final File gradleFile = project.directory
        .childDirectory('android')
        .childFile('build.gradle');
417
    final String textInBold = globals.logger.terminal.bolden(
418
      'To regenerate the lockfiles run: `./gradlew :generateLockfiles` in ${gradleFile.path}\n'
419
      'To remove dependency locking, remove the `dependencyLocking` from ${gradleFile.path}'
420
    );
421
    globals.printBox(
422
      'You need to update the lockfile, or disable Gradle dependency locking.\n'
423 424
      '$textInBold',
      title: _boxTitle,
425 426 427 428 429
    );
    return GradleBuildStatus.exit;
  },
  eventLabel: 'lock-dep-issue',
);
430 431 432 433

@visibleForTesting
final GradleHandledError incompatibleKotlinVersionHandler = GradleHandledError(
  test: _lineMatcher(const <String>[
434
    'was compiled with an incompatible version of Kotlin',
435 436 437 438 439 440 441 442 443
  ]),
  handler: ({
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
  }) async {
    final File gradleFile = project.directory
        .childDirectory('android')
        .childFile('build.gradle');
444 445
    globals.printBox(
      '${globals.logger.terminal.warningMark} Your project requires a newer version of the Kotlin Gradle plugin.\n'
446
      'Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then update ${gradleFile.path}:\n'
447
      "ext.kotlin_version = '<latest-version>'",
448
      title: _boxTitle,
449 450 451 452 453
    );
    return GradleBuildStatus.exit;
  },
  eventLabel: 'incompatible-kotlin-version',
);
454

455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
final RegExp _outdatedGradlePattern = RegExp(r'The current Gradle version (.+) is not compatible with the Kotlin Gradle plugin');

@visibleForTesting
final GradleHandledError outdatedGradleHandler = GradleHandledError(
  test: _outdatedGradlePattern.hasMatch,
  handler: ({
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
  }) async {
    final File gradleFile = project.directory
        .childDirectory('android')
        .childFile('build.gradle');
    final File gradlePropertiesFile = project.directory
        .childDirectory('android')
        .childDirectory('gradle')
        .childDirectory('wrapper')
        .childFile('gradle-wrapper.properties');
    globals.printBox(
      '${globals.logger.terminal.warningMark} Your project needs to upgrade Gradle and the Android Gradle plugin.\n\n'
      'To fix this issue, replace the following content:\n'
      '${gradleFile.path}:\n'
      '    ${globals.terminal.color("- classpath 'com.android.tools.build:gradle:<current-version>'", TerminalColor.red)}\n'
      '    ${globals.terminal.color("+ classpath 'com.android.tools.build:gradle:$templateAndroidGradlePluginVersion'", TerminalColor.green)}\n'
      '${gradlePropertiesFile.path}:\n'
      '    ${globals.terminal.color('- https://services.gradle.org/distributions/gradle-<current-version>-all.zip', TerminalColor.red)}\n'
      '    ${globals.terminal.color('+ https://services.gradle.org/distributions/gradle-$templateDefaultGradleVersion-all.zip', TerminalColor.green)}',
      title: _boxTitle,
    );
    return GradleBuildStatus.exit;
  },
  eventLabel: 'outdated-gradle-version',
);

489 490 491 492 493 494 495 496 497 498
final RegExp _minCompileSdkVersionPattern = RegExp(r'The minCompileSdk \(([0-9]+)\) specified in a');

@visibleForTesting
final GradleHandledError minCompileSdkVersionHandler = GradleHandledError(
  test: _minCompileSdkVersionPattern.hasMatch,
  handler: ({
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
  }) async {
499 500
    final Match? minCompileSdkVersionMatch = _minCompileSdkVersionPattern.firstMatch(line);
    assert(minCompileSdkVersionMatch?.groupCount == 1);
501 502 503 504 505 506

    final File gradleFile = project.directory
        .childDirectory('android')
        .childDirectory('app')
        .childFile('build.gradle');
    globals.printBox(
507 508
      '${globals.logger.terminal.warningMark} Your project requires a higher compileSdk version.\n'
      'Fix this issue by bumping the compileSdk version in ${gradleFile.path}:\n'
509
      'android {\n'
510
      '  compileSdk ${minCompileSdkVersionMatch?.group(1)}\n'
511 512 513 514 515 516 517
      '}',
      title: _boxTitle,
    );
    return GradleBuildStatus.exit;
  },
  eventLabel: 'min-compile-sdk-version',
);
518 519

@visibleForTesting
520
final GradleHandledError jvm11RequiredHandler = GradleHandledError(
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
  test: (String line) {
    return line.contains('Android Gradle plugin requires Java 11 to run');
  },
  handler: ({
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
  }) async {
    globals.printBox(
      '${globals.logger.terminal.warningMark} You need Java 11 or higher to build your app with this version of Gradle.\n\n'
      'To get Java 11, update to the latest version of Android Studio on https://developer.android.com/studio/install.\n\n'
      'To check the Java version used by Flutter, run `flutter doctor -v`.',
      title: _boxTitle,
    );
    return GradleBuildStatus.exit;
  },
  eventLabel: 'java11-required',
);
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559

/// Handles SSL exceptions: https://github.com/flutter/flutter/issues/104628
@visibleForTesting
final GradleHandledError sslExceptionHandler = GradleHandledError(
  test: _lineMatcher(const <String>[
    'javax.net.ssl.SSLException: Tag mismatch!',
    'javax.crypto.AEADBadTagException: Tag mismatch!',
  ]),
  handler: ({
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
  }) async {
    globals.printError(
      '${globals.logger.terminal.warningMark} '
      'Gradle threw an error while downloading artifacts from the network.'
    );
    return GradleBuildStatus.retry;
  },
  eventLabel: 'ssl-exception-tag-mismatch',
);
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575

/// If an incompatible Java and Gradle versions error is caught, we expect an
/// error specifying that the Java major class file version, one of
/// https://javaalmanac.io/bytecode/versions/, is unsupported by Gradle.
final RegExp _unsupportedClassFileMajorVersionPattern = RegExp(r'Unsupported class file major version\s+\d+');

@visibleForTesting
final GradleHandledError incompatibleJavaAndGradleVersionsHandler = GradleHandledError(
  test: (String line) {
    return _unsupportedClassFileMajorVersionPattern.hasMatch(line);
  },
  handler: ({
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
  }) async {
576 577 578 579 580
    final File gradlePropertiesFile = project.directory
        .childDirectory('android')
        .childDirectory('gradle')
        .childDirectory('wrapper')
        .childFile('gradle-wrapper.properties');
581 582 583 584
    // TODO(reidbaker): Replace URL with constant defined in
    // https://github.com/flutter/flutter/pull/123916.
    globals.printBox(
      "${globals.logger.terminal.warningMark} Your project's Gradle version "
585 586 587 588 589 590 591 592 593
          'is incompatible with the Java version that Flutter is using for Gradle.\n\n'
          'If you recently upgraded Android Studio, consult the migration guide '
          'at docs.flutter.dev/go/android-java-gradle-error.\n\n'
          'Otherwise, to fix this issue, first, check the Java version used by Flutter by '
          'running `flutter doctor --verbose`.\n\n'
          'Then, update the Gradle version specified in ${gradlePropertiesFile.path} '
          'to be compatible with that Java version. '
          'See the link below for more information on compatible Java/Gradle versions:\n'
          'https://docs.gradle.org/current/userguide/compatibility.html#java\n\n',
594 595 596 597 598 599
      title: _boxTitle,
    );
    return GradleBuildStatus.exit;
  },
  eventLabel: 'incompatible-java-gradle-version',
);
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617

@visibleForTesting
final GradleHandledError remoteTerminatedHandshakeHandler = GradleHandledError(
  test: (String line) => line.contains('Remote host terminated the handshake'),
  handler: ({
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
  }) async {
    globals.printError(
      '${globals.logger.terminal.warningMark} '
      'Gradle threw an error while downloading artifacts from the network.'
    );

    return GradleBuildStatus.retry;
  },
  eventLabel: 'remote-terminated-handshake',
);
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635

@visibleForTesting
final GradleHandledError couldNotOpenCacheDirectoryHandler = GradleHandledError(
  test: (String line) => line.contains('> Could not open cache directory '),
  handler: ({
    required String line,
    required FlutterProject project,
    required bool usesAndroidX,
  }) async {
    globals.printError(
      '${globals.logger.terminal.warningMark} '
      'Gradle threw an error while resolving dependencies.'
    );

    return GradleBuildStatus.retry;
  },
  eventLabel: 'could-not-open-cache-directory',
);