When pod search for Flutter is performed on the terminal, you will find that there are multiple versions of Flutter in CocoaPods, but only 1.0.0 is selected by default
So I wonder if we can decide which version of the Flutter Pod library to use?
After some attempts, I managed to specify a version of the Flutter Pod library. However, this solution was not used in a formal project. It was just a personal attempt
Analysis Podfile
The version of the POD library is configured in the Podfile, so analyze the Podfile first
Omit most of the Podfile code and just look at target's
target 'Runner' do
use_frameworks!
use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
Copy the code
Based on integrating the Flutter Module into the iOS project about using CocoaPods and the Flutter SDK integration
Flutter_install_all_ios_pods file.dirname (file.realPath (__FILE__))
I then use ruby’s print statement (since CocoaPods is implemented by Ruby) to find the path file. dirname returns is ios in the project directory
Then, according to the code above target in your Podfile, the method flutter_root
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('.. '.'Flutter'.'Generated.xcconfig'), __FILE__)
unlessFile.exist? (generated_xcode_build_settings_path) raise"#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
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)
Copy the code
Analyze a file named flutter/packages/flutter_tools/bin/ PodHelper. Open this file and you can see a lot of code. Find the following code by searching for Flutter
# Generate a fake podspec to represent the Flutter framework.
# This is only necessary because plugin podspecs contain `s.dependency 'Flutter'`, and if this Podfile
# does not add a `pod 'Flutter'` CocoaPods will try to download it from the CocoaPods trunk.
File.open(copied_podspec_path, 'w') { |podspec|
podspec.write <<~EOF # # NOTE: This podspec is NOT to be published. It is only used as a local source! # This is a generated file; Do not edit or check into the version control. # Pod: : Spec. New do | s | s.n ame = 'Flutter' s.v ersion = "1.0.0" s.s ummary = 'High-performance, high-fidelity mobile apps.' s.homepage = 'https://flutter.io' s.license = { :type => 'MIT' } s.author = { 'Flutter Dev Team' => '[email protected]' } s.source = { :git => 'https://github.com/flutter/engine', To_s} s.iso. Deployment_target = '9.0' # Framework linking is handled by Flutter tooling, not CocoaPods. # Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs. s.vendored_frameworks = 'path/to/nothing' end EOF
}
# Keep pod path relative so it can be checked into Podfile.lock.
pod 'Flutter'.:path= >'Flutter'
Copy the code
Try changing S.sion = ‘1.0.0’ to s.sion = ‘2.0.2’ and then execute pod Install
A success
Only the iOS part is modified here, in fact, there is also macOS part in the file, also directly modify S. sion can be
The specifiedpodhelper
The path of the
The key podhelper.rb file has been modified in the Flutter SDK to apply to all future projects. Does this only apply to current projects? From the previous analysis, you can actually specify the path of the PodHelper by modifying the path in the Podfile
First, I copied flutter/packages/flutter_tools/bin/podhelper.rb into the ios directory of my current project, which is the same as the Podfile
Then modify the contents of the Podfile as follows
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug'= >:debug.'Profile'= >:release.'Release'= >:release,}# Remove the code for the flutter_root method, which is only used to return the Flutter SDK path
This is the path to load the PodHelper
require File.expand_path(File.join('podhelper'))
flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
Copy the code
If you want to update your iPod file, you need to update your ios podhelper.rb folder. If you want to update your ios folder, you need to update your ios folder
Search for artifacts_dir = in podhelper.rb
artifacts_dir = File.join('.. '.'.. '.'.. '.'.. '.'bin'.'cache'.'artifacts'.'engine')
# Change the above code to the following
artifacts_dir = File.expand_path(File.join('bin'.'cache'.'artifacts'.'engine'),flutter_root)
Add flutter_root to podHelper. rb before flutter_additional_iOS_build_settings
Copy the code
If you search artifacts_dir =, there are actually two results, one for iOS and one for macOS, you can change it as needed or you can change both
Put up my modified Podfile and PodHelper.rb for your reference, portal
Version of the environment
Flutter has been iterated to 2.5.3 and my attempt may not be suitable for all versions
Here is my environment
MacOS Big Sur (11.6.1) Xcode Version 12.5.1 (12E507) Flutter 2.5.3 • Channel stable • https://github.com/flutter/flutter.git Framework revision 18116933 e7 (2 weekes line), the 2021-10-15 10:46:35-0700 Engine • Dart 2.14.4 pod -- Version 1.11.2 Ruby --version ruby 2.6.3 P62 [universal x86_64 - darwin20] gem - version 3.0.3Copy the code