From f340d207f6750f110f346d4d8c395e9614af088d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=B4=B5=E9=94=8B?= Date: Sun, 21 Jan 2024 14:18:26 +0800 Subject: [PATCH] Adjust the position of require File.expand_path (#141521) On `Podfile`: ```ruby flutter_application_path = '../flutter_module' load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb') target 'OCProject' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! # Pods for OCProject # install_all_flutter_pods(flutter_application_path) # install_flutter_engine_pod(flutter_application_path) # install_flutter_application_pod(flutter_application_path) install_flutter_plugin_pods(flutter_application_path) end post_install do |installer| flutter_post_install(installer) end ``` Encountering the following error after executing `pod install`: ```shell pod install [!] Invalid `Podfile` file: undefined method `flutter_relative_path_from_podfile' for #, @internal_hash={}, @root_target_definitions=[#], @current_target_definition=#> relative = flutter_relative_path_from_podfile(export_script_directory) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^. # from /Users/lxf/gitHub/flutter_hybrid_bug/OCProject/Podfile:17 # ------------------------------------------- # # install_flutter_plugin_pods(flutter_application_path) > install_flutter_application_pod(flutter_application_path) # # ------------------------------------------- ``` The `flutter_relative_path_from_podfile` method is in `flutter_tools/bin/podhelper.rb`, but now `flutter_tools/bin/podhelper.rb` is only required in `install_all_flutter_pods` in `podhelper.rb.tmpl`. Sometimes we only need to use the `install_flutter_plugin_pods` method in podhelper.rb. For example, using `Shorebird` in an iOS hybird app scenario, we need to build `Flutter.xcframework` and `App.xcframework` and embed them into the iOS native project. In order to avoid unnecessary conflicts, use `install_flutter_plugin_pods` method to install Flutter plugin pods. [Shorebird - Code Push In Hybrid Apps](https://docs.shorebird.dev/guides/hybrid-app/ios) So I adjust the position of `require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)`. --- dev/devicelab/bin/tasks/module_test_ios.dart | 34 +++++++++++++++++-- .../library/Flutter.tmpl/podhelper.rb.tmpl | 4 +-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/dev/devicelab/bin/tasks/module_test_ios.dart b/dev/devicelab/bin/tasks/module_test_ios.dart index b0875d7ac5..f65b5c3af1 100644 --- a/dev/devicelab/bin/tasks/module_test_ios.dart +++ b/dev/devicelab/bin/tasks/module_test_ios.dart @@ -310,8 +310,38 @@ end }, ); - final File hostPodfileLockFile = File(path.join(objectiveCHostApp.path, 'Podfile.lock')); - final String hostPodfileLockOutput = hostPodfileLockFile.readAsStringSync(); + File hostPodfileLockFile = File(path.join(objectiveCHostApp.path, 'Podfile.lock')); + String hostPodfileLockOutput = hostPodfileLockFile.readAsStringSync(); + if (!hostPodfileLockOutput.contains(':path: "../hello/.ios/Flutter"') + || !hostPodfileLockOutput.contains(':path: "../hello/.ios/Flutter/FlutterPluginRegistrant"') + || !hostPodfileLockOutput.contains(':path: "../hello/.ios/.symlinks/plugins/url_launcher_ios/ios"') + || hostPodfileLockOutput.contains('android_alarm_manager') + || hostPodfileLockOutput.contains(dartPluginName)) { + print(hostPodfileLockOutput); + throw TaskResult.failure('Building host app Podfile.lock does not contain expected pods'); + } + + section('Validate install_flutter_[engine_pod|plugin_pods|application_pod] methods in the Podfile can be executed normally'); + + podfileContent = podfileContent.replaceFirst(''' + install_all_flutter_pods flutter_application_path +''', ''' + install_flutter_engine_pod(flutter_application_path) + install_flutter_plugin_pods(flutter_application_path) + install_flutter_application_pod(flutter_application_path) +'''); + await podfile.writeAsString(podfileContent, flush: true); + + await exec( + 'pod', + ['install'], + environment: { + 'LANG': 'en_US.UTF-8', + }, + ); + + hostPodfileLockFile = File(path.join(objectiveCHostApp.path, 'Podfile.lock')); + hostPodfileLockOutput = hostPodfileLockFile.readAsStringSync(); if (!hostPodfileLockOutput.contains(':path: "../hello/.ios/Flutter"') || !hostPodfileLockOutput.contains(':path: "../hello/.ios/Flutter/FlutterPluginRegistrant"') || !hostPodfileLockOutput.contains(':path: "../hello/.ios/.symlinks/plugins/url_launcher_ios/ios"') diff --git a/packages/flutter_tools/templates/module/ios/library/Flutter.tmpl/podhelper.rb.tmpl b/packages/flutter_tools/templates/module/ios/library/Flutter.tmpl/podhelper.rb.tmpl index b3694eac6e..56742400ac 100644 --- a/packages/flutter_tools/templates/module/ios/library/Flutter.tmpl/podhelper.rb.tmpl +++ b/packages/flutter_tools/templates/module/ios/library/Flutter.tmpl/podhelper.rb.tmpl @@ -28,8 +28,6 @@ POSTINSTALL raise 'Missing `flutter_post_install(installer)` in Podfile `post_install` block' end - require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) - flutter_application_path ||= File.join('..', '..') install_flutter_engine_pod(flutter_application_path) install_flutter_plugin_pods(flutter_application_path) @@ -112,6 +110,8 @@ def flutter_root raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" end +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + # Run the post-install script to set build settings on Flutter plugins. # # @example