Skip to content

Resolving "DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS" in Xcode 15

Problem Statement

After updating Xcode to version 15 (with macOS Sonoma), many developers encounter build errors such as:

Common error messages include:

plaintext
Firebase - DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead
FirebaseAnalytics - DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead
GoogleMLKit - DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead

This issue occurs because Xcode 15 replaces the DT_TOOLCHAIN_DIR environment variable with TOOLCHAIN_DIR. Projects or pods referencing the old variable cause build failures, typically affecting:

  • Firebase-related modules
  • CocoaPods dependency management
  • Flutter iOS builds
  • Legacy projects migrated from Xcode 14

Primary Solution: Update CocoaPods

The most reliable fix is updating CocoaPods to v1.13.0+. This version includes a patch for Xcode 15 compatibility.

Steps:

  1. Update CocoaPods:

    bash
    sudo gem update cocoapods
    # Alternatively with Homebrew:
    brew upgrade cocoapods
  2. Verify installation:

    bash
    pod --version  # Should show 1.13.0+

  3. Clean project artifacts:

    bash
    cd ios
    flutter clean     # For Flutter projects
    rm Podfile.lock
    rm -rf Pods/
  4. Reinstall dependencies:

    bash
    flutter pub get  # Flutter projects only
    pod install
    pod update       # Recommended to refresh pods
  5. Clean build folder in Xcode (Product > Clean Build Folder)

Alternative Solution: Add Podfile Script (Temporary Fix)

If updating CocoaPods doesn't resolve the issue immediately, add a post_install hook to your Podfile:

ruby
post_install do |installer|
  installer.pods_project.targets.each do |target|
    # Flutter projects only: keep this line
    flutter_additional_ios_build_settings(target)
    
    target.build_configurations.each do |config|
      next unless config.base_configuration_reference
      xcconfig_path = config.base_configuration_reference.real_path
      xcconfig = File.read(xcconfig_path)
      xcconfig_mod = xcconfig.gsub('DT_TOOLCHAIN_DIR', 'TOOLCHAIN_DIR')
      File.write(xcconfig_path, xcconfig_mod)
    end
  end
end

Apply the script:

  1. Run pod install
  2. Perform a full rebuild (Shift-Command-K to clean)

Additional Troubleshooting Steps

For persistent issues:

  1. Manual search/replace:
    In Xcode, open Find > Find and Replace in Workspace and replace all DT_TOOLCHAIN_DIR with TOOLCHAIN_DIR.

  2. Update iOS deployment target:
    Ensure your Podfile specifies a minimum iOS version ≥ 13.0:

    ruby
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
        end
      end
    end
  3. Flutter-specific fixes:

    • Upgrade problematic packages (e.g., flutter_inappwebview to v5.8.0+)
    • Run:
      bash
      flutter clean && flutter pub get
      cd ios
      pod install

Explanation

  • Apple deprecated DT_TOOLCHAIN_DIR in Xcode 15's build system, replacing it with TOOLCHAIN_DIR.
  • Older CocoaPods versions (pre-1.13.0) hardcode DT_TOOLCHAIN_DIR, causing LIBRARY_SEARCH_PATHS evaluation failures.
  • Updating CocoaPods resolves this permanently by patching internal references, while the Podfile script provides an immediate search-and-replace workaround.
  • Flutter projects require special handling due to additional build settings injected by the Flutter toolchain.

Important

Avoid manually editing pod configuration files unless necessary. If updating CocoaPods doesn't resolve your issue automatically, the temporary script solution should be used as an interim measure until library owners update their dependencies.