Cocoapods: Setting IPHONEOS_DEPLOYMENT_TARGET when using :generate_multiple_pod_projects

Created on 21 Oct 2020  路  4Comments  路  Source: CocoaPods/CocoaPods

Report

What did you do?

Ran pod install with this Podfile:

source 'https://cdn.cocoapods.org/'
use_frameworks! :linkage => :static
inhibit_all_warnings!

install! 'cocoapods', :generate_multiple_pod_projects => true

deployment_target = '13.0'
platform :ios, deployment_target

target 'DeploymentTargetTest' do
    pod 'SDCAlertView'
end

post_install do |installer|
    installer.generated_projects.each do |project|
        project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
            end
        end
    end
end

As you can see, I'm using the post-install hook to set the deployment target, but this does not appear to set it everywhere it's needed:

$ grep -r IPHONEOS_DEPLOYMENT_TARGET Pods
Pods/Pods.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Pods/Pods.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Pods/Pods.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Pods/Pods.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Pods/SDCAlertView.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 9.0;
Pods/SDCAlertView.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Pods/SDCAlertView.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Pods/SDCAlertView.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 9.0;
Pods/SDCAlertView.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Pods/SDCAlertView.xcodeproj/project.pbxproj:                IPHONEOS_DEPLOYMENT_TARGET = 13.0;

Are there any other post-install actions that are required to update the remaining IPHONEOS_DEPLOYMENT_TARGET settings, which are apparently the ones Xcode is looking at?

What did you expect to happen?

Compilation without warnings, all deployment target settings updated to 13.0

What happened instead?

I'm seeing a warning to update the project settings for SDCAlertView: "Update the minimum deployment target of project 'SDCAlertView' to '12.0'"

CocoaPods Environment

Cocoapods 1.10, Xcode 12.1, running on macOS 10.15.7

Project that demonstrates the issue

https://github.com/gereons/DeploymentTargetTest

workaround available

Most helpful comment

You are not changing the projects root object deployment target. You are changing all targets within it.

Screen_Shot_2020-10-21_at_9_58_00_AM

This could be a tiny bug in cocoapods but workaround is

post_install do |installer|
    installer.generated_projects.each do |project|
        project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
            end
        end
        project.build_configurations.each do |bc|
            bc.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
        end
    end
end

However, this does seem to be a cocoapods bug also as the project we generate should use the same one in Pods.xcodeproj which for some reason it gets the right version.

All 4 comments

You are not changing the projects root object deployment target. You are changing all targets within it.

Screen_Shot_2020-10-21_at_9_58_00_AM

This could be a tiny bug in cocoapods but workaround is

post_install do |installer|
    installer.generated_projects.each do |project|
        project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
            end
        end
        project.build_configurations.each do |bc|
            bc.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
        end
    end
end

However, this does seem to be a cocoapods bug also as the project we generate should use the same one in Pods.xcodeproj which for some reason it gets the right version.

Ah this may be working as intended actually. The platform of the root object is determined by the pods it includes. In this case SDCAlertView sets its deployment target to 9.0.

So the workaround proposed above is the correct way to fix this and I do not think we should change this logic into CocoaPods.

Closing for now.

Thanks! That workaround is just what I was looking for :)

Thanks a lot! This works for our project!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sonu5 picture sonu5  路  3Comments

pronebird picture pronebird  路  3Comments

k06a picture k06a  路  3Comments

pallaviMN picture pallaviMN  路  3Comments

evermeer picture evermeer  路  3Comments