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

carvr3hs  于 2023-10-21  发布在  iOS
关注(0)|答案(6)|浏览(180)

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

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

yrdbyhpb

yrdbyhpb1#

解决方案2023

当我从我的主目标中删除我的代码并将其移到全局范围的post_install块中时,它就像魅力一样工作。
出于某种原因,如果您添加多个post_install(例如全局和1个目标),请将它们移动到同一个全局块中,并添加if-else语句用于管理目标。

nwlqm0z1

nwlqm0z12#

我暂时解决了这场冲突。把代码放到你的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
rkttyhzu

rkttyhzu3#

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

nbewdwxp

nbewdwxp4#

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

Full Code:P2P

# 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
50pmv0ei

50pmv0ei5#

把他们都搬到这样的地方,这对我很有效。

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
bvpmtnay

bvpmtnay6#

使用abstract_target
链接click here

相关问题