指定多个post_install挂钩的无效Podfile文件不受支持

时间:2016-11-09 14:09:16

标签: ios cocoapods

我使用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|

以前有人遇到过同样的问题吗?是的!我在我的1个目标中有1个post_install,在全局范围内有另一个。我可以搬进去,但为什么呢?

5 个答案:

答案 0 :(得分:3)

当我从主目标中移除代码并移动到全局范围的post_install块时,它就像魅力一样。

出于某种原因,如果添加多个post_install(例如全局和1个目标),请将它们移动到同一个全局块中,并添加if-else语句来管理目标。

答案 1 :(得分:1)

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

答案 2 :(得分:0)

我暂时解决了这一冲突。将代码放入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

答案 3 :(得分:0)

使用abstract_target

链接click here

答案 4 :(得分:0)

我遇到了类似的问题,这是因为我在 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