Duplicate symbols when building iOS8 extension target - ios

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:
Create a new project, target "MainTarget"
select Add Target > Today Extension, name target "Extension"
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)

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

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.

Related

How can I run XCTest in my project there was a runtime error occur

I create a Xcode Framework project, and then I use CocoaPods to import another module. Then I want to write a Unit Test.
But when Unit Test run, there has been an run time error
2019-02-02 10:20:39.157536+0800 xctest[90385:6327514] The bundle “XXX” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2019-02-02 10:20:39.157855+0800 xctest[90385:6327514] (dlopen_preflight(/Users/XXX/Library/Developer/Xcode/DerivedData/XXX-dfsjsywxidmqgmaudrhgrhgniihc/Build/Products/Debug-iphonesimulator/XXX.xctest/XXXTests): Library not loaded: #rpath/XXX1.framework/XXX1
Referenced from: /Users/XXX/Library/Developer/Xcode/DerivedData/XXX-dfsjsywxidmqgmaudrhgrhgniihc/Build/Products/Debug-iphonesimulator/XXX.framework/XXX
Reason: image not found)
Program ended with exit code: 82
How can solve this problem.
In your Podfile, make sure that your module is also available for your Unit Test target.
Here is an example, some pods inherited from the main target, other only available for testing purpose.
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
pod 'AFNetworking', '~> 2.6'
pod 'ORStackView', '~> 3.0'
pod 'SwiftyJSON', '~> 2.3'
target 'MyAppTests' do
inherit! :search_paths
pod 'Quick'
end
end

Why does my iOS project with Cocoapods try (and fails) to build on a x86_64 architecture? [duplicate]

This question already has answers here:
ld: framework not found Stripe for architecture x86_64
(4 answers)
iOS , ld: framework not found GoogleMaps for architecture arm64
(3 answers)
Closed 6 years ago.
I got the following error testing my test target in Xcode:
ld: framework not found GoogleMapsBase for architecture x86_64
My project is an iOS project so I don't really understand why it builds with a x86_64 architecture. When examining my Pods project, the build settings feature the following settings:
Base SDK: No SDK (Latest macOS)
Supported Platforms: macOS
Valid architectures: i386 x86_64
My Podfile looks like this:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'Foo' do
use_frameworks!
...
pod 'GooglePlaces', '2.0.1'
...
target 'FooTests' do
inherit! :search_paths
pod 'Quick', '~> 1.0'
pod 'Nimble', '~> 5.0'
end
end
What can I do to fix this issue?
UPDATE: cf this link for the answer of a similar question that helped me fix my issue.
A question. Do you literally included ... in your podfile? Or is it you are omitting other pods with this sign?
Now, the simpler edition of your podfile would be like this:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'Foo' do
use_frameworks!
pod 'GooglePlaces', '2.0.1'
end
target 'FooTests' do
pod 'Quick', '~> 1.0'
pod 'Nimble', '~> 5.0'
end
This should work. Let us know what you got.

Quickblox: Undefined symbols for architecture x86_64: error

I used following pods but I'm getting Error
Undefined symbols for architecture x86_64:
platform :ios, "8.0" use_frameworks!
target 'CSocial' do
#
pod 'Alamofire', '~> 3.0'
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
pod 'FlickrKit'
pod 'MONActivityIndicatorView'
Chat Integration
pod 'QuickBlox'
#Production pod
#pod 'QMCVDevelopment', :git => 'git#github.com:QuickBlox/QMChatViewController-ios.git', :commit => '7244eaf609797a5dc5ec6d28dc2b284633b03a1f'
#For development pods
pod 'QMCVDevelopment', :git => 'https://github.com/QuickBlox/QMChatViewController-ios.git'
#Production pod
#pod 'QMServicesDevelopment', :git => 'git#github.com:QuickBlox/q-municate-services-ios.git', :commit => 'ab56ac143bb770e76409a027bfb38de582d728aa'
#For development pods
pod 'QMServicesDevelopment', :git => 'https://github.com/QuickBlox/q-municate-services-ios.git'
end
Go through the below steps and your problem will be solved:
1) Tap on "Pods.xcodeproj" in your project
2) Select all the pods / any of one in which you are facing the issue.
3)Tap on "Build Settings" and change "Build Active Architecture Only" to "NO"
4) Now try to build to build the project and your problem will be solved.
Hope this helps!
If you are using swift you have to link these libraries in the build settings of the project
search for the Framework search path and add the path for the libraries
I hope you have added all the frameworks mentioned by the Quickblox website ,
Add -lxml2, -ObjC flags to Other Linker Flags section in project settings
Official doc link including bolts if it's not already added by pods
For QMCV and QMService i am also facing some issue recently but after some setting is worked

Library not found for -lBraintree

