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

5
import 'package:meta/meta.dart';
Dan Field's avatar
Dan Field committed
6
import 'package:xml/xml.dart';
7
import 'package:yaml/yaml.dart';
8

9
import '../src/convert.dart';
10
import 'android/gradle_utils.dart' as gradle;
11
import 'base/common.dart';
12
import 'base/error_handling_io.dart';
13
import 'base/file_system.dart';
14
import 'base/logger.dart';
15
import 'base/utils.dart';
16
import 'bundle.dart' as bundle;
17
import 'cmake_project.dart';
18
import 'features.dart';
19
import 'flutter_manifest.dart';
20
import 'flutter_plugins.dart';
21
import 'globals_null_migrated.dart' as globals;
22
import 'platform_plugins.dart';
23
import 'template.dart';
24 25 26 27
import 'xcode_project.dart';

export 'cmake_project.dart';
export 'xcode_project.dart';
28

29
class FlutterProjectFactory {
30
  FlutterProjectFactory({
31 32
    required Logger logger,
    required FileSystem fileSystem,
33 34 35 36 37
  }) : _logger = logger,
       _fileSystem = fileSystem;

  final Logger _logger;
  final FileSystem _fileSystem;
38

39 40
  @visibleForTesting
  final Map<String, FlutterProject> projects =
41
      <String, FlutterProject>{};
42 43 44 45 46

  /// Returns a [FlutterProject] view of the given directory or a ToolExit error,
  /// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
  FlutterProject fromDirectory(Directory directory) {
    assert(directory != null);
47
    return projects.putIfAbsent(directory.path, () {
48 49
      final FlutterManifest manifest = FlutterProject._readManifest(
        directory.childFile(bundle.defaultManifestPath).path,
50 51
        logger: _logger,
        fileSystem: _fileSystem,
52 53 54 55 56
      );
      final FlutterManifest exampleManifest = FlutterProject._readManifest(
        FlutterProject._exampleDirectory(directory)
            .childFile(bundle.defaultManifestPath)
            .path,
57 58
        logger: _logger,
        fileSystem: _fileSystem,
59 60 61
      );
      return FlutterProject(directory, manifest, exampleManifest);
    });
62 63 64
  }
}

65
/// Represents the contents of a Flutter project at the specified [directory].
66
///
67 68 69 70 71 72 73
/// [FlutterManifest] information is read from `pubspec.yaml` and
/// `example/pubspec.yaml` files on construction of a [FlutterProject] instance.
/// The constructed instance carries an immutable snapshot representation of the
/// presence and content of those files. Accordingly, [FlutterProject] instances
/// should be discarded upon changes to the `pubspec.yaml` files, but can be
/// used across changes to other files, as no other file-level information is
/// cached.
74
class FlutterProject {
75
  @visibleForTesting
76
  FlutterProject(this.directory, this.manifest, this._exampleManifest)
77 78 79
    : assert(directory != null),
      assert(manifest != null),
      assert(_exampleManifest != null);
80

81 82
  /// Returns a [FlutterProject] view of the given directory or a ToolExit error,
  /// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
83
  static FlutterProject fromDirectory(Directory directory) => globals.projectFactory.fromDirectory(directory);
84

85 86
  /// Returns a [FlutterProject] view of the current directory or a ToolExit error,
  /// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
87
  static FlutterProject current() => globals.projectFactory.fromDirectory(globals.fs.currentDirectory);
88

89 90
  /// Create a [FlutterProject] and bypass the project caching.
  @visibleForTesting
91
  static FlutterProject fromDirectoryTest(Directory directory, [Logger? logger]) {
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    final FileSystem fileSystem = directory.fileSystem;
    logger ??= BufferLogger.test();
    final FlutterManifest manifest = FlutterProject._readManifest(
      directory.childFile(bundle.defaultManifestPath).path,
      logger: logger,
      fileSystem: fileSystem,
    );
    final FlutterManifest exampleManifest = FlutterProject._readManifest(
      FlutterProject._exampleDirectory(directory)
        .childFile(bundle.defaultManifestPath)
        .path,
      logger: logger,
      fileSystem: fileSystem,
    );
    return FlutterProject(directory, manifest, exampleManifest);
  }
108 109 110 111

