Using static libraries with CocoaPods 1.5 no such module at import

前端 未结 2 2015
遥遥无期
遥遥无期 2021-02-05 11:15

With CocoaPods 1.5 released I am trying to migrate from having 10-15 dynamic pods in my projects to having them as static libraries instead, with the goal of speeding up my app

相关标签:
2条回答
  • 2021-02-05 11:35

    In most cases for a small project it will be enough to add use_modular_headers! instead of the removed import_frameworks!.

    Alternatively you can try adding :modular_headers => true after each pod declaration of a "missing" module:

    pod 'Firebase/Auth' :modular_headers => true
    pod 'Firebase/Database' :modular_headers => true
    pod 'Firebase/Storage' :modular_headers => true
    pod 'Firebase/DynamicLinks' :modular_headers => true
    

    However, a bigger project might contain modules that just don't want to be static, with or without modular headers. One good example is Facebook SDK. For this case there is a cool addition here, which allows to specify which modules you want to leave dynamic.

    Here's an example podfile, where all libs will be static except the ones, listed in the dynamic_frameworks array:

    platform :ios, deployment_target: '9.3'
    
    inhibit_all_warnings!
    
    # Import CocoaPods sources
    source 'https://github.com/CocoaPods/Specs.git'
    use_frameworks!
    dynamic_frameworks = ['Bolts', 'FBSDKCoreKit', 'FBSDKLoginKit', 'FBSDKShareKit']
    
    # make all the other frameworks into static frameworks by overriding the static_framework? function to return true
    pre_install do |installer|
        installer.pod_targets.each do |pod|
            if !dynamic_frameworks.include?(pod.name)
                puts "Overriding the static_framework? method for #{pod.name}"
                def pod.static_framework?;
                    true
                end
            end
        end
    end
    
    target 'MyApp' do
    pod 'SwiftLint'
    pod 'Firebase/Auth'
    pod 'Firebase/Database'
    pod 'Firebase/Storage'
    pod 'Firebase/DynamicLinks'
    pod 'FBSDKCoreKit', '~> 4.33.0'
    pod 'FBSDKLoginKit', '~> 4.33.0'
    pod 'FBSDKShareKit', '~> 4.33.0'
    
    end
    
    0 讨论(0)
  • 2021-02-05 11:37

    CocoaPods 1.5.0 introduced use_modular_headers! to still provide module support with static libraries. Details in the release notes.

    Alternatively you could change the modular imports in your sources to file imports.

    I'd also recommend trying out the CocoaPods 1.6.0 beta since it has several fixes for static/dynamic library and framework issues.

    2020 Update

    CocoaPods 1.9.0 introduced use_frameworks! :linkage => :static which will generate full frameworks with statically linked libraries and module map files. This is typically an even better approach than use_modular_headers!.

    0 讨论(0)
提交回复
热议问题