You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cocoapods:工作区双App共享私有框架的依赖问题排查

Hey there! Let's tackle both the warning and runtime error you're facing. Here's what's going on and how to fix it:

Why You're Seeing These Issues

  1. The Warning: CocoaPods is alerting you that your Common framework target doesn't have a "host" target (like an app or test target) that embeds it. Since this framework is meant to be used by your two apps, we need to link it properly to those app targets so CocoaPods recognizes their relationship.
  2. The Runtime Error: Your Common framework depends on Alamofire (via Moya), but right now Alamofire is only installed for the Common target—not your app targets. When the app tries to run, it can't find Alamofire in its own frameworks directory, hence the "image not found" error.

Fixed Podfile Configuration

Replace your current Podfile with this updated version, which properly links the framework to your apps and ensures all dependencies are embedded correctly:

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
use_frameworks!
workspace 'SIPMI'

# Shared pod groups
def networking_pods
    pod 'Moya/RxSwift', '10.0.2'
end

def application_pods
    pod 'RxCocoa', '4.1.2'
    pod 'Fabric', '1.7.3'
    pod 'Crashlytics', '3.10.0'
    pod 'IQKeyboardManagerSwift', '5.0.7'
end

# Abstract target to bundle shared dependencies for apps using Common
abstract_target 'AppWithCommon' do
    # Include app-specific pods
    application_pods
    # Include framework-dependent pods (so apps embed them too)
    networking_pods

    target 'TKIApp' do
        project 'TKIApp/TKIApp.xcodeproj'
        # Link the Common framework to this app
        pod 'Common', :path => './Common'
    end

    target 'WalletApp' do
        project 'WalletApp/WalletApp.xcodeproj'
        # Link the Common framework to this app
        pod 'Common', :path => './Common'
    end
end

# Optional: Add a test target for Common to fully resolve the warning
target 'CommonTests' do
    project 'Common/Common.xcodeproj'
    inherit! :search_paths
    networking_pods
end

Key Changes Explained

  • Abstract Target: The AppWithCommon abstract target lets us define shared pods once, so both apps inherit them—including the networking pods that Common needs. This ensures Alamofire is embedded in your apps, fixing the runtime error.
  • Linking Common: Using pod 'Common', :path => './Common' tells CocoaPods to handle embedding the Common framework into each app automatically, which resolves the host target warning.
  • Optional Test Target: Adding CommonTests gives Common a dedicated host target for testing, which fully eliminates the CocoaPods warning if you need to run framework-specific tests.

Post-Configuration Steps

  1. Clean up old Pods setup: Run pod deintegrate in your terminal.
  2. Reinstall pods: Run pod install.
  3. Open the generated .xcworkspace file (not the .xcodeproj).
  4. Double-check your app's settings:
    • Go to your app target's General tab, confirm Common.framework is listed under Embedded Binaries.
    • Verify Build Settings > Runpath Search Paths includes @executable_path/Frameworks (this is default, but good to check).

That should get rid of both the warning and the runtime crash!

内容的提问来源于stack exchange,提问作者alpiopio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:58:28