我使用cocoapods 1.1.1,在我的podfile中我有多个post_install钩子。我得到了这个错误:
[!] Invalid `Podfile` file: [!] Specifying multiple `post_install` hooks is unsupported..
-------------------------------------------
#
> post_install do |installer|
# installer.pods_project.targets.each do |target|
以前有人遇到过同样的问题吗?是的!我有一个post_install在我的1个目标和另一个在全局范围内。我可以搬进去,但为什么呢?
解决方案2022
当我从我的主要目标中删除我的代码并移动到全局作用域的post_install块时,它的工作就像魅力一样。
由于某些原因,如果您添加了多个post_install(例如全局和一个目标),将它们移动到同一个全局块中,并添加if-else语句来管理目标。
暂时解决了这个冲突。把代码放到Podfile中。
def multiple_post_install(flutter_application_path)
#read podhelper from flutter_application_path
flutter_podhelper = File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb'))
#find the post_install end location by hardcoding
post_install_string = 'post_install do |installer|'
location = flutter_podhelper.index(post_install_string)
location += post_install_string.length
#declare your own hook func
update_configs_func = %q[
update_configs(installer)]
#insert the func you declare
flutter_podhelper.insert(location, update_configs_func)
return flutter_podhelper
end
flutter_application_path = 'path/to/my_flutter/'
flutter_podhelper = multiple_post_install(flutter_application_path)
eval(flutter_podhelper, binding)
def update_configs(installer)
#put your own custom code
end
def main_pods
pod 'CocoaLumberjack', '2.0.0'
pod 'MBProgressHUD', '0.9.1'
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
if target.name == 'Pods-AFNetworking'
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << '_AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_=1'
end
end
end
end
结束我有类似的问题,这是因为我在POD文件中添加的位置权限。然后我注释掉这部分,它就工作了。
# post_install do |installer|
# installer.pods_project.targets.each do |target|
# flutter_additional_ios_build_settings(target)
# end
# end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## Add this line
'PERMISSION_LOCATION=1'
]
end
end
end
完整代码:POD文件
# 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,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.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)
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
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## Add this line
'PERMISSION_LOCATION=1'
]
end
end
end
像这样把它们全部移到一个地方,对我来说很有效。
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.build_settings['WRAPPER_EXTENSION'] == 'bundle'
config.build_settings['DEVELOPMENT_TEAM'] = 'S09DP9UN6F'
end
end
end
end
后post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.build_settings['WRAPPER_EXTENSION'] == 'bundle'
config.build_settings['DEVELOPMENT_TEAM'] = 'S09DP9UN6F'
end
end
end
end
use abstract_target
链接点击这里