Cocoapods: Allow different version of a pod per build configuration

Created on 18 Jan 2017  路  4Comments  路  Source: CocoaPods/CocoaPods

Is it possible to set a different version of a pod per build configuration (NOT PER TARGET)?

I know it's possible to do the following and only have a pod in the given configurations
pod 'Lib', :configurations => ['Debug']

What I'm trying to do is to provide a different version per config

// Framework built for debug and supports simulator
pod 'Lib', '1.0', :configurations => ['Development', `Integration`]
// Framework built for release
pod 'Lib', '1.0r', :configurations => ['Appstore']

Most helpful comment

@minuscorp your approach doesn't work in case when pod version is not the only thing that should be changed

def pod_RxDataSources
    if %r{^true$}i.match ENV['USE_DEBUG_PODS']
        pod 'RxDataSources', :git => 'https://github.com/iwheelbuy/RxDataSources.git'
    else
        pod 'RxDataSources', '3.0.2'
    end
end

target 'Example' do
    pod_RxDataSources
end

Using it this way:

USE_DEBUG_PODS=true pod install

or some function in .zshrc:

function podinstall_debug {
    USE_DEBUG_PODS=true pod install
}

All 4 comments

Your podfile is ruby you could have logic that checks an environment variable (or something else) that basically returns a different version and configuration array to use.

Here's a method to achieve this.

def configs_for_debug_menu_only_dependencies
  if %r{^beta$}i.match ENV['RELEASE_VARIANT']
    ['Debug', 'Release']
  else
    ['Debug']
  end
end

# Use it like this:
pod 'MyPod', '1.0.0', configuration: configs_for_debug_menu_only_dependencies

if you use RELEASE_VARIANT=beta pod install should install this pod on both debug and releases for dogfood versus debug only for non-dogfood builds.

Closing at the moment since this can be easily achieved.

I don't think your answer solved the issue the OP posted. I'm getting in the same issue. I have a pod which depending of its version should be used either one version for debug builds and another version for release builds.
Your script only changes which configurations is the same version of the pod being installed depending of the environment variable. But as was clearly posted, we want a behavior like:

  pod 'MyPod', '1.0.0', :configuration => ['Debug']
  pod 'MyPod', '> 1.0.0', :configuration => ['Release']

Kind regards!

EDIT:

I auto-answer my question:

def version_for_debug_or_release
  if ENV['POD_RELEASE'] =~ "true"
    '> 1.0.0'
  else
    '1.0.0'
  end
end

pod 'MyLib', version_for_debug_or_release 

Solves the issue.

@minuscorp your approach doesn't work in case when pod version is not the only thing that should be changed

def pod_RxDataSources
    if %r{^true$}i.match ENV['USE_DEBUG_PODS']
        pod 'RxDataSources', :git => 'https://github.com/iwheelbuy/RxDataSources.git'
    else
        pod 'RxDataSources', '3.0.2'
    end
end

target 'Example' do
    pod_RxDataSources
end

Using it this way:

USE_DEBUG_PODS=true pod install

or some function in .zshrc:

function podinstall_debug {
    USE_DEBUG_PODS=true pod install
}
Was this page helpful?
0 / 5 - 0 ratings