Building a static library with cocoapods

前端 未结 3 516
孤独总比滥情好
孤独总比滥情好 2021-01-31 05:59

I am trying to build a static library that has different dependencies (AFNetworking for example) specified in a Podfile. I don\'t want the dependencies to be included in the fin

3条回答
  •  滥情空心
    2021-01-31 06:26

    Whilst manually removing the libPods.a from the "Link Binary with Libraries" build phase does indeed work, the real answer is to not let it get added there in the first place.

    The reason it is added is because the pod install command is finding the static library target as one of its targets to link with. This could be because it is the first target in the list (cocoapods' implementation causes it to pick the first one if you haven't explicitly specified targets) or it could be because you have explicitly stated it in the 'link_with' section.

    The answer I find is to use the link_with section of the Podfile to explicitly state your targets, and omit the static library target.

    The pods project is still created, and your dependencies brought into there as you'd expect, but the libPods.a isn't added to the build phase of your static library.

    The only problem is what to put into the link_with section, if not your static library. If you have other targets that you do want to link with (an iPhone app target for instance) that's a good choice. But if your only real target is your static library, you need a little workaround.

    My successful strategy so far has been to create a static library target (yes, a separate one from your main static library) and call it "Dummy". Specify this target in your Podfile's link_with section.

    It is a little distasteful, granted, but it does work.

    platform :ios, '5.1.1'
    
    link_with ['Dummy']
    
    pod 'AFNetworking', '= 1.3.1'
    

提交回复
热议问题