project.dart 23.7 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
  IosProject? _ios;
167
  IosProject get ios => _ios ??= IosProject.fromFlutter(this);
168 169

  /// The Android sub project of this project.
170
  AndroidProject? _android;
171
  AndroidProject get android => _android ??= AndroidProject._(this);
172

173
  /// The web sub project of this project.
174
  WebProject? _web;
175
  WebProject get web => _web ??= WebProject._(this);
176

177
  /// The MacOS sub project of this project.
178
  MacOSProject? _macos;
179
  MacOSProject get macos => _macos ??= MacOSProject.fromFlutter(this);
180

181
  /// The Linux sub project of this project.
182
  LinuxProject? _linux;
183
  LinuxProject get linux => _linux ??= LinuxProject.fromFlutter(this);
184

185
  /// The Windows sub project of this project.
186
  WindowsProject? _windows;
187
  WindowsProject get windows => _windows ??= WindowsProject.fromFlutter(this);
188

189
  /// The Windows UWP sub project of this project.
190
  WindowsUwpProject? _windowUwp;
191
  WindowsUwpProject get windowsUwp => _windowUwp ??= WindowsUwpProject.fromFlutter(this);
192

193
  /// The Fuchsia sub project of this project.
194
  FuchsiaProject? _fuchsia;
195
  FuchsiaProject get fuchsia => _fuchsia ??= FuchsiaProject._(this);
196

197 198 199 200 201 202
  /// 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');

203 204 205 206 207 208
  /// 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');

209 210 211
  /// The `.metadata` file of this project.
  File get metadataFile => directory.childFile('.metadata');

212
  /// The `.flutter-plugins` file of this project.
213 214
  File get flutterPluginsFile => directory.childFile('.flutter-plugins');

215 216 217 218
  /// The `.flutter-plugins-dependencies` file of this project,
  /// which contains the dependencies each plugin depends on.
  File get flutterPluginsDependenciesFile => directory.childFile('.flutter-plugins-dependencies');

219 220 221
  /// The `.dart-tool` directory of this project.
  Directory get dartTool => directory.childDirectory('.dart_tool');

222 223
  /// The directory containing the generated code for this project.
  Directory get generated => directory
224
    .absolute
225 226 227 228 229
    .childDirectory('.dart_tool')
    .childDirectory('build')
    .childDirectory('generated')
    .childDirectory(manifest.appName);

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

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

240 241 242
  /// True if this project is a Flutter plugin project.
  bool get isPlugin => manifest.isPlugin;

243
  /// True if the Flutter project is using the AndroidX support library.
244 245
  bool get usesAndroidX => manifest.usesAndroidX;

246
  /// True if this project has an example application.
247
  bool get hasExampleApp => _exampleDirectory(directory).existsSync();
248 249

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

252 253 254 255 256
  /// 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.
257
  static FlutterManifest _readManifest(String path, {
258 259
    required Logger logger,
    required FileSystem fileSystem,
260
  }) {
261
    FlutterManifest? manifest;
262
    try {
263 264 265 266 267
      manifest = FlutterManifest.createFromPath(
        path,
        logger: logger,
        fileSystem: fileSystem,
      );
268
    } on YamlException catch (e) {
269 270
      logger.printStatus('Error detected in pubspec.yaml:', emphasis: true);
      logger.printError('$e');
271 272 273 274 275 276
    } 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');
277 278
    }
    if (manifest == null) {
279
      throwToolExit('Please correct the pubspec.yaml file at $path');
280
    }
281 282 283
    return manifest;
  }

284 285 286 287 288 289 290 291 292 293 294 295 296 297
  /// 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(),
298
      winUwpPlatform: featureFlags.isWindowsUwpEnabled && windowsUwp.existsSync(),
299 300 301 302 303 304 305 306 307 308 309 310
    );
  }

  /// 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,
311
    bool winUwpPlatform = false,
312
  }) async {
313
    if (!directory.existsSync() || hasExampleApp || isPlugin) {
314
      return;
315
    }
316 317
    await refreshPluginsList(this, iosPlatform: iosPlatform, macOSPlatform: macOSPlatform);
    if (androidPlatform) {
318 319
      await android.ensureReadyForPlatformSpecificTooling();
    }
320
    if (iosPlatform) {
321 322
      await ios.ensureReadyForPlatformSpecificTooling();
    }
323
    if (linuxPlatform) {
324 325
      await linux.ensureReadyForPlatformSpecificTooling();
    }
326
    if (macOSPlatform) {
327 328
      await macos.ensureReadyForPlatformSpecificTooling();
    }
329
    if (windowsPlatform) {
330 331
      await windows.ensureReadyForPlatformSpecificTooling();
    }
332
    if (webPlatform) {
333 334
      await web.ensureReadyForPlatformSpecificTooling();
    }
335
    if (winUwpPlatform) {
336 337
      await windowsUwp.ensureReadyForPlatformSpecificTooling();
    }
338 339 340 341 342 343 344 345
    await injectPlugins(
      this,
      androidPlatform: androidPlatform,
      iosPlatform: iosPlatform,
      linuxPlatform: linuxPlatform,
      macOSPlatform: macOSPlatform,
      windowsPlatform: windowsPlatform,
      webPlatform: webPlatform,
346
      winUwpPlatform: winUwpPlatform,
347
    );
348
  }
