Invalid Podfile file specifying multiple post_install hooks is unsupported
Asked Answered
N

7

11

I'm using cocoapods 1.1.1 and in my podfile I have more than one post_install hooks. And I'm getting this error :

[!] Invalid `Podfile` file: [!] Specifying multiple `post_install` hooks is unsupported..
-------------------------------------------
 #
 >  post_install do |installer|
 #      installer.pods_project.targets.each do |target|

Did anyone face the same problem before? And Yes! I have 1 post_install in my 1 target and another in global scope. I could move in one, but why?

Nabob answered 9/11, 2016 at 14:9 Comment(0)
N
15

Solution 2023

When I removed my code from my main target and moved in global scope's post_install block it's works like charm.

For some reason if you add multiple post_install (global and 1 target for instance) move them in same global block and add if-else statements for managing targets.

Nabob answered 9/11, 2016 at 14:43 Comment(0)
O
4

Move all of them to one place like this, it worked for me.

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

after

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
Orthogonal answered 9/11, 2016 at 14:9 Comment(0)
T
4

I temporarily solved this conflict. Put the code in your 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
Tenorrhaphy answered 28/3, 2019 at 7:57 Comment(0)
M
3
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

end

Mildredmildrid answered 14/11, 2016 at 11:51 Comment(4)
Please try to remove post_install block. And try again. And share warnings after "pod install"Nabob
Ok now (as expected) "pod install" works correctly, but compiler now show me some warnings: ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES build setting defined in `Pods/Target Support Files/Pods-TargetName/Pods-TargetName.xcconfig'. This can lead to problems with the CocoaPods installationMildredmildrid
I'm glad. Now check your warnings in Xcode, if Xcode has some update for settings, let it update your settingsNabob
Yep.. now it works correctly and for your info, moving "post_install" out of main block, solved all the problems with GCC_PREPROCESSOR_DEFINITIONS macro in different target. Well done!Mildredmildrid
R
3

I had the Similar Issue , Its Because of the Location Permission Which I added in POD file . then I comment Out this Portion and it works .

# 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 : POD file

# 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
Rita answered 28/6, 2021 at 22:43 Comment(0)
B
1

use abstract_target

Link click here

Briefing answered 2/7, 2020 at 18:22 Comment(1)
Please, read the post carefully. This no about abstract_target.Nabob
E
1

I had..

post_install do |installer|
  react_native_post_install(
    installer,
    # Set `mac_catalyst_enabled` to `true` in order to apply patches
    # necessary for Mac Catalyst builds
    :mac_catalyst_enabled => false
  )
  __apply_Xcode_12_5_M1_post_install_workaround(installer)
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == "react-native-quick-sqlite" then
      target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'SQLITE_ENABLE_FTS5=1'
      end
    end
  end
end

and just needed to change it like so..

post_install do |installer|
  react_native_post_install(
    installer,
    # Set `mac_catalyst_enabled` to `true` in order to apply patches
    # necessary for Mac Catalyst builds
    :mac_catalyst_enabled => false
  )
  __apply_Xcode_12_5_M1_post_install_workaround(installer)

  installer.pods_project.targets.each do |target|
    if target.name == "react-native-quick-sqlite" then
      target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'SQLITE_ENABLE_FTS5=1'
      end
    end
  end
end

merging the two blocks with post_install do |installer| into the same block.

Errantry answered 12/6, 2024 at 8:28 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.