  /// The location of this project.
  final Directory directory;

112
  /// The manifest of this project.
113 114
  final FlutterManifest manifest;

115
  /// The manifest of the example sub-project of this project.
116
  final FlutterManifest _exampleManifest;
117

118
  /// The set of organization names found in this project as
119 120
  /// part of iOS product bundle identifier, Android application ID, or
  /// Gradle group ID.
121
  Future<Set<String>> get organizationNames async {
122 123 124
    final List<String> candidates = <String>[];

    if (ios.existsSync()) {
125 126 127
      // Don't require iOS build info, this method is only
      // used during create as best-effort, use the
      // default target bundle identifier.
128
      final String? bundleIdentifier = await ios.productBundleIdentifier(null);
129 130 131 132 133
      if (bundleIdentifier != null) {
        candidates.add(bundleIdentifier);
      }
    }
    if (android.existsSync()) {
134 135
      final String? applicationId = android.applicationId;
      final String? group = android.group;
136 137 138 139 140 141 142 143
      candidates.addAll(<String>[
        if (applicationId != null)
          applicationId,
        if (group != null)
          group,
      ]);
    }
    if (example.android.existsSync()) {
144
      final String? applicationId = example.android.applicationId;
145 146 147 148 149
      if (applicationId != null) {
        candidates.add(applicationId);
      }
    }
    if (example.ios.existsSync()) {
150
      final String? bundleIdentifier = await example.ios.productBundleIdentifier(null);
151 152 153 154
      if (bundleIdentifier != null) {
        candidates.add(bundleIdentifier);
      }
    }
155
    return Set<String>.of(candidates.map<String?>(_organizationNameFromPackageName).whereType<String>());
156 157
  }

158
  String? _organizationNameFromPackageName(String packageName) {
159
    if (packageName != null && 0 <= packageName.lastIndexOf('.')) {
160
      return packageName.substring(0, packageName.lastIndexOf('.'));
161 162
    }
    return null;
163 164 165
  }

  /// The iOS sub project of this project.
166
  late final IosProject ios = IosProject.fromFlutter(this);
167 168

  /// The Android sub project of this project.
169
  late final AndroidProject android = AndroidProject._(this);
170

171
  /// The web sub project of this project.
172
  late final WebProject web = WebProject._(this);
173

174
  /// The MacOS sub project of this project.
175
  late final MacOSProject macos = MacOSProject.fromFlutter(this);
176

177
  /// The Linux sub project of this project.
178
  late final LinuxProject linux = LinuxProject.fromFlutter(this);
179

180
  /// The Windows sub project of this project.
181
  late final WindowsProject windows = WindowsProject.fromFlutter(this);
182

183
  /// The Windows UWP sub project of this project.
184
  late final WindowsUwpProject windowsUwp = WindowsUwpProject.fromFlutter(this);
185

186
  /// The Fuchsia sub project of this project.
187
  late final FuchsiaProject fuchsia = FuchsiaProject._(this);
188

189 190 191 192 193 194
  /// The `pubspec.yaml` file of this project.
  File get pubspecFile => directory.childFile('pubspec.yaml');

  /// The `.packages` file of this project.
  File get packagesFile => directory.childFile('.packages');

195 196 197 198 199 200
  /// The `package_config.json` file of the project.
  ///
  /// This is the replacement for .packages which contains language
  /// version information.
  File get packageConfigFile => directory.childDirectory('.dart_tool').childFile('package_config.json');

201 202 203
  /// The `.metadata` file of this project.
  File get metadataFile => directory.childFile('.metadata');

204
  /// The `.flutter-plugins` file of this project.
205 206
  File get flutterPluginsFile => directory.childFile('.flutter-plugins');

207 208 209 210
  /// The `.flutter-plugins-dependencies` file of this project,
  /// which contains the dependencies each plugin depends on.
  File get flutterPluginsDependenciesFile => directory.childFile('.flutter-plugins-dependencies');

211 212 213
  /// The `.dart-tool` directory of this project.
  Directory get dartTool => directory.childDirectory('.dart_tool');

214 215
  /// The directory containing the generated code for this project.
  Directory get generated => directory
216
    .absolute
217 218 219 220 221
    .childDirectory('.dart_tool')
    .childDirectory('build')
    .childDirectory('generated')
    .childDirectory(manifest.appName);

222 223 224 225 226
  /// The generated Dart plugin registrant for non-web platforms.
  File get dartPluginRegistrant => dartTool
    .childDirectory('flutter_build')
    .childFile('generated_main.dart');

227
  /// The example sub-project of this project.
228
  FlutterProject get example => FlutterProject(
229 230
    _exampleDirectory(directory),
    _exampleManifest,
231
    FlutterManifest.empty(logger: globals.logger),
232 233
  );

234 235
  /// True if this project is a Flutter module project.
  bool get isModule => manifest.isModule;
236

237 238 239
  /// True if this project is a Flutter plugin project.
  bool get isPlugin => manifest.isPlugin;

240
  /// True if the Flutter project is using the AndroidX support library.
241 242
  bool get usesAndroidX => manifest.usesAndroidX;

243
  /// True if this project has an example application.
244
  bool get hasExampleApp => _exampleDirectory(directory).existsSync();
245 246

