117

I use CocoaPods to manage dependencies in my project. I've written Podfile:

target 'MyApp' do
  platform :ios, '8.0'
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
  #use_frameworks!

  # Pods for MyApp
  pod 'KeepLayout', :git => 'https://github.com/iMartinKiss/KeepLayout', :tag => 'v1.6.0'
  pod 'EasyMapping'

  target 'MyAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'MyAppUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

This file works well with CocoaPods 0.x but I can't compile project after I've updated to CocoaPods 1.0. After I've run

pod update 

I can't compile my project with error:

/Users/<...>/Pods/KeepLayout/Sources/KeepAttribute.m:195:1: Cannot synthesize weak property because the current deployment target does not support weak references

I've seen that every library is builded with different deployment target. For example KeepLayout is builded with 4.3 deployment target.

How I can determine build target for every pod dependency?

Andrew Romanov
  • 4,774
  • 3
  • 25
  • 40
  • Temporary solution: go in xcode, click the 'Pods' project, and set the deployment target above 6, I think, when 'weak' appeared. I have 8.0. But after each pod install it reverts to 4, so I'm also curios about a definitive solution. – codrut May 11 '16 at 12:44
  • Thanks. I've created it before, but do not think that it is a good solution. – Andrew Romanov May 11 '16 at 12:51
  • Also I've find script to create it automatic for every target from the project, but it does not work with CocoaPods 1.0. :( – Andrew Romanov May 11 '16 at 12:55
  • 2
    `pod update` is setting the deployment target of the pod to iOS 4.3 because that is the default deployment target if the podspec doesn't specify one. This was an intentional decision by the CocoaPods team, even though it breaks some older pods that basically have an incomplete podspec. If you are maintaining the pod, you should specify an appropriate target, e.g. `platform :ios, '8.0'` to fix it. If you are just trying to use a pod that is broken in this way, please try my suggestion below. – Alex Nauda May 18 '16 at 03:26
  • @codrut thank you for the quick fix. For anyone else looking I have just updated to Cocoapods 1.0.0. This required a syntax change in my podfile. I am using maybe 15 pods which all compiled fine except for MBProgressHUD. The pods project itself is set to 8.0 as defined in my Podfile, but for some reason the MBProgressHUD target was set to 4.3. The fix listed blow by Alex Nauda works great for a permanent solution. – VaporwareWolf May 30 '16 at 20:32

7 Answers7

228

While some development versions of CocoaPods (as well as pre-1.0 versions) may have propagated the deployment target of the project down to the pods, this is no longer the case in 1.0. To work around this, the current developer recommends using a post-install hook.

Here's a brute force approach to force a hard-coded deployment target for every pod in the generated Pods project. Paste this at the end of your Podfile:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.2'
    end
  end
end
DawnSong
  • 4,752
  • 2
  • 38
  • 38
Alex Nauda
  • 4,126
  • 1
  • 24
  • 24
150

Since the Podfile uses a directive like platform :ios, '9.0' to specify "iOS Deployment Target" (aka IPHONEOS_DEPLOYMENT_TARGET) for the Pods/Pods.xcodeproj project, you just need to remove the Deployment Target info from each build target.
Do it by adding this to your Podfile

platform :ios, '9.0' # set IPHONEOS_DEPLOYMENT_TARGET for the pods project
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
    end
  end
end

Inspired by the github post and Alex Nauda's answer.

DawnSong
  • 4,752
  • 2
  • 38
  • 38
21

Here is the way to set deployment target permanently for pod targets.

Goto -> podfile -> Add below code

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "12.0"
     end
  end
end
Yano
  • 585
  • 3
  • 18
12

While the accepted answer by Alex Nauda is good, but letting the Pods inherit the target from the app might be a much better solution.

app_ios_deployment_target = Gem::Version.new('9.2') # Change to your current deployment target

platform :ios, app_ios_deployment_target.version

# Let Pods targets inherit deployment target from the app
# This solution is suggested here: https://github.com/CocoaPods/CocoaPods/issues/4859
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |configuration|
      pod_ios_deployment_target = Gem::Version.new(configuration.build_settings['IPHONEOS_DEPLOYMENT_TARGET'])
      if pod_ios_deployment_target <= app_ios_deployment_target
        configuration.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
      end
    end
  end
end
Ahmed M. Hassan
  • 709
  • 9
  • 14
2

Swift 5 Simple Solution Copy paste the below code into end your podFile

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.1' //set your minimum version your all pods will set to mininum 13.1 version :-)
    end
  end
end

install your pods

//MARK: - Run the command in your terminal
pod install

Happy Coding

Shakeel Ahmed
  • 5,361
  • 1
  • 43
  • 34
-1

change target to "11.0"

platform :ios, '11.0'
As If Prince
  • 257
  • 2
  • 10
-2

1) Search for IPHONEOS_DEPLOYMENT_TARGET

2) Change the iOS Deployment Target

enter image description here

Francesco
  • 231
  • 3
  • 11
  • 41
    This is not a long-term solution. A "pod install" will revert the setting back to whatever was in the podspec. – John Fowler Aug 08 '19 at 20:20
  • @JohnFowler what is the long-term solution? – Opeyemi Noah May 16 '23 at 17:53
  • @OpeyemiNoah Long-term solution is to update the podfile in one of the manners listed in the acceptable solutions above. By updating the podfile, running a "pod install" will set the deployment target to the desired value. – John Fowler May 24 '23 at 00:23