Headers not found when referencing CocoaPods project from Swift - ios

I would like to include iOS-WebP as a pod to my Swift project.
The pod spec reads
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'iOS-WebP', '0.4'
In Swift, I use import iOS_WebP to use the library.
However, compilation fails with the relative header paths inside the library not resolving correctly:
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "/Users/.../Products/Debug-iphoneos/Pods/iOS_WebP.framework/Headers/Pods-iOS-WebP-umbrella.h"
^
/Users/.../Build/Products/Debug-iphoneos/Pods/iOS_WebP.framework/Headers/Pods-iOS-WebP-umbrella.h:3:9: note: in file included from /Users/.../Build/Products/Debug-iphoneos/Pods/iOS_WebP.framework/Headers/Pods-iOS-WebP-umbrella.h:3:
#import "UIImage+WebP.h"
^
/Users/.../Build/Products/Debug-iphoneos/Pods/iOS_WebP.framework/Headers/UIImage+WebP.h:10:9: error: 'WebP/decode.h' file not found
#import <WebP/decode.h>
^
/Users/...ViewController.swift:3:8: error: could not build Objective-C module 'iOS_WebP'
import iOS_WebP
^
Building the library standalone via the scheme switcher works fine, it's only the integration into the Swift project that fails.
Cleaning DerivedData did not help, and the .xcconfig properly references the library both in OTHER_CFLAGS and OTHER_LDFLAGS.
Update
It works if I remove use_frameworks! and include the library via the ObjC Bridging header. Is there a way to disable use_frameworks! for a single pod?
Update 2
With this pod file, it compiles.
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
xcodeproj 'xxx'
target "Frameworks", :exclusive => true do
link_with "xxx"
use_frameworks!
pod ....
end
target "StaticLibraries", :exclusive => true do
link_with "xxx"
pod 'iOS-WebP', '0.4'
end
Problem is that now when I launch the app, it doesn't seem to find the frameworks:
dyld: Library not loaded: #rpath/XXX.framework/XXX
Referenced from: /private/var/mobile/Containers/Bundle/Application/...
Reason: image not found
(lldb)

Related

CocoaPods: can my framework depend on other frameworks?

I'm creating a framework called MyFramework. This framework depends on ZipFoundation.
In order to test MyFramework I've created a new target application called MyFrameworkShowcase.
The workspace looks like the following:
MyFramework.xcworkspace
MyFramework.xcodeproj
MyFramework
MyFrameworkShowcase
Pods.xcodeproj
The Podfile looks like the following:
platform :ios, '11.0'
target 'MyFramework' do
use_frameworks!
pod 'ZIPFoundation', '~> 0.9'
end
target 'MyFrameworkShowcase' do
use_frameworks!
end
Running the showcase app I receive the following error:
dyld: Library not loaded: #rpath/ZIPFoundation.framework/ZIPFoundation
Any way I can adjust the Podfile in order to fix this issue?

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

How to use cocoapod to include shared framework for both ios app and watch extension

