I have a workspace set like this:
MyAppiOS project
MyAppMacOS project
Pods
AFNetworking
Pods project was added to the initial workspace (MyAppiOS project) with the podfile
platform :ios, '5.0'
pod 'AFNetworking', '1.1'
and the pod install command
Now I woud like MyAppMacOS to also link with AFNetworking.
I have seen example of podfiles with multiple targets, but with a common platform. I could not find an example of podfile that would work with multiple platforms.
I also tried using two podfiles for the two projects, but a pod install command creates two workspaces.
What is the best way to use CocoaPods in that scenario?
How about
MyAppiOS project with folder
Pods
AFNetworking
MyAppMacOS project with folder
Pods
AFNetworking
MyAppCommon folder
You can still add files from MyAppCommon in the platform specific projects.
Try something like this, where you specify the workspace that should be created, and the platform for each target/project combination. You can adjust the project files to point to different folders where each platform's source is located.
workspace 'MyWorkspace.xcworkspace'
platform :ios
def import_pods
pod 'AFNetworking'
end
target :'MyAppiOS' do
platform :ios
xcodeproj 'MyAppiOS.xcodeproj'
import_pods
end
target :'MyAppOSX' do
platform :osx
xcodeproj 'MyAppOSX.xcodeproj'
import_pods
end
Related
I am trying to create a Dynamic Framework to share the code among various extensions of my app.
Problem :
Here is my project structure.
MyFrameworks is a network layer of my app which inherently uses Alamofire. So structured my pod file as follow.
platform :ios, '9.0'
use_frameworks!
workspace 'CocoaPodsProjectworkspace'
def shared_pods
pod 'Alamofire'
pod 'SwiftyJSON'
end
target 'CocoaPodsProject' do
project 'CocoaPodsProject.xcodeproj'
# Pods for CocoaPodsProject
end
target 'MyFramework' do
project 'MyFramework/MyFramework.xcodeproj'
shared_pods
end
target 'CocoaPodsProjectTests' do
end
target 'CocoaPodsProjectUITests' do
end
On building the framework when I drag it as embedded binary to my Main project I get the error.
dyld: Library not loaded: .framework/Alamofire Referenced from:
/Users/sandeep/Library/Developer/Xcode/DerivedData/CocoaPodsProjectworkspace-enpobdyluhbxdwazuvbfogcspfof/Build/Products/Debug-iphonesimulator/MyFramework.framework/MyFramework
Reason: image not found
Solutions I tried :
Declaring the pods_frameworks.framework as optional in linked
binaries.
Tried changing RunPath Search path of framework Dynamic Library
Install name Running pod deintegrate and running pod install again.
Deleting derived data and relinking framework all lead to same
problem.
Solution that worked :
I realized that MyFramework.framework was trying to find the Alamofire.framework in a wrong directory and it was alway trying to search relative to project/target using the framework . So the simplest solution that I could find was to modify pod file as follow.
platform :ios, '9.0'
use_frameworks!
workspace 'CocoaPodsProjectworkspace'
def shared_pods
pod 'Alamofire'
pod 'SwiftyJSON'
end
target 'CocoaPodsProject' do
project 'CocoaPodsProject.xcodeproj'
shared_pods
# Pods for CocoaPodsProject
end
target 'MyFramework' do
project 'MyFramework/MyFramework.xcodeproj'
shared_pods
end
target 'CocoaPodsProjectTests' do
end
target 'CocoaPodsProjectUITests' do
end
As you can see I added the shared_pods to both main app and my framework project and their respective targets. Now everything works smooth. I neither had to make pods_framework optional nor had to modify the build settings of MyFramework.
Question:
Adding the shared repos to all the projects and their targets which wants to use my framework looks little redundant. Is there a better way I can specify Myframework.framework to read all its dependencies rather than reading from project using it?
I have raised a issue for the same on CocoaPods Git repo. But because it isn't inherently a issue they might not revert back. Hence posting it as a question here.Link to issue : https://github.com/CocoaPods/CocoaPods/issues/6901 if it helps.
Solved it by creating a cocoa pod for my custom Framework and using cocoa pods dependency .
Step 1 : Clean the Main/Parent project
Removed MyFramework from the project (which was added as sub
project) and remove MyFramework.framework added in embedded library of projects General settings.
Run pod deintegrate (to de-integrate the pod already added to
project)
Now that the project is clean and does not have any pod added
initialized the pod by running pod init
Step 2: Create a Pod for my Framework
Using cd command navigate to MyFramework project and once you are in
MyFramework's root folder run pod spec create MyFramework
This will create a file named MyFramework.podspec in the
MyFramework's root folder. Open MyFramework.podspec using any of the
editor tool and update it as shown in tutorial https://www.raywenderlich.com/126365/ios-frameworks-tutorial
Most important step which is not there in this tutorial is how to add
cocoa pods dependency that our framework needs to build. Turns out
thats the most easiest part. In my case I needed SwiftyJSON and
Alamofire so in .podspec file I added,
s.dependency 'Alamofire'
s.dependency 'SwiftyJSON'
Step 3:
Now open the Main/Parent projects Podfile and update it as shown
below.
target 'CocoaPodsProject' do
use_frameworks!
pod 'TestFramework', :path => 'TestFramework/'
end
What it did is, it tells main project to add TestFramework as dependency and installs TestFramework in Framework folder of main project. Because TestFramework in itself has dependency to Alamofire & SwiftyJSON when you run pod install it will not only install Alamofire but also installs SwiftyJSON and adds it to TestFramework's Framework folder.
Thats all. Now your TestFramework can access Alamofire and SwiftyJSON and Main/Patent project can access TestFramework
If you want to now update TestFramework code, till u finish develop add it as subproject to Main project (This is necessary because if you open TestFramework.xcproj u won't see Alamofire/Swifty JSON. You have to open the Parent project's workspace itself hence this solution). Once u are done with development if u decide to remove the TestFramework as subproject u can do that :)
Finally If you decide to add additional extensions to app, Lets say u add Today extension all u have to do is to modify ur Podfile as follow.
target 'CocoaPodsProject' do
use_frameworks!
pod 'TestFramework', :path => 'TestFramework/'
end
target 'CocoapodsToday' do
use_frameworks!
pod 'TestFramework', :path => 'TestFramework/'
end
Woo hooo :) Now add your frameworks to as many extensions you want :) Hope it helps.
I've set up a fresh react native project, and instantiated a cocoa pod .xcworkspace doing:
cd ios
pod init
pod install
I've then added a pod that I want to use (in this case being Buddybuild, although it doesn't really matter which pod i add, as the behavior is similar)
After I run pod install and include the header #import <BuddyBuildSDK/BuddyBuildSDK.h> in my AppDelegate.m , it is always returning me a /Users/nik/dev/myproject/ios/myproject/AppDelegate.m:14:9: 'BuddyBuildSDK/BuddyBuildSDK.h' file not found
I've battled with this all day and I have no idea why. The headers are all there in the Pods/headers/Public folder. They're being included in the header search paths in build settings as well as you can see here:
I'd highly appreciate help on this as I'm very stuck.
EDIT Also here's my Podfile:
Turns out the issue was an xcode thing. After much Googling the issue that solved it was making sure that my projects configurations were properly set. So going to Project -> Info -> Configurations And choosing the right Pods-projectName.debug and Pods-projectName.release configurations.
For RN 0.58.6 I noticed you don't need any react or react-native pods.
If you create a brand new project using react-native init (for 0.58.6) you will notice there is no need for a pod file.
My pod file looks like this:
platform :ios, '9.0'
project 'MyRNProject.xcodeproj'
install! 'cocoapods', :deterministic_uuids => false
target 'MyRNProject' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Add pods that you need here
target 'MyRNProject' do
inherit! :search_paths
# Pods for testing
end
end
In Project target Linked framework or libraries I have:
framework deps (CoreFoundation.framework, SystemConfiguration.framework Pods_MyRNProject.framework etc)
RCT and RN deps
other libs that I use
I added pods to an existing workspace and now I have 2 of the same project in my workspace (Both projects ending in IOS). If I delete either one, I lose all references to the project.
Here is what the project tree looks like and the pods file. Anyone have any insight?
This is how the podfile should be
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'Demo8' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'FBSDKCoreKit', '~> 4.16'
end
This is no requirement to specify workspace externally until there is any requirements.
I built 2 swift projects. Both use CocoaPod, so these projects are workspaces.
The first one is like a framework with a lot of Classes I use in the second one.
I don't succeed in this importation:
I followed those steps from the Apple Docs , but any Classes from my Framework (1st project) are recognized... I have 80 error like this :
Use of undeclared type < MyFrameworkClass >
I know two options for setting up a workspace with multiple pods.
You can create a single podfile for both projects. As you can imagine, it will create a single workspace where your two projects (app and framework) will be at (let's cocoapods take care of the entire workspace).
The pod file will look like this:
platform :ios, '8.0'
use_frameworks!
workspace 'WorkspaceName’
xcodeproj ‘FolderOfApp/Project.xcodeproj'
xcodeproj ‘FolderOfApp/App.xcodeproj'
target :ApptTarget do
xcodeproj 'FolderOfApp/App.xcodeproj'
pod ‘MyAppPod’
end
target :FrameworkTarget do
xcodeproj 'FolderOfFramework/Framework.xcodeproj
pod ‘MyFrameworkPod’
end
You will probably need to add the "MyFrameworkPod" to the AppTarget too, and this bring some warnings that I still couldn't solve.
Anyway, you have another option that I was using before. Create and execute the two pod files as you are doing now, create another workspace, add the two projects and the two pods (separate them with folders). DONT ADD THE WORKSPACES, just the projects.
With this approach I had a feel problems like the app not finding the frameworks dependencies, but I solved adding the framework search path.
Swift 5 Very easy solution in your POD File
in your directory : touch Podfile (file will create in workspace)
# platform :ios, '10.0'
use_frameworks!
workspace 'TestWorkSpace'
xcodeproj 'Project1/Project1.xcodeproj'
xcodeproj 'Project2/Project2.xcodeproj'
target 'Project1' do
xcodeproj 'Project1/Project1.xcodeproj'
#Pods for Project1
pod 'SwiftyJSON', '~> 4.0'
end
target 'Project2' do
xcodeproj 'Project2/Project2.xcodeproj'
#Pods for Project2
pod 'SwiftyJSON', '~> 4.0'
end
I want to have a Workspace that contains two projects (2 different apps), a Common (shared) project and a couple of Pods.
I have been struggling to get the App1 project to "see" the Common classes.
My thinking was:
Create the workspace
Create the two app projects (App1 and App2)
Create the Common project
Create Podfile
The Podfile I have is along the lines of this:
workspace 'MyApps'
xcodeproj 'App1/App1.xcodeproj'
xcodeproj 'App2/App2.xcodeproj'
xcodeproj 'Common/Common.xcodeproj'
target :App1 do
platform :ios, '6.0'
pod 'AFNetworking', '~> 1.3.2'
xcodeproj 'App1/App1.xcodeproj'
end
target :App2 do
platform :ios, '6.0'
pod 'AFNetworking', '~> 1.3.2'
xcodeproj 'App2/App2.xcodeproj'
end
target :Common do
platform :ios, '6.0'
pod 'AFNetworking', '~> 1.3.2'
xcodeproj 'Common/Common.xcodeproj'
end
I have seen this question but I can't seem to get the Common code to be available in the Apps.
Do I have to manually update the search paths for each of the Apps projects to make it work or can this be solved via the Podfile?
i had a similar problem at work, and i found it was better to change the project structure to work with Cocoapods.
i think the right solution for you, or at least the right path to one, is to turn your common project into a local (see "Using the files from a local path" here), private pod.
i implemented my common project as such, and have my Application project also configured with CocoaPods, using that private pod.
a final word of note, when building a common library project through CocoaPods, you'll want to override the 'Other Linker Flags' build setting in that project, just like it is in the Pods project created and managed by CocoaPods.
¡let me know if this works for you!
I have just posted an answer on this topic in the context of multiple targets - should apply to multiple projects to: Multiple targets depending on same cocoapods