How can you use cocoapod framework into another cocoapod created locally? - ios

Specifically:
Created a new project
Setup CocoaPods
To the Pod file under Pods I added a dependency (for ex.AlamoFire)
The main app which consumes the pods can import Alamofire
The local cocoapod which I created and added by using the following lines in the podfile:
target 'SomeValue' do
my_own_pod
pod 'CocoaPod_2', :path => '/LocalPath/To/PodSource'
end
Ran pod install and I added the AlamoFire Framework to the CocoaPod_2 under Pods -> General-> CocoaPod_2-> Linked Libraries & Binaries
At this point I was expecting that importing Alamofire in my CocoaPod_2 will work fine but its not.
Screenshot of the workspace :
MyProject.XCWorkspace
|_MyProject.App
|____Source Code files importing CocoaPod_1 (Embedded using CocoaPod)
|____Source Code files importing CocoaPod_2 (Embedded using CocoaPods, local Pod)
|_Pods
|____Podfile
|____Frameworks
|____Pods
|___CocoaPod_1
|___CocoaPod_1 Source Files
|____Source Code for Local Pod
|___CocoaPod_2
|____File contains statement (import cocoapod_1) <---Gives error ld: framework not found

You need to do the following two additional things:
You need to add a Podfile in your CocoaPod_2 followed by a pod install.
Also, you need to define a CocoaPod_2.podspec file in your CocoaPod_2
folder.
If you add Alamofire in both the Podfile and podspec file of CocoaPod_2, you don't need to add in the main app's Podfile. Only adding CocoaPod_2 entry in the app's Podfile will suffice.
I hope that helps!

Related

How to link a cocoapods cordova plugin src to a .framework header file when there's multiple xcode projects in the workspace?

The unique situation is that this is an Ionic app that pulls in the uncompiled plugin source via pods. The problem is that when compiling, the plugin headers and implementation can't find the .framework's headers/implementation. The demo Cordova app finds the .framework, but they're only in a single project.
I've tried all the suggestions for "header file not found".
Adding the .framework to the linked libraries of either the pods project or the app project
Adding search paths to every target, every app (and combinations thereof)
Adding a linked binary
Adding headers/sources to build phases
add s.vendored_frameworks = 'ValidicMobile.framework to the podspec and doing pod update
What might be the next thing to try? Would wrapping the vendor .framework in a cocoapod help the plugin find the framework, assuming pods would be better at linking? The plugin requires the import of the other Cordova frameworks in the pods, so not sure if I can put the src directly in the main app or not.
I'm not sure if it's applicable for your scenario, but way back I did post processing of the PCH file for one of my pods in the podfile.
platform :ios, '7.0'
pod 'A','7.4.1'
pod 'B', '0.3.1-beta2'
pod 'C', '0.6.5'
post_install do | installer |
print "Updating #{installer.sandbox.target_support_files_root}/Pods-A/A.pch\n"
open("#{installer.sandbox.target_support_files_root}/Pods-A/A.pch","a") do |file|
file.puts <<EOF
//your extra stuff goes here
#import "../../../A/Hacks/someExtraHeader1.h"
#import "../../../A/Hacks/someExtraHeader2.h"
EOF
end
end
That allowed me to inject extra header imports on pod level during pod install after all the sources of the pods have already been checked out.

ld: framework not found IDZSwiftCommonCrypto