I tried to use one framework (Realm.framework) for both of my ios app and ios watch kit.
I tried many ways, none of them work. Could anyone give me an example of how to write a pod file to share a framework between ios app and watch app?
With out any watch extension target in pod file, I got an error saying:
Target 'Realm' of project 'Pods' was rejected as an implicit dependency for 'Realm.framework' because it doesn't contain platform 'watchsimulator' in its SUPPORTED_PLATFORMS 'iphonesimulator, iphoneos'
Target 'RealmSwift' of project 'Pods' was rejected as an implicit dependency for 'RealmSwift.framework' because it doesn't contain platform 'watchsimulator' in its SUPPORTED_PLATFORMS 'iphonesimulator, iphoneos'
Target 'Pods' of project 'Pods' was rejected as an implicit dependency for 'Pods.framework' because it doesn't contain platform 'watchsimulator' in its SUPPORTED_PLATFORMS 'iphonesimulator, iphoneos'
Then I added target for watch extension to my pod file. Here is my pod file:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
link_with 'myApp', 'myApp Watch Extension'
def shared_pods
pod 'RealmSwift'
end
target 'myApp' do
podspec :path => 'myapp.podspec'
pod 'SnapKit'
pod 'ChameleonFramework/Swift'
pod 'Google-Mobile-Ads-SDK'
shared_pods
end
target 'myApp Watch Extension' do
podspec :path => 'myapp.podspec'
platform :watchos, '2.0'
shared_pods
end
I got it run with warnings with "pod install", but my workspace failed to run.
2015-12-07 15:45:46.402 ruby[17042:4339468] warning: The file reference for "Realm.framework" is a member of multiple groups ("Products" and "Products"); this indicates a malformed project. Only the membership in one of the groups will be preserved (but membership in targets will be unaffected). If you want a reference to the same file in more than one group, please add another reference to the same path.
2015-12-07 15:45:46.402 ruby[17042:4339468] warning: The file reference for "RealmSwift.framework" is a member of multiple groups ("Products" and "Products"); this indicates a malformed project. Only the membership in one of the groups will be preserved (but membership in targets will be unaffected). If you want a reference to the same file in more than one group, please add another reference to the same path.
There are so many errors in my Pods-myApp Watch Extension-Realm file.
I also tried pod file like:
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
link_with 'myApp', 'myApp Watch Extension'
def shared_pods
pod 'RealmSwift'
end
target 'myApp' do
podspec :path => 'myapp.podspec'
platform :ios, '8.0'
pod 'SnapKit'
pod 'ChameleonFramework/Swift'
pod 'Google-Mobile-Ads-SDK'
shared_pods
end
target 'myApp Watch Extension' do
podspec :path => 'myapp.podspec'
platform :watchos, '2.0'
shared_pods
end
Then I got "[!] Targets with different platforms" error.
In my podspec, I already added lines:
s.platform = :ios
s.platform = :ios, "8.0"
s.platform = :watchos
s.platform = :watchos, "2.0"
Could anyone show me how it should be done?
The warnings, you saw, after running pod install shouldn't appear and are definitively a bug in CocoaPods / Xcodeproj. That seems to be related to the UUID generation and the warning you might have seen about that as well:
[!] [Xcodeproj] Generated duplicate UUIDs:
…
You have two target specific dependency definition groups in your Podfile.
You can't link to the implicit root target in the Podfile to both your app and its extension as their are on different platforms. That means you have to remove the 3rd/4th line:
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
#link_with 'myApp', 'myApp Watch Extension' # <= REMOVE this line.
…
I can't reproduce the error you're seeing in Xcode about the rejection of targets as implicit dependencies. As I don't have your podspec, I can't reproduce it exactly, but from what I see it shouldn't matter as long as your podspec doesn't declare any dependencies.
Beside that, it is sufficient to declare the platform availability by just those two lines in the podspec:
s.platform = :ios, "8.0"
s.platform = :watchos, "2.0"

ParseFacebookUtilsV4 duplicate symbols for architecture armv7

I cannot compile my Xcode project, it has problems with duplicate ParseFacebookUtilsV4
this is my apple Mach-O Linker Error:
duplicate symbol _llvm.cmdline in:
/directory/Pods/ParseFacebookUtilsV4/libParseFacebookUtilsV4Lib.a(PFFacebookAuthenticationProvider.o)
/directory/Pods/ParseFacebookUtilsV4/libParseFacebookUtilsV4Lib.a(PFFacebookUtils.o)
duplicate symbol _llvm.embedded.module in:
/directory/Pods/ParseFacebookUtilsV4/libParseFacebookUtilsV4Lib.a(PFFacebookAuthenticationProvider.o)
/directory/Pods/ParseFacebookUtilsV4/libParseFacebookUtilsV4Lib.a(PFFacebookUtils.o)
ld: 2 duplicate symbols for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've imported ParseFacebookUtilsV4 with cocoapods, here is my Podfile:
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
use_frameworks!
target 'ZZZ' do
pod 'Parse'
pod 'FBSDKCoreKit', '4.3.0'
pod 'FBSDKLoginKit', '4.3.0'
pod 'ParseFacebookUtilsV4'
end
target 'ZZZTests' do
end
And here is my bridging header:
#ifndef FarThings_FarThings_Bridging_Header_h
#define FarThings_FarThings_Bridging_Header_h
#import <Parse/Parse.h>
#import <ParseFacebookUtilsV4/PFFacebookUtilsV4.h>
#import "FBSDKCoreKit.h"
#import "FBSDKLoginKit.h"
#import <Bolts/BFTask.h>
#endif
I hit this before, In my case I upgrade from old version and here's how I fix it. (Main idea is cleanup everything before pod)
Remove all old Parse, Bolt and Facebook related (all .framework lookup path and embed .framework) until you end up with unknown class.
Remove all .framework form folder via finder.
Clean up your build folder by 'alt+clean' via Xcode.
Delete all Pod related include all Pod folder via finder.
try pod install one by one (or all at one if you feeling brave) until it look like this.
pod 'Parse'
pod 'ParseFacebookUtilsV4'
pod 'ParseCrashReporting'
and some other pod you need after that.
It work for me, just make sure you remove all related.
You can this pod with new project to prove this work before trying with real project.

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