Search code examples
iosxcodebuildcocoapods

How to prevent 'pod install' from overriding XCode 'BUILD_LIBRARY_FOR_DISTRIBUTION' setting?


'pod install' overrides the following pod setting of XCode IDE if set:

BUILD_LIBRARY_FOR_DISTRIBUTION=NO

Or to be more precise - it just deletes it meaning it will default to "YES" (for each library). This kills our build since we have libs (like OpenCombine, BetterSegment) that afterwards fail to build because build warnings are then handled as errors.

The only workaround is to make this setting again in XCode afterwards for each problematic library.


Solution

  • A workaround (until there exists a flag or bugfix for cocoapods) is to add the following in your Podfile:

    post_install do |installer|
      installer.pods_project.build_configurations.each do |config|   
        config.build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "NO"
        config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
      end
    
      installer.pods_project.targets.each do |t|
        t.build_configurations.each do |config|
          config.build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "NO"
         end
      end
    end
    

    This adds a post build hook to enable this setting again on library & global pod project level.

    Which is btw a common solution to set XCode pod configs back if 'pod install' is messing around with them.