Cocoapods: Pod defined "SWIFT_ACTIVE_COMPILATION_CONDITIONS" are overridden in debug builds

Created on 5 Apr 2017  ·  17Comments  ·  Source: CocoaPods/CocoaPods

🌈

Report

When using Xcodeproj 1.4.3, the build setting SWIFT_ACTIVE_COMPILATION_CONDITIONS is set to DEBUG for Swift debug builds as per Apple's default. This overrides any other flags that are potentially set by a pod. Please note that release builds don't have this issue.

Podfile to test:

target 'Test' do
  use_frameworks!
  pod 'Permission/Camera'
end

Including the following code will trigger an error in a debug build:

let camera = PermissionButton(.camera)

This is because the compilation of Permission/Camera is determined by a compiler flag.
(see PermissionConfiguration.xcconfig for more info)

Cause

The Xcodeproj dependency version was bumped by 5d471d6e1a9290b8d3c74cdc726c3493673c33d9, however, even with CocoaPods 1.2.0 (version before this commit) this can cause an issue because the dependency version was defined as (>= 1.4.1, < 2.0).

Current CocoaPod installations can also break this if the user updates/installs Xcodeproj separately (1.4.3 is deemed an official, stable, release).

Solution

The solution is to add $(inherited) to this build setting. As noted by @segiddins in CocoaPods/Xcodeproj#479, it's probably best to keep the Xcodeproj project in sync with Apple's defaults and override the setting in CocoaPods.

I'm currently taking a look at how to fix this efficiently, so consider this issue a heads up that CocoaPods 1.2.1.rc.1 broke some pods.

Original report from: CocoaPods/Xcodeproj#478

Most helpful comment

For anyone who has that issue, here is a workaround for CocoaPods 1.2.1.

⚠️ the workaround modifies the project generated by CocoaPods: the patch is thus fragile, and may have to be reapplied after CocoaPods has regenerated its project.

  1. Click on the Pods project in your workspace
  2. Click on the target of the pod that misses correct compilation options
  3. Click the Build Settings tab, and display all settings by levels
  4. Set the SWIFT_ACTIVE_COMPILATION_CONDITIONS of the Debug configuration to $(inherited) DEBUG (between Resolved and Config.File).

All 17 comments

This seems trickier than first thought. Simply adding $(inherited) to the pod's .xcconfig doesn't affect the debug value. As a matter of fact, any value set in the pod's .xcconfig doesn't affect the debug value from project.pbxproj.

Using SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Debug] is also a no-go, since Xcode creates a subset for the "config" specifier.
A great explanation for this can be found here: https://pewpewthespells.com/blog/xcconfig_guide.html#CondVarConfig

What I think needs to happen here:
In the generated project.pbxproj:
for every pod's debug (not release!) config build settings,
set value of SWIFT_ACTIVE_COMPILATION_CONDITIONS from DEBUG to "$(inherited) DEBUG".

@segiddins Any pointers for easily implementing this? (I'm not that familiar with the CocoaPods code base)

Maybe in Pod::Project#add_build_configuration?

The settings there seems to point to the wrong group in project.pbxproj.

Fixed in #6629

Any news on this? Seems like we got stuck waiting for cocoapods-integration-specs/#105 to land?

Hello, I have the same question as @phlippieb. Is there any workaround for CocoaPods 1.2.1? Should we downgrade to 1.1.1?

For anyone who has that issue, here is a workaround for CocoaPods 1.2.1.

⚠️ the workaround modifies the project generated by CocoaPods: the patch is thus fragile, and may have to be reapplied after CocoaPods has regenerated its project.

  1. Click on the Pods project in your workspace
  2. Click on the target of the pod that misses correct compilation options
  3. Click the Build Settings tab, and display all settings by levels
  4. Set the SWIFT_ACTIVE_COMPILATION_CONDITIONS of the Debug configuration to $(inherited) DEBUG (between Resolved and Config.File).

If you, like me, ran into this from the Permission pod, there's another workaround for that pod on this issue.

Thanks @phlippieb. Less frustration in this world.

How do we get this fix on homebrew? Do we wait for the next release?

@phlippieb - hey, also facing this issue with Permission, but none of the above — including the suggestion in the relevant Permission’s thread — worked for me. Still getting the same build error. Perhaps you have any other suggestion? Also tried to include the library without pods — i.e., directly dragging it to my project — but same status.

@oferRounds Here's what I do:

  1. In XCode, go to the project navigator (press cmd+1, or click on the folder icon on the left)
  2. Click on the blue Pods project icon
  3. In the pane just to the right of the project navigator, you should see a list of targets. Click on Permission.
  4. In the pane just to the right of that, at the top, click on Build settings
  5. Search for "custom flags"
  6. You should see an entry called "Active compilation conditions", with two sub-entries named "Debug" and "Release".
  7. Copy the contents of "Release"
  8. Paste it into "Debug"

You have to do this every time after you run pod install. Luckily, XCode remembers where you were in the Pods project pane, so after the first time, you only really have to do step 7 and 8. It's still very tedious though, and I wish Cocoapods would release their fix already.

screen shot 2017-06-14 at 2 27 49 pm

Seems fixed in 1.3.1! Thanks Cocoapods team :)

Confirmation, it's fixed in Cocoapods 1.3.1 great work

@phlippieb – missed your answer! THANK YOU!

Was this page helpful?
0 / 5 - 0 ratings