I have installed the pod libcommoncrypto, the path is
<project>/Pods/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/*.swift files
I fail to understand why Xcode is not able to find a framework installed by the pod.
Edit (Podfile)
source 'https://github.com/CocoaPods/Specs.git'
project 'myproject.xcodeproj'
target 'myproject' do
use_frameworks!
pod 'Toaster'
pod 'libCommonCrypto'
end
Edit : CommonCrypto not found
You apparently have IDZCSwiftCommonCrypto and Toaster as explicit entries in your "Linked Frameworks and Libraries", not as part of you cocoapods. Remove those two and try again, these should be added to your app only via Pods_SwiftCommons.framework that cocoapods creates for you.
Also: pod 'libCommonCrypto' does not create any files named IDZSwiftCommonCrypto at all, instead I find Pods/libCommonCrypto/CommonCrypto.{h,swift}, as I would expect. IDZSwiftCommonCrypto is another pod, unrelated to libCommonCrypto, if you still have those files I'd recommend cleaning your your Pods directory and running pod update again.

No Such Module Found adding dependency in Podspec

I am creating a framework in iOS Using Swift. I have created the podspec file and put the dependency of googlemap in my framework.
When I am trying to install the my framework in sample application,It shows "No Such Module Find" for "GooogleMaps". Please let me how to link google maps in my framework so any application when install my cocoapod will automatically get GoogleMaps without any error.
If you have created a pod and in your .podspec file you are trying to add a dependency (like Alamofire, RealmSwift..) after that you should go to the Example/.. folder and do a pod install to make the dependencies required from the .podspec of your custom pod visible to the .swift files in your custom pod/framework.
A typical example of a pod project folder hierarchy would be:
- SMCustomPod/
- _Pods.xcodeproj
- Example/ // <-- do a pod install under this folder in order to get the dependencies declared in your .podspec
- Podfile
- SMCustomPod.xcodeproj
- SMCustomPod.xcworkspace
- SMCustomPod/
- Classes/ // <-- folder with pod specific logic that also uses Alamofire
- Assets/
- SMCustomPod.podspec // <-- your podspec with dependencies (Alamofire..)
First off try to clean the project by
Command + Shift + Options + K
If I'm not mistaken, GoogleMaps framework is built from Objective-C so if there's still a problem then do the following steps:
Create a bridging header file which you can trigger and setup automatically by creating a dummy Objective-C class in your Swift project. Xcode will then ask you if you would want to create a bridging header, click yes. Delete the dummy class you created after.
Configure the header search path to point the Pods with recursion
Do a clean-build.
try this :-
Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'Circle' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Circle --------->>>>>>>>>. Your Project name
pod 'GoogleMaps'
pod 'GooglePlaces'
end

Pod install doesn't download frameworks

I'm using switf and pods. When i type 'pod install' on my terminal, Instead of having the frameworks downloaded to my project, i get the files.
This makes no difference to me, except for the fact that when i want to import them in my project, i always get an error saying they can't be found.
Here is my pod file
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
use_frameworks!
target 'Project' do
pod 'MSSTabbedPageViewController'
pod 'PageMenu'
end
As ocarol stated, import the framework. However, before importing at the top of the file you want to use the framework, build the project, as Xcode seems to not link the pod's to the project automatically.
Also open the .xcworkspace file that pod install generates.
You use these libraries as frameworks (use_frameworks!). So you have to import the framework at the top of the Swift file, like:
import MSSTabbedPageViewController
if had created a bridging header file, you can import the framework in it.

Creating a pod that relies on another pod

Trying to build a Cocoapod library which is dependant of other published Cocoapod library I own, got the project in XCode to build OK, but running pod lib lint command for checking pod validity fails with
error: include of non-modular header inside framework module on the header files of the library (pod) I'm depending on. All source is Obj-C not Swift.
I did try the following, according to the recommendations found here
Setting the header files of the dependant library as public instead of project
Setting CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES =
YES for each target
verifying that the relevant headers in build phases are under public.
but problem persists, I cannot publish the pod nor test it.
Update
when I comment out the
s.dependency 'OldPodIDependOn'
line in my podspec file of my new pod then error disappears but the dependent headers are not found. if I do not include the pod I depend on in the Podfile under the ./Example folder, like so:
target 'NewPod', :exclusive => true do
pod "NewPod", :path => "../"
pod "OldPodIDependOn", :path => "../../OldPodIDependOn/"
end
then project will just not build in XCode since the OldPodIDependOn files are not part of the project. Got a bit of a chicken-or-the-egg problem.
Update 2
Also tried removing the :path => "../../OldPodIDependOn/" component to reference the pod that has been published instead of a local one - doesn't help.
Worth mentioning that this pod will include a UI hence a storyboard will be included and referenced, I added s.resources = 'Pod/Classes/UI/NewPod.storyboard' line to the podspec file, and removed the storyboard from the pod target compile sources (otherwise xcode won't build). I don't think that this has something to do with the problem but worth mentioning, maybe I'm doing something wrong in there.
What am I doing wrong?
Any help will be greatly appreciated!
To finally solve this issue I had to discard the workspace that pob lib create created - there was no way around it, I tried all possible combinations / recommendations / code modifications to get rid of the "non-modular header inside framework" errors but nothing seemed to work. pod lib lint ALWAYS failed.
I created my own static library xcode project from scratch, then run pod update on it after adding the dependent pod to the Podfile, then created a .podspec file for this lib and added the dependant pod header files to the "Copy files" build phase of the static lib target + libPods.a file to the "Link Binary with libs" build phase. Poof! no more "non modular header" errors from pod lib lint, even though I am practically doing the exact same thing. Lesson learnt is that pod lib create is not recommended for ALL cocoapod cases.
I had the same issue, and I used
pod lib lint MyPod.podspec --allow-warnings --use-libraries
When adding the --use-libraries option, it worked.
In general error: include of non-modular header inside framework module implies that one of the header files inside the resulting framework ( CocoaPods lints for both frameworks and libraries now ) is not stored inside the framework, or classed as a public header.
This can usually be worked around moving external imports into the implementation files, see this Modified to support using framework #353.

Resources