I have added Braintree with other lib using pods. My build is failed because it can't find library for Braintree. Here's what I have:
ld: library not found for -lBraintree
clang error: linker command failed with exit code 1 (use -v to see
invocation)
Things I've tried:
Used .xcworkspace instead of .xcodeproj
Set build active architecture NO
Removed any red lib.a
This is what my project looks like:
I don't see a -lBraintree flag in the last picture yet it shows here -ObjC -ObjC -l"AdIdAccessLibrary" -l"Braintree" -l"DI... why?
Podfile
target 'MyProject' do
pod 'Braintree', '3.9.3'
pod 'Google/Analytics', '~> 1.0.0'
pod 'GoogleIDFASupport'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'
pod 'GoogleMaps'
end
target 'MyProjectTests' do
end

Pods library is linked twice with first target, as libPods.a and libPods-<targetname>.a

I have the project, that contains two targets one for iOS and one for OSX.
Here's how the Podfile looks like.
# Pods
xcodeproj 'ipolypus.xcodeproj'
pod 'BlocksKit'
pod 'Reachability'
pod 'MKStoreKit'
# Objective C
pod 'libextobjc'
pod 'LinqToObjectiveC'
target :ipolypus, :exclusive => false do
platform :ios, '5.1.1'
pod 'CocoaLumberjack'
pod 'EGOTableViewPullRefresh'
pod 'SVProgressHUD'
pod 'FlurrySDK'
# AdMob SDK and AdMob mediation adapter
pod 'AdMob'
pod 'AdMobMediationAdapterIAd'
end
target :ipolypusTests, :exclusive => true do
pod 'CocoaLumberjack'
end
target :'ipolypus-osx', :exclusive => false do
platform :osx
pod 'CocoaLumberjack'
end
After running pod install I can see that two Pods libraries are linked against the first target (ipolypus).
libPods.a and libPods-ipolypus.a
If I try to build the project right away, I will get strange link errors, like missing FlurrySDK symbols.
To fix it, I have to remove libPods.a and libPods-ipolypus.a from the list of libraries to link with the target, run pod install again, then manually remove libPods.a for the first target and then it will build and link.
There must be something wrong with the way I make that Podfile. I checked related posts, couldn't find similar problem.
Update
Here's the link error
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_Flurry", referenced from:
objc-class-ref in IOSAppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
After I do the steps described above, I will have successful builds until next pod install or pod update.
I should also mention, that the project had single target for quite a while, then I added OSX target and modified Podfile for that, and that's when the problems started.
But I tried to remove Podfile.lock and to wipe Pods folder, still the problem occurs.
And I had another type of error, where linker failed because the same symbol was already defined, but I don't see that one anymore.
I got to the cause of "double-linking" problem.
It's caused by the structure of the Podfile, as expected.
Since I wanted to have some common pods available both for OSX and iOS targets, I put them all in the beginning.
xcodeproj 'ipolypus.xcodeproj'
pod 'BlocksKit'
pod 'Reachability'
pod 'MKStoreKit'
# Objective C
pod 'libextobjc'
pod 'LinqToObjectiveC'
These common pods will be in libPods.a library, also, CocoaPods can't stand the fact that some pods library is not linked against a target, so it will link libPods.a against default project target, in my example it's ipolypus.
Then there's libPods-ipolypus.a generated for ipolypus iOS target. Since this target is not exclusive, things like FlurrySDK will be included into both libPods.a and libPods-ipolypus.a, resulting into duplicated symbols while linking.
After trying to figure out the proper way to use exclusive/non-exclusive target configs, I ended up with separate list of pods for each target. Might be a bit longer than I would want, but does the job as expected.
# Pods
xcodeproj 'ipolypus.xcodeproj'
target :ios, :exclusive => true do
platform :ios, '6.0'
link_with 'ipolypus'
# shared
pod 'CocoaLumberjack'
pod 'Reachability'
pod 'MKStoreKit'
pod 'LinqToObjectiveC'
# pod 'EGOTableViewPullRefresh'
# platform
pod 'SVProgressHUD'
pod 'FlurrySDK'
# AdMob SDK and AdMob mediation adapter
pod 'Google-Mobile-Ads-SDK'
pod 'AdMobMediationAdapterIAd'
end
target :iosTests, :exclusive => true do
platform :ios, '6.0'
link_with 'ipolypusTests'
pod 'OCMock'
end
target :osx, :exclusive => false do
platform :osx, '10.7'
link_with 'ipolypus-osx'
# shared
pod 'CocoaLumberjack'
pod 'Reachability'
pod 'LinqToObjectiveC'
end
target :osxTests, :exclusive => true do
platform :osx, '10.7'
link_with 'ipolypus-osxTests'
pod 'OCMock'
end

Resources