Kiwi and CocoaPods with a static shared library

陌路散爱 提交于 2019-12-01 21:52:23

I finally found a working solution for this. Here's the Podfile:

platform :ios, '7.0'

workspace 'MyApp.xcworkspace'

xcodeproj 'MyApp'

pod 'CupertinoYankee', '~> 1.0'

target :MyAppTests, :exclusive => true do
    pod 'Kiwi/XCTest'
end

target :Common, :exclusive => true do
    xcodeproj 'Common/Common'
    pod 'CupertinoYankee', '~> 1.0'
end

target :CommonTests, :exclusive => true do
    xcodeproj 'Common/Common'
    pod 'Kiwi/XCTest'
end

This example Podfile shows both MyApp and Common configured to use Kiwi for tests and they can both use pods (CupertinoYankee in this example).

I did manually have to configure in Xcode that MyApp links with Common with these steps:

  1. In MyApp project settings > MyApp target > Build Phases > Link Binary With Libraries > add libCommon.a
  2. In MyApp project settings > Build Settings > User Header Search Paths > add ${SRCROOT}/Common/Common/**

This repo has a working example: https://github.com/lyahdav/cocoapods_kiwi_shared_library

The only slightly annoying thing I didn't manage to figure out was if there's a way to not duplicate each pod that I want to use both in MyApp and Common. If anyone has a solution that does all of what my solution does and solves that, I'll gladly mark it the accepted answer.

Jossef Harush

Posted as an edit by anonymous user. Here's his answer:


I have forked the repository and made few changes for new cocoapods versions to make it still working.

platform :ios, '8.0'

workspace 'MyApp.xcworkspace'

project 'MyApp'

target :MyApp do
    pod 'CupertinoYankee', '~> 1.0'
end

target :MyAppTests do
    pod 'Kiwi/XCTest'
end

target :Common do
    project 'Common/Common'
    pod 'CupertinoYankee', '~> 1.0'
end

target :CommonTests do
    project 'Common/Common'
    pod 'Kiwi/XCTest'
end

https://github.com/chrishunterkiller/cocoapods_kiwi_shared_library

I'm not sure how to fix the setup you have, but if I were you I would make Common into its own Pod. Pods can be private and just stored in GitHub as a repo. Of course, you need a podspec for Common but I built a sample to test that setup for our build service and it took me less than 30 mins to get it right.

Then in your Podfile for MyApp, you do something like this:

pod 'Common', :git => 'git@github.com:lyahdav/Common.git', :commit => 'a1b2c3d'

And AFNetworking and Reachability can be referenced in the podspec of Common (assuming that's the right dependency).

This setup also allows you to include Common in whatever other apps you're building without having to embed the code. Again, making assumptions about what you're trying to achieve, so add more detail to the question if that's not right.

You could hack a solution that may get broken again, or better yet as Common is your library, start using CocoaPods for your Common library as well.

It will show up as a local "Dvelopment Pod", which means that you can directly edit the library code as well.

To begin easily just create a Common.podspec at the root folder:

$ pod lib create Common

Then just edit the minimum required parameters, such as platform, source_files, requires_arc and dependency if any.

You can take a look at how your library looks as you change it (and compare it to what you had with your manually created Common library):

$ pod lib lint --no-clean Common.podspec

Finally remove the no-longer needed Common from your workspace and add this to your Podfile:

pod 'Common', :path => '../Relative/Path/To/CommonSources/'

It will take you no more than 30 minutes and you'll learn many things in the process.

Next you could take a look at making private pod repositories.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!