Fix: Class Implemented in Both Framework and App Target with CocoaPods

Fix: Class Implemented in Both Framework and App Target with CocoaPods

Written by

in

Quick answer: The warning occurs because CocoaPods links the same framework dependencies into both your framework target and your app target. Fix it by removing the duplicate framework references from the app target’s OTHER_LDFLAGS in the generated Pods-[AppName].debug.xcconfig file, or automate the cleanup with a post_install hook in your Podfile.

Why this happens

When you define separate CocoaPods targets for a framework and an app that embeds that framework, CocoaPods generates distinct Pods-[TargetName].debug.xcconfig and Pods-[TargetName].release.xcconfig files for each target. If the framework target declares a dependency (for example AFNetworking) and the app target does not declare it, CocoaPods still adds -framework AFNetworking to the app target’s OTHER_LDFLAGS because the framework itself is linked into the app. At runtime the dynamic loader finds the same class—such as PodsDummy_AFNetworking—in both the embedded framework binary and the app binary, and emits:

Class PodsDummy_AFNetworking is implemented in both
/private/var/containers/Bundle/Application/.../MyFramework.framework/MyFramework
and
/var/containers/Bundle/Application/.../MyFrameworkExampleApp
One of the two will be used. Which one is undefined.

The root cause is duplicate -framework entries in the app target’s linker flags for frameworks that are already embedded inside the framework target.

How to fix it

1. Manual xcconfig edit (quickest for one-off fixes)

  1. In the Project Navigator, expand Pods → Target Support Files → Pods-MyFrameworkExampleApp.
  2. Open Pods-MyFrameworkExampleApp.debug.xcconfig (and the .release counterpart).
  3. Locate the OTHER_LDFLAGS line. It will contain entries like -framework "AFNetworking" -framework "ReactiveCocoa" ….
  4. Delete every -framework "<DuplicateFramework>" that also appears in your framework target’s pod list.
  5. Clean the build folder (Product → Clean Build Folder) and rebuild.

Note: This edit is overwritten on every pod install. Use the automated fix below for a permanent solution.

2. Automated post_install hook (recommended)

Add the following post_install block to your Podfile. Replace MyFramework and MyFrameworkExampleApp with your actual target names.

post_install do |installer|
  framework_target_name = 'Pods-MyFramework'
  app_target_name       = 'Pods-MyFrameworkExampleApp'

  framework_aggregate = installer.aggregate_targets.find { |t| t.name == framework_target_name }
  app_aggregate       = installer.aggregate_targets.find { |t| t.name == app_target_name }

  next unless framework_aggregate && app_aggregate

  # Collect framework names that the framework target vendors
  framework_names = Set.new
  framework_aggregate.pod_targets.each do |pod_target|
    pod_target.specs.each do |spec|
      vendored = spec.attributes_hash['vendored_frameworks'] ||
                 spec.attributes_hash.dig('ios', 'vendored_frameworks')
      Array(vendored).each do |path|
        framework_names << File.basename(path, File.extname(path))
      end
    end
  end

  # Remove those frameworks from the app target's OTHER_LDFLAGS
  app_aggregate.xcconfigs.each do |config_name, config_file|
    framework_names.each do |name|
      if config_file.frameworks.delete(name)
        puts "[CocoaPods] Removed duplicate framework '#{name}' from #{config_name}"
      end
    end
    config_file.save_as(app_aggregate.xcconfig_path(config_name))
  end
end

Run pod install again. The hook strips the duplicate -framework flags from the app target’s generated xcconfig files before they are written to disk, eliminating the runtime warnings permanently.

3. Alternative: Restructure pod targets (cleanest architecture)

If you control both targets, consider making the framework target a dependency of the app target instead of embedding it as a separate CocoaPods target:

target 'MyFramework' do
  # … all framework pods …
end

target 'MyFrameworkExampleApp' do
  # No pods here; the app links MyFramework.framework
  # which already bundles its dependencies.
end

Then, in the app target’s General → Frameworks, Libraries, and Embedded Content, add MyFramework.framework as Embed & Sign. This way CocoaPods only resolves dependencies once, and the duplicate-symbol problem cannot occur.

How to prevent it

  • Keep a single source of truth for shared dependencies: declare them only in the framework target.
  • Use the post_install hook above in every workspace that mixes a framework target with an app target.
  • Run pod install in CI and verify the generated xcconfig files contain no duplicate -framework entries for the same library.
  • Prefer static frameworks or XCFrameworks when possible; they avoid the duplicate-class runtime ambiguity.

FAQ

Why does the warning mention PodsDummy_<Framework> classes?

CocoaPods generates a dummy class (PodsDummy_<Framework>) for each vendored framework to force the linker to include the framework’s symbols. When the same framework is linked into both the embedded framework and the host app, two copies of that dummy class exist, triggering the Objective-C runtime warning.

Can I suppress the warning instead of fixing the duplication?

You can add -Wl,-no_duplicate_symbols to OTHER_LDFLAGS, but this only silences the linker; the runtime still loads two copies, which can cause subtle bugs (e.g., singleton state split across copies). Removing the duplicate linkage is the correct fix.

Does this affect Swift packages or only CocoaPods?

The same duplication can happen with Swift Package Manager if you link a package product into both a framework target and an app target that embeds that framework. The fix is identical: ensure the package product is linked only once, typically by letting the framework target re-export it and the app target link only the framework.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.