diff --git a/packages/flutter_tools/lib/src/commands/create_base.dart b/packages/flutter_tools/lib/src/commands/create_base.dart index 5bbe4aaf3c..eb6b6e3e0a 100644 --- a/packages/flutter_tools/lib/src/commands/create_base.dart +++ b/packages/flutter_tools/lib/src/commands/create_base.dart @@ -13,8 +13,11 @@ import '../android/gradle_utils.dart' as gradle; import '../base/common.dart'; import '../base/file_system.dart'; import '../base/utils.dart'; +import '../build_info.dart'; +import '../build_system/build_system.dart'; import '../cache.dart'; import '../convert.dart'; +import '../dart/generate_synthetic_packages.dart'; import '../dart/pub.dart'; import '../features.dart'; import '../flutter_project_metadata.dart'; @@ -480,6 +483,27 @@ abstract class CreateBase extends FlutterCommand { } if (boolArg('pub')) { + final Environment environment = Environment( + artifacts: globals.artifacts, + logger: globals.logger, + cacheDir: globals.cache.getRoot(), + engineVersion: globals.flutterVersion.engineRevision, + fileSystem: globals.fs, + flutterRootDir: globals.fs.directory(Cache.flutterRoot), + outputDir: globals.fs.directory(getBuildDirectory()), + processManager: globals.processManager, + platform: globals.platform, + projectDir: project.directory, + generateDartPluginRegistry: true, + ); + + // Generate the l10n synthetic package that will be injected into the + // package_config in the call to pub.get() below. + await generateLocalizationsSyntheticPackage( + environment: environment, + buildSystem: globals.buildSystem, + ); + await pub.get( context: PubContext.create, directory: directory.path, diff --git a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart index 9857062bd0..62534705c8 100644 --- a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart +++ b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart @@ -1291,7 +1291,9 @@ class LocalizationsGenerator { // A pubspec.yaml file is required when using a synthetic package. If it does not // exist, create a blank one. if (useSyntheticPackage) { - final Directory syntheticPackageDirectory = _fs.directory(_defaultSyntheticPackagePath(_fs)); + final Directory syntheticPackageDirectory = projectDirectory != null + ? projectDirectory!.childDirectory(_defaultSyntheticPackagePath(_fs)) + : _fs.directory(_defaultSyntheticPackagePath(_fs)); syntheticPackageDirectory.createSync(recursive: true); final File flutterGenPubspec = syntheticPackageDirectory.childFile('pubspec.yaml'); if (!flutterGenPubspec.existsSync()) { diff --git a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart index fb3679a829..d59c1b3ea3 100755 --- a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart @@ -147,6 +147,8 @@ void main() { projectDir, ['-t', 'skeleton', '-i', 'objc', '-a', 'java', '--implementation-tests'], [ + '.dart_tool/flutter_gen/pubspec.yaml', + '.dart_tool/flutter_gen/gen_l10n/app_localizations.dart', 'analysis_options.yaml', 'android/app/src/main/java/com/example/flutter_project/MainActivity.java', 'android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',