[flutter_tool] Always re-copy Framework/podspec when regenerating iOS module project (#45877)

diff --git a/dev/bots/test.dart b/dev/bots/test.dart
index bd7de38..d0e8014 100644
--- a/dev/bots/test.dart
+++ b/dev/bots/test.dart
@@ -775,8 +775,7 @@
     () => _runDevicelabTest('module_test', environment: gradleEnvironment, testEmbeddingV2: true),
     () => _runDevicelabTest('plugin_dependencies_test', environment: gradleEnvironment),
 
-    // TODO(jmagman): Re-enable once flakiness is resolved, https://github.com/flutter/flutter/issues/37525
-    // if (Platform.isMacOS) () => _runDevicelabTest('module_test_ios'),
+    if (Platform.isMacOS) () => _runDevicelabTest('module_test_ios'),
     if (Platform.isMacOS) () => _runDevicelabTest('build_ios_framework_module_test'),
     if (Platform.isMacOS) () => _runDevicelabTest('plugin_lint_mac'),
     () => _runDevicelabTest('plugin_test', environment: gradleEnvironment),
diff --git a/packages/flutter_tools/lib/src/project.dart b/packages/flutter_tools/lib/src/project.dart
index 8e8a561..833bc6e 100644
--- a/packages/flutter_tools/lib/src/project.dart
+++ b/packages/flutter_tools/lib/src/project.dart
@@ -9,6 +9,7 @@
 import 'package:yaml/yaml.dart';
 
 import 'android/gradle_utils.dart' as gradle;
+import 'artifacts.dart';
 import 'base/common.dart';
 import 'base/context.dart';
 import 'base/file_system.dart';
@@ -456,6 +457,11 @@
     if (!pubspecChanged && !toolingChanged) {
       return;
     }
+
+    final Directory engineDest = ephemeralDirectory
+      .childDirectory('Flutter')
+      .childDirectory('engine');
+
     _deleteIfExistsSync(ephemeralDirectory);
     _overwriteFromTemplate(fs.path.join('module', 'ios', 'library'), ephemeralDirectory);
     // Add ephemeral host app, if a editable host app does not already exist.
@@ -464,6 +470,17 @@
       if (hasPlugins(parent)) {
         _overwriteFromTemplate(fs.path.join('module', 'ios', 'host_app_ephemeral_cocoapods'), ephemeralDirectory);
       }
+      // Copy podspec and framework from engine cache. The actual build mode
+      // doesn't actually matter as it will be overwritten by xcode_backend.sh.
+      // However, cocoapods will run before that script and requires something
+      // to be in this location.
+      final Directory framework = fs.directory(artifacts.getArtifactPath(Artifact.flutterFramework,
+        platform: TargetPlatform.ios, mode: BuildMode.debug));
+      if (framework.existsSync()) {
+        final File podspec = framework.parent.childFile('Flutter.podspec');
+        copyDirectorySync(framework, engineDest.childDirectory('Flutter.framework'));
+        podspec.copySync(engineDest.childFile('Flutter.podspec').path);
+      }
     }
   }