Multiple projects and Cocoapods - ios

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

Related

Share dependencies across frameworks with CocoaPods without duplicating classes' definitions

I currently have 2 deployable frameworks. Same app, two faces: Client and Vendor.
Most of the data-model classes and some views are completely identical. So I've created another framework named "Common". I had no problem using Common as a dependency for Client and Vendor frameworks until Firebase and Crashlytics appeared.
I have some code that again, would be identical in both frameworks. So Common is the way I wanted to go. But, when using Cocoapods, there will be two definitions of those libraries, Xcode log says Class <<SomeFirebaseClass>> is implemented in both <<LONG CLIENT PATH>> and <<LONG COMMON PATH>>. One of the two will be used. Which one is undefined. and this issue occurs.
My Pod File:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
workspace 'Application'
use_frameworks!
# ignore all warnings from all pods
inhibit_all_warnings!
abstract_target 'CommonPods' do
pod 'ChameleonFramework/Swift'
pod 'Fabric'
pod 'Crashlytics'
pod 'Alamofire', '~> 4.5'
pod 'SwiftyJSON'
pod 'Firebase/Core'
pod 'Firebase/Auth'
target 'Attendant' do
project 'Attendant/Attendant'
end
target 'Client' do
project 'Client/Client'
end
end
I've found some issues in the CocoaPods's repository somehow related but no fix so far.
My question here is: How can I accomplish this? And if I can't, what is the best way to achieve something close to this?

Setting up cocoa pods with a react native project

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 file, and it made another project in my workspace

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.

Import a workspace with pod in a other similar worskspace in Xcode

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

Manage dependencies of multiple projects in a single workspace

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

Resources