  /// The directory that will contain the example if an example exists.
247
  static Directory _exampleDirectory(Directory directory) => directory.childDirectory('example');
248

249 250 251 252 253
  /// Reads and validates the `pubspec.yaml` file at [path], asynchronously
  /// returning a [FlutterManifest] representation of the contents.
  ///
  /// Completes with an empty [FlutterManifest], if the file does not exist.
  /// Completes with a ToolExit on validation error.
254
  static FlutterManifest _readManifest(String path, {
255 256
    required Logger logger,
    required FileSystem fileSystem,
257
  }) {
258
    FlutterManifest? manifest;
259
    try {
260 261 262 263 264
      manifest = FlutterManifest.createFromPath(
        path,
        logger: logger,
        fileSystem: fileSystem,
      );
265
    } on YamlException catch (e) {
266 267
      logger.printStatus('Error detected in pubspec.yaml:', emphasis: true);
      logger.printError('$e');
268 269 270 271 272 273
    } on FormatException catch (e) {
      logger.printError('Error detected while parsing pubspec.yaml:', emphasis: true);
      logger.printError('$e');
    } on FileSystemException catch (e) {
      logger.printError('Error detected while reading pubspec.yaml:', emphasis: true);
      logger.printError('$e');
274 275
    }
    if (manifest == null) {
276
      throwToolExit('Please correct the pubspec.yaml file at $path');
277
    }
278 279 280
    return manifest;
  }

281 282 283 284 285 286 287 288 289 290 291 292 293 294
  /// Reapplies template files and regenerates project files and plugin
  /// registrants for app and module projects only.
  ///
  /// Will not create project platform directories if they do not already exist.
  Future<void> regeneratePlatformSpecificTooling() async {
    return ensureReadyForPlatformSpecificTooling(
      androidPlatform: android.existsSync(),
      iosPlatform: ios.existsSync(),
      // TODO(stuartmorgan): Revisit the conditions here once the plans for handling
      // desktop in existing projects are in place.
      linuxPlatform: featureFlags.isLinuxEnabled && linux.existsSync(),
      macOSPlatform: featureFlags.isMacOSEnabled && macos.existsSync(),
      windowsPlatform: featureFlags.isWindowsEnabled && windows.existsSync(),
      webPlatform: featureFlags.isWebEnabled && web.existsSync(),
295
      winUwpPlatform: featureFlags.isWindowsUwpEnabled && windowsUwp.existsSync(),
296 297 298 299 300 301 302 303 304 305 306 307
    );
  }

  /// Applies template files and generates project files and plugin
  /// registrants for app and module projects only for the specified platforms.
  Future<void> ensureReadyForPlatformSpecificTooling({
    bool androidPlatform = false,
    bool iosPlatform = false,
    bool linuxPlatform = false,
    bool macOSPlatform = false,
    bool windowsPlatform = false,
    bool webPlatform = false,
308
    bool winUwpPlatform = false,
309
  }) async {
310
    if (!directory.existsSync() || hasExampleApp || isPlugin) {
311
      return;
312
    }
313 314
    await refreshPluginsList(this, iosPlatform: iosPlatform, macOSPlatform: macOSPlatform);
    if (androidPlatform) {
315 316
      await android.ensureReadyForPlatformSpecificTooling();
    }
317
    if (iosPlatform) {
318 319
      await ios.ensureReadyForPlatformSpecificTooling();
    }
320
    if (linuxPlatform) {
321 322
      await linux.ensureReadyForPlatformSpecificTooling();
    }
323
    if (macOSPlatform) {
324 325
      await macos.ensureReadyForPlatformSpecificTooling();
    }
326
    if (windowsPlatform) {
327 328
      await windows.ensureReadyForPlatformSpecificTooling();
    }
329
    if (webPlatform) {
330 331
      await web.ensureReadyForPlatformSpecificTooling();
    }
332
    if (winUwpPlatform) {
333 334
      await windowsUwp.ensureReadyForPlatformSpecificTooling();
    }
335 336 337 338 339 340 341 342
    await injectPlugins(
      this,
      androidPlatform: androidPlatform,
      iosPlatform: iosPlatform,
      linuxPlatform: linuxPlatform,
      macOSPlatform: macOSPlatform,
      windowsPlatform: windowsPlatform,
      webPlatform: webPlatform,
343
      winUwpPlatform: winUwpPlatform,
344
    );
345
  }
346 347 348

