muyexi

Use both Carthage and CocoaPods

When the number of pods in your project increases, and it take forever to complete a fresh build, Carthage seems a better choice more and more. But you have dozens of pods, it's hard or impossible (React Native) to migrate all the pods to Carthage at once. So is it possible to use both Carthage and CocoaPods at the same time and migrate every pod one by one? Recently I figured out a way to do this.

Add Cartfile

Create Cartfile in the root directory of your project, add the pods you want to migrate, for example:

github "onevcat/Kingfisher" ~> 4.0

Run carthage update to fetch dependencies and build frameworks.

Add CarthageFrameworks.podspec

Use vendored_frameworks to reference frameworks generated by Carthage.

Pod::Spec.new do |s|
  s.name             = 'Carthage'
  s.version          = '0.1.0'
  s.summary          = 'Load Carthage frameworks'

  s.ios.deployment_target = '9.0'
  s.swift_version = '4.1'

  s.vendored_frameworks = 'Carthage/Build/iOS/*.framework'
end

Edit Podfile

Add CarthageFrameworks to your Podfile and comment out Kingfisher.

pod 'Carthage', :path => 'Carthage.podspec'

# pod 'Kingfisher'

pod `AnotherPod`

Run pod install to load Carthage frameworks.

If AnotherPod also depends on Kingfisher, now it needs to depend on CarthageFrameworks.

评论