4

I spend hours trying Extension target to use separate pods config from main target. The reason for that is that Pods are duplicated for extension target and thus making your whole app about twice in size. Need to make Extension contain only pods that's necessary there.

There seem to be some magic that XCode does when embedding Extension into main target, and CocoaPods seem to be oblivious to that whole procedure? Or I am doing it wrong? I tried al kinds of Podfile configurations, nothing works. Anyone was able to successfully achieve that?

to reproduce:

  1. Create a new project, target "MainTarget"
  2. select Add Target > Today Extension, name target "Extension"
  3. Create podfile:
target 'MainTarget' do
pod 'RestKit', '~> 0.20.3'
pod 'AFNetworking', '~> 1.3.1'
pod 'SSKeychain', '~> 1.2.0'
pod "MagicalRecord/Shorthand", '~> 2.2'
pod 'StyledPageControl', '~> 1.0'
pod 'GoogleAnalytics-iOS-SDK', '~> 3.0.2'
end

target 'Extension' do
    pod 'AFNetworking', '~> 1.3.1'
end

4 run pod install 5 build

result:

/Users/d/Library/Developer/Xcode/DerivedData/MainTarget-fvmcyblwdybpkdgfzflcjhqpjxab/Build/Products/Debug-iphonesimulator/libPods.a(AFHTTPRequestOperation.o)
/Users/d/Library/Developer/Xcode/DerivedData/MainTarget-fvmcyblwdybpkdgfzflcjhqpjxab/Build/Products/Debug-iphonesimulator/libPods-MainTarget.a(AFHTTPRequestOperation.o)
duplicate symbol _OBJC_IVAR_$_AFHTTPRequestOperation._successCallbackQueue in:
/Users/d/Library/Developer/Xcode/DerivedData/MainTarget-fvmcyblwdybpkdgfzflcjhqpjxab/Build/Products/Debug-iphonesimulator/libPods.a(AFHTTPRequestOperation.o)
/Users/d/Library/Developer/Xcode/DerivedData/MainTarget-fvmcyblwdybpkdgfzflcjhqpjxab/Build/Products/Debug-iphonesimulator/libPods-MainTarget.a(AFHTTPRequestOperation.o)

...(and so on... every file repeated 4 times.)

ld: 2148 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Andrew
  • 15,357
  • 6
  • 66
  • 101
Roman
  • 1,920
  • 2
  • 17
  • 17

2 Answers2

3

This is because you're including AFNetworking at least twice. If it is the only library you need in your extension you should use:

target 'Extension', :exclusive => true do
  pod 'foo'
end

Documented here

If you would instead like all your libraries linked to your extension you should remove your 'MainTarget' group and use link_with as shown here

Community
  • 1
  • 1
Keith Smiley
  • 61,481
  • 12
  • 97
  • 110
3

I figured out how to do it thanks to Keith Smiley. It required me a little testing. Here is what I did

platform :ios, 7.0

link_with ['Target', 'Target todays widget']

pod 'AFNetworking', '~> 2.2'

Than I had to remove the libPods.a and the others before redoing a pod install and it worked.

jfgrang
  • 1,148
  • 13
  • 13