  /// Returns a json encoded string containing the [appName], [version], and [buildNumber] that is used to generate version.json
  String getVersionInfo()  {
349 350
    final String? buildName = manifest.buildName;
    final String? buildNumber = manifest.buildNumber;
351 352
    final Map<String, String> versionFileJson = <String, String>{
      'app_name': manifest.appName,
353 354 355 356
      if (buildName != null)
        'version': buildName,
      if (buildNumber != null)
        'build_number': buildNumber,
357
      'package_name': manifest.appName,
358 359 360
    };
    return jsonEncode(versionFileJson);
  }
361 362
}

363 364 365 366 367 368 369 370 371 372
/// Base class for projects per platform.
abstract class FlutterProjectPlatform {

  /// Plugin's platform config key, e.g., "macos", "ios".
  String get pluginConfigKey;

  /// Whether the platform exists in the project.
  bool existsSync();
}

373 374 375
/// Represents the Android sub-project of a Flutter project.
///
/// Instances will reflect the contents of the `android/` sub-folder of
376
/// Flutter applications and the `.android/` sub-folder of Flutter module projects.
377
class AndroidProject extends FlutterProjectPlatform {
378 379 380 381 382
  AndroidProject._(this.parent);

  /// The parent of this project.
  final FlutterProject parent;

383 384 385
  @override
  String get pluginConfigKey => AndroidPlugin.kConfigKey;

386
  static final RegExp _applicationIdPattern = RegExp('^\\s*applicationId\\s+[\'"](.*)[\'"]\\s*\$');
387
  static final RegExp _kotlinPluginPattern = RegExp('^\\s*apply plugin\\:\\s+[\'"]kotlin-android[\'"]\\s*\$');
388
  static final RegExp _groupPattern = RegExp('^\\s*group\\s+[\'"](.*)[\'"]\\s*\$');
389

390 391 392 393
  /// The Gradle root directory of the Android host app. This is the directory
  /// containing the `app/` subdirectory and the `settings.gradle` file that
  /// includes it in the overall Gradle project.
  Directory get hostAppGradleRoot {
394
    if (!isModule || _editableHostAppDirectory.existsSync()) {
395
      return _editableHostAppDirectory;
396
    }
397
    return ephemeralDirectory;
398 399 400 401
  }

  /// The Gradle root directory of the Android wrapping of Flutter and plugins.
  /// This is the same as [hostAppGradleRoot] except when the project is
402
  /// a Flutter module with an editable host app.
403
  Directory get _flutterLibGradleRoot => isModule ? ephemeralDirectory : _editableHostAppDirectory;
404

405
  Directory get ephemeralDirectory => parent.directory.childDirectory('.android');
406
  Directory get _editableHostAppDirectory => parent.directory.childDirectory('android');
407

408 409
  /// True if the parent Flutter project is a module.
  bool get isModule => parent.isModule;
410

411
  /// True if the Flutter project is using the AndroidX support library.
412 413
  bool get usesAndroidX => parent.usesAndroidX;

414
  /// Returns true if the current version of the Gradle plugin is supported.
415
  late final bool isSupportedVersion = _computeSupportedVersion();
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437