349 350 351

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

365 366 367 368 369 370 371 372 373 374
/// 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();
}

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

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

385 386 387
  @override
  String get pluginConfigKey => AndroidPlugin.kConfigKey;

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

392 393 394 395
  /// 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 {
396
    if (!isModule || _editableHostAppDirectory.existsSync()) {
397
      return _editableHostAppDirectory;
398
    }
399
    return ephemeralDirectory;
400 401 402 403
  }

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

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

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

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

416 417
  /// Returns true if the current version of the Gradle plugin is supported.
  bool get isSupportedVersion => _isSupportedVersion ??= _computeSupportedVersion();
418
  bool? _isSupportedVersion;
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440

  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;
  }

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

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

453
  File get gradleAppOutV1File => gradleAppOutV1Directory.childFile('app-debug.apk');
454 455

  Directory get gradleAppOutV1Directory {
456
    return globals.fs.directory(globals.fs.path.join(hostAppGradleRoot.path, 'app', 'build', 'outputs', 'apk'));
457 458
  }

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

465
  bool get isUsingGradle {
466
    return hostAppGradleRoot.childFile('build.gradle').existsSync();
467
  }
468

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

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

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

484
  Future<void> ensureReadyForPlatformSpecificTooling() async {
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
    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.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
"""
      );
    }
502
    if (isModule && _shouldRegenerateFromTemplate()) {
503
      await _regenerateLibrary();
504 505
      // Add ephemeral host app, if an editable host app does not already exist.
      if (!_editableHostAppDirectory.existsSync()) {
506 507
        await _overwriteFromTemplate(globals.fs.path.join('module', 'android', 'host_app_common'), ephemeralDirectory);
        await _overwriteFromTemplate(globals.fs.path.join('module', 'android', 'host_app_ephemeral'), ephemeralDirectory);
508
      }
509
    }
510
    if (!hostAppGradleRoot.existsSync()) {
511
      return;
512 513
    }
    gradle.updateLocalProperties(project: parent, requireAndroidSdk: false);
514 515
  }

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

523 524
  File get localPropertiesFile => _flutterLibGradleRoot.childFile('local.properties');

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

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

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

  AndroidEmbeddingVersion getEmbeddingVersion() {
561 562 563 564 565
    if (isModule) {
      // A module type's Android project is used in add-to-app scenarios and
      // only supports the V2 embedding.
      return AndroidEmbeddingVersion.v2;
    }
566 567 568
    if (appManifestFile == null || !appManifestFile.existsSync()) {
      return AndroidEmbeddingVersion.v1;
    }
Dan Field's avatar
Dan Field committed
569
    XmlDocument document;
570
    try {
Dan Field's avatar
Dan Field committed
571 572
      document = XmlDocument.parse(appManifestFile.readAsStringSync());
    } on XmlParserException {
573 574 575 576 577 578
      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
579
    for (final XmlElement metaData in document.findAllElements('meta-data')) {
580
      final String? name = metaData.getAttribute('android:name');
581
      if (name == 'flutterEmbedding') {
582
        final String? embeddingVersionString = metaData.getAttribute('android:value');
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
        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,
601 602
}

603
/// Represents the web sub-project of a Flutter project.
604
class WebProject extends FlutterProjectPlatform {
605 606 607 608
  WebProject._(this.parent);

  final FlutterProject parent;

609 610 611
  @override
  String get pluginConfigKey => WebPlugin.kConfigKey;

612
  /// Whether this flutter project has a web sub-project.
613
  @override
614
  bool existsSync() {
615 616
    return parent.directory.childDirectory('web').existsSync()
      && indexFile.existsSync();
617
  }
618

619 620 621
  /// The 'lib' directory for the application.
  Directory get libDirectory => parent.directory.childDirectory('lib');

622 623 624
  /// The directory containing additional files for the application.
  Directory get directory => parent.directory.childDirectory('web');

625
  /// The html file used to host the flutter web application.
626 627 628
  File get indexFile => parent.directory
      .childDirectory('web')
      .childFile('index.html');
629

630
  Future<void> ensureReadyForPlatformSpecificTooling() async {}
631 632
}

633
/// The Fuchsia sub project.
634 635 636 637 638
class FuchsiaProject {
  FuchsiaProject._(this.project);

  final FlutterProject project;

639
  Directory? _editableHostAppDirectory;
640 641 642 643 644
  Directory get editableHostAppDirectory =>
      _editableHostAppDirectory ??= project.directory.childDirectory('fuchsia');

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

645
  Directory? _meta;
646 647 648
  Directory get meta =>
      _meta ??= editableHostAppDirectory.childDirectory('meta');
}