  bool _computeSupportedVersion() {
    final FileSystem fileSystem = hostAppGradleRoot.fileSystem;
    final File plugin = hostAppGradleRoot.childFile(
        fileSystem.path.join('buildSrc', 'src', 'main', 'groovy', 'FlutterPlugin.groovy'));
    if (plugin.existsSync()) {
      return false;
    }
    final File appGradle = hostAppGradleRoot.childFile(
        fileSystem.path.join('app', 'build.gradle'));
    if (!appGradle.existsSync()) {
      return false;
    }
    for (final String line in appGradle.readAsLinesSync()) {
      if (line.contains(RegExp(r'apply from: .*/flutter.gradle')) ||
          line.contains("def flutterPluginVersion = 'managed'")) {
        return true;
      }
    }
    return false;
  }

438 439 440
  /// True, if the app project is using Kotlin.
  bool get isKotlin {
    final File gradleFile = hostAppGradleRoot.childDirectory('app').childFile('build.gradle');
441
    return firstMatchInFile(gradleFile, _kotlinPluginPattern) != null;
442 443
  }

444
  File get appManifestFile {
445
    return isUsingGradle
446
        ? globals.fs.file(globals.fs.path.join(hostAppGradleRoot.path, 'app', 'src', 'main', 'AndroidManifest.xml'))
447
        : hostAppGradleRoot.childFile('AndroidManifest.xml');
448 449
  }

450
  File get gradleAppOutV1File => gradleAppOutV1Directory.childFile('app-debug.apk');
451 452

  Directory get gradleAppOutV1Directory {
453
    return globals.fs.directory(globals.fs.path.join(hostAppGradleRoot.path, 'app', 'build', 'outputs', 'apk'));
454 455
  }

456
  /// Whether the current flutter project has an Android sub-project.
457
  @override
458 459 460 461
  bool existsSync() {
    return parent.isModule || _editableHostAppDirectory.existsSync();
  }

462
  bool get isUsingGradle {
463
    return hostAppGradleRoot.childFile('build.gradle').existsSync();
464
  }
465

466
  String? get applicationId {
467
    final File gradleFile = hostAppGradleRoot.childDirectory('app').childFile('build.gradle');
468
    return firstMatchInFile(gradleFile, _applicationIdPattern)?.group(1);
469 470
  }

471
  String? get group {
472
    final File gradleFile = hostAppGradleRoot.childFile('build.gradle');
473
    return firstMatchInFile(gradleFile, _groupPattern)?.group(1);
474
  }
475

476 477 478 479 480
  /// The build directory where the Android artifacts are placed.
  Directory get buildDirectory {
    return parent.directory.childDirectory('build');
  }

481
  Future<void> ensureReadyForPlatformSpecificTooling() async {
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
    if (getEmbeddingVersion() == AndroidEmbeddingVersion.v1) {
      globals.printStatus(
"""
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It's being deprecated in favor of Android embedding v2. Follow the
steps at

https://flutter.dev/go/android-project-migration

to migrate your project.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
"""
      );
    }
499
    if (isModule && _shouldRegenerateFromTemplate()) {
500
      await _regenerateLibrary();
501 502
      // Add ephemeral host app, if an editable host app does not already exist.
      if (!_editableHostAppDirectory.existsSync()) {
503 504
        await _overwriteFromTemplate(globals.fs.path.join('module', 'android', 'host_app_common'), ephemeralDirectory);
        await _overwriteFromTemplate(globals.fs.path.join('module', 'android', 'host_app_ephemeral'), ephemeralDirectory);
505
      }
506
    }
507
    if (!hostAppGradleRoot.existsSync()) {
508
      return;
509 510
    }
    gradle.updateLocalProperties(project: parent, requireAndroidSdk: false);
511 512
  }

513
  bool _shouldRegenerateFromTemplate() {
514
    return globals.fsUtils.isOlderThanReference(
515 516 517
      entity: ephemeralDirectory,
      referenceFile: parent.pubspecFile,
    ) || globals.cache.isOlderThanToolsStamp(ephemeralDirectory);
518
  }
519

520 521
  File get localPropertiesFile => _flutterLibGradleRoot.childFile('local.properties');

522
  Directory get pluginRegistrantHost => _flutterLibGradleRoot.childDirectory(isModule ? 'Flutter' : 'app');
523

524
  Future<void> _regenerateLibrary() async {
525
    ErrorHandlingFileSystem.deleteIfExists(ephemeralDirectory, recursive: true);
526
    await _overwriteFromTemplate(globals.fs.path.join(
527 528
      'module',
      'android',
529
      'library_new_embedding',
530
    ), ephemeralDirectory);
531
    await _overwriteFromTemplate(globals.fs.path.join('module', 'android', 'gradle'), ephemeralDirectory);
532
    globals.gradleUtils?.injectGradleWrapperIfNeeded(ephemeralDirectory);
533
  }
534

535
  Future<void> _overwriteFromTemplate(String path, Directory target) async {
536 537 538 539 540 541 542
    final Template template = await Template.fromName(
      path,
      fileSystem: globals.fs,
      templateManifest: null,
      logger: globals.logger,
      templateRenderer: globals.templateRenderer,
    );
543
    final String androidIdentifier = parent.manifest.androidPackage ?? 'com.example.${parent.manifest.appName}';
544 545
    template.render(
      target,
546
      <String, Object>{
547
        'android': true,
548
        'projectName': parent.manifest.appName,
549
        'androidIdentifier': androidIdentifier,
550
        'androidX': usesAndroidX,
551 552 553 554
      },
      printStatusWhenWriting: false,
    );
  }
555 556

  AndroidEmbeddingVersion getEmbeddingVersion() {
557 558 559 560 561
    if (isModule) {
      // A module type's Android project is used in add-to-app scenarios and
      // only supports the V2 embedding.
      return AndroidEmbeddingVersion.v2;
    }
562 563 564
    if (appManifestFile == null || !appManifestFile.existsSync()) {
      return AndroidEmbeddingVersion.v1;
    }
Dan Field's avatar
Dan Field committed
565
    XmlDocument document;
566
    try {
Dan Field's avatar
Dan Field committed
567 568
      document = XmlDocument.parse(appManifestFile.readAsStringSync());
    } on XmlParserException {
569 570 571 572 573 574
      throwToolExit('Error parsing $appManifestFile '
                    'Please ensure that the android manifest is a valid XML document and try again.');
    } on FileSystemException {
      throwToolExit('Error reading $appManifestFile even though it exists. '
                    'Please ensure that you have read permission to this file and try again.');
    }
Dan Field's avatar
Dan Field committed
575
    for (final XmlElement metaData in document.findAllElements('meta-data')) {
576
      final String? name = metaData.getAttribute('android:name');
577
      if (name == 'flutterEmbedding') {
578
        final String? embeddingVersionString = metaData.getAttribute('android:value');
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
        if (embeddingVersionString == '1') {
          return AndroidEmbeddingVersion.v1;
        }
        if (embeddingVersionString == '2') {
          return AndroidEmbeddingVersion.v2;
        }
      }
    }
    return AndroidEmbeddingVersion.v1;
  }
}

/// Iteration of the embedding Java API in the engine used by the Android project.
enum AndroidEmbeddingVersion {
  /// V1 APIs based on io.flutter.app.FlutterActivity.
  v1,
  /// V2 APIs based on io.flutter.embedding.android.FlutterActivity.
  v2,
597 598
}

599
/// Represents the web sub-project of a Flutter project.
600
class WebProject extends FlutterProjectPlatform {
601 602 603 604
  WebProject._(this.parent);

  final FlutterProject parent;

605 606 607
  @override
  String get pluginConfigKey => WebPlugin.kConfigKey;

608
  /// Whether this flutter project has a web sub-project.
609
  @override
610
  bool existsSync() {
611 612
    return parent.directory.childDirectory('web').existsSync()
      && indexFile.existsSync();
613
  }
614

615 616 617
  /// The 'lib' directory for the application.
  Directory get libDirectory => parent.directory.childDirectory('lib');

618 619 620
  /// The directory containing additional files for the application.
  Directory get directory => parent.directory.childDirectory('web');

621
  /// The html file used to host the flutter web application.
622 623 624
  File get indexFile => parent.directory
      .childDirectory('web')
      .childFile('index.html');
625

626
  Future<void> ensureReadyForPlatformSpecificTooling() async {}
627 628
}

629
/// The Fuchsia sub project.
630 631 632 633 634
class FuchsiaProject {
  FuchsiaProject._(this.project);

  final FlutterProject project;

635
  Directory? _editableHostAppDirectory;
636 637 638 639 640
  Directory get editableHostAppDirectory =>
      _editableHostAppDirectory ??= project.directory.childDirectory('fuchsia');

  bool existsSync() => editableHostAppDirectory.existsSync();

641
  Directory? _meta;
642 643 644
  Directory get meta =>
      _meta ??= editableHostAppDirectory.childDirectory('meta');
}