First of all, I've turned on use_framework! in Podfile.
Assume the main project is MAIN_APP, and two subprojects are FRAMEWORK_A and FRAMEWORK_B.
MAIN_APP requires FRAMEWORK_A and FRAMEWORK_B, and FRAMEWORK_B requires FRAMEWORK_A as well.
All projects/targets are using CocoaPods to manage third party libraries.
For now, my Podfile looks like:
target :MAIN_APP do
project 'MAIN_APP'
pod 'PodA'
end
target :FRAMEWORK_A do
project 'FRAMEWORK_A'
pod 'PodB'
end
target :FRAMEWORK_B do
project 'FRAMEWORK_B'
pod 'PodC'
end
I manually added FRAMEWORK_A to build settings of FRAMEWORK_B, and both FRAMEWORK_A and FRAMEWORK_B to build settings of MAIN_APP.
All code compiles well, but when running the MAIN_APP crashes because it cannot load Framework of PodB.
I know I can manually add PodB to MAIN_APP and FRAMEWORK_B as well, but is it possible to define this kind of target dependency in Podfile?
Btw, when pod install, I got the warning:
[!] The Podfile contains framework targets, for which the Podfile does not contain host targets (targets which embed the framework).
If this project is for doing framework development, you can ignore this message. Otherwise, add a target to the Podfile that embeds these frameworks to make this message go away (e.g. a test target).
As I know, I can use nested target for host targets like:
target :FRAMEWORK_A
target :MAIN_APP
end
end
So CocoaPods will setup MAIN_APP to use FRAMEWORK_A and inherit pod dependencies from FRAMEWORK_A. But seems I cannot do it with multiple dependencies like:
target :FRAMEWORK_A
target :MAIN_APP
end
end
target :FRAMEWORK_B
target :MAIN_APP
end
end
Because target :MAIN_APP cannot be declared twice.
Is there any better solutions instead of defining pod dependencies as a function in Podfile and include in all target?
This is a great question and I've struggled with a similar situation. This is my PodFile:
platform :ios, '8.0'
workspace 'mygreatapp.xcworkspace'
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
abstract_target 'This can say whatever you want' do
target 'MyGreatApp' do
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
pod 'AFNetworking', '~> 2.6.0'
pod 'PromiseKit', '~> 1.5'
pod 'PromiseKit/Join'
pod 'KVOController', '~> 1.0'
pod 'FLAnimatedImage', '~> 1.0'
pod 'Crashlytics', '~> 3.3'
pod 'SSZipArchive'
end
target 'MyGreatAppTests' do
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
pod 'OCMock', '~> 3.1'
end
target 'MyGreatFramework' do
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
pod 'SSZipArchive'
end
target 'MyGreatFrameworkTests' do
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
pod 'OCMock', '~> 3.1'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
end
As you can see I'm not using frameworks and I use an abstract_target to group it all together. I wish these kinds of dependencies were easier to do in CocoaPods. I know this doesn't really answer your question but it might be helpful nonetheless.
I think you can also get around this by just making FrameworkA and FrameworkB into local (static library) pods and it will de-duplicate everything for you and integrate it into the host app properly.
Examples: https://github.com/rob-keepsafe/PodFrameworksIssue
master branch shows duplicate classes and umbrella frameworks like you have
deduped branch makes the internal dynamic frameworks into local pods (as static libs) to de-dupe and still link in the dependencies
I'm not entirely sure your issue is the same as mine, but I'm going to leave my solution here just-in-case someone has a similar issue.
I have a project with multiple sub-projects I use to modularize my code (and potentially prepare to extract to my own private pods).
I had the issue of one importing an external pod to one of the sub-projects, and receiving a dyld error due to a "missing image".
I found this Medium article from which I concluded that I had to always include the pods in the main project for the sub-projects to be able to find them. Neither of my external pods are used in the main project.
( https://medium.com/#akfreas/how-to-use-cocoapods-with-your-internal-ios-frameworks-192aa472f64b )
(I'm probably not writing the podfile as correctly or efficiently as I could, but this seems to fix my issue)
My podfile is therefore as follows:
abstract_target "RandomName" do
target "MainProject" do
inherit! :complete
workspace './MainProject.xcodeproj'
pod 'Moya', '~> 13.0'
pod 'KeychainSwift', '~> 17.0'
end
target "ModuleA" do
project './ModuleA/ModuleA.xcodeproj'
workspace './ModuleA/ModuleA.xcodeproj'
pod 'Moya', '~> 13.0'
end
target "ModuleB" do
project './ModuleB/ModuleB.xcodeproj'
workspace './ModuleB/ModuleB.xcodeproj'
pod 'KeychainSwift', '~> 17.0'
end
end
Related
I am writing an iOS app, using CocoaPods 1.6.0 as my dependency manager. My project consists of a iOS app project (myapp-ui), as well as 3 iOS framework projects (myapp-common, myapp-model, and myapp-editor). I'm also leveraging Fabric.io for crash reporting and app metrics. My myapp-ui and myapp-model projects both make use of the Fabric and Crashlytics frameworks. My Pods file looks like this:
platform :ios, '11.0'
workspace 'MyApp.xcworkspace'
project 'myapp-ui/myapp-ui.xcodeproj'
project 'myapp-common/myapp-common.xcodeproj'
project 'myapp-model/myapp-model.xcodeproj'
project 'myapp-editor/myapp-editor.xcodeproj'
target 'myapp-ui' do
use_frameworks!
project 'myapp-ui/myapp-ui.xcodeproj'
# Pods for myapp-ui
pod 'SwiftyBeaver'
pod 'SwifterSwift'
pod 'Fabric'
pod 'Crashlytics'
pod 'KeychainSwift', '~> 13.0'
target 'myapp-uiTests' do
inherit! :search_paths
# Pods for testing
end
end
target 'myapp-common' do
use_frameworks!
project 'myapp-common/myapp-common.xcodeproj'
# Pods for myapp-common
pod 'SwiftyBeaver'
pod 'SwifterSwift'
pod 'KeychainSwift', '~> 13.0'
end
target 'myapp-model' do
use_frameworks!
project 'myapp-model/myapp-model.xcodeproj'
# Pods for myapp-model
pod 'SwiftyBeaver'
pod 'SwifterSwift'
pod 'Fabric'
pod 'Crashlytics'
end
target 'myapp-editor' do
use_frameworks!
project 'myapp-editor/myapp-editor.xcodeproj'
# Pods for myapp-editor
end
The pods install just fine, and my app builds with no issue. However, when I run it I see a large number of errors in the console that look something like this:
objc[62607]: Class CLSInternalReport is implemented in both <SOME LOCATION>/Build/Products/Debug-iphonesimulator/myapp_model.framework/myapp_model (0x11252f960) and <SOME OTHER LOCATION>/myapp-ui.app/myapp-ui (0x10f2831e8). One of the two will be used. Which one is undefined.
objc[62607]: Class Crashlytics is implemented in both <SOME LOCATION>/Products/Debug-iphonesimulator/myapp_model.framework/myapp_model (0x11252f9b0) and <SOME OTHER LOCATION>/myapp-ui.app/myapp-ui (0x10f283238). One of the two will be used. Which one is undefined.
objc[62607]: Class CLSFileManager is implemented in both <SOME LOCATION>/Build/Products/Debug-iphonesimulator/myapp_model.framework/myapp_model (0x11252fa00) and <SOME OTHER LOCATION>/myapp-ui.app/myapp-ui (0x10f283288). One of the two will be used. Which one is undefined.
objc[62607]: Class CLSAlert is implemented in both <SOME LOCATION>/Build/Products/Debug-iphonesimulator/myapp_model.framework/myapp_model (0x11252fa78) and <SOME OTHER LOCATION>/myapp-ui.app/myapp-ui (0x10f283300). One of the two will be used. Which one is undefined.
Is there a way to address these warnings? I've tried removing them from myapp-ui thinking that myapp-ui makes use of myapp-model (and would therefore inherit the dependency) but that didn't work. I'm at a loss as to how to address this. Thoughts?
I was getting the same warnings you're seeing and took me a while to find a fix. Turns out this happens when you have a dependency that comes pre-compiled, like Fabric and Crashlytics. I think it's because they are copied twice.
What I did was to add those pods only to the app target. My Podfile ended up looking somewhat like this
def pods
pod 'CGMath'
...
end
def app
pod 'Crashlytics'
pod 'Fabric'
end
target 'FrameworkTarget' do
pods
end
target 'AppTarget' do
pods
app
end
I'm trying to pod install this library into my project's (lets say child xcodeproj) parent project (lets say Parent xcodeproj).
Child .xcodeproj has its own podfile where I have added RxSwift, RxCocoa, Realm and this GeoSwift library. Here is the cocoapods file as show below
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, "9.0"
inhibit_all_warnings!
use_frameworks!
project 'LocationManager/LocationManager'
def pods
pod 'GEOSwift'
pod 'RxSwift', '~> 4.0'
pod 'RxCocoa', '~> 4.0'
pod 'RealmSwift', '~> 3.0'
end
target 'LocationManager' do
pods
target 'LocationManagerTests' do
inherit! :search_paths
pod 'RxBlocking', '~> 4.0'
pod 'RxTest', '~> 4.0'
end
end
This LocationManager is installed into another XCode project as another podfile
def location_pods
pod 'GEOSwift'
pod 'LocationManager', :git => 'git#github.com:myrepo/locationmanager.git', :branch => 'users/me/add-geoswift'
end
target 'TestApp' do
location_pods
project 'TestApp.project'
end
When I try to compile the TestApp target, XCode throws an error as below
GeoSwift module is not found. This error is inside the Pods > LocationManager > MockLocationManager.swift The same module imported else where in that Pods > LocationManager works. Also import RxSwift and import RxCoca works. When I accessed Pods > Targets > LocationManager > Build Phases > Target Dependencies I see all the pods except GeoSwift
May I know how to fix this issue? Adding GeoSwift to this targetDependency doesn't compile either. When compiling LocationManager.xcworkspace as a separate entity it works perfectly fine. That module import GeoSwift doesn't throw any compilation error.
I had an issue similar to this.
Go into Pods:
Then click on "Build Settings", find the row titled "Swift Language Version", and try updating it to the latest (in my case, it was 4.1).
This worked for me! Hopefully it helps someone else out there too.
More info: Xcode 9 Swift Language Version (SWIFT_VERSION)
From what I know Cocoapods do not support sub-projects. I had an issue with this too and I promoted all my sub-projects as folders within the main project and put them under a different target. Now those targets can use Cocoapods too.
Ok, let's start with the basics since I cannot friggin get this to work (see Xcode Workspace - Not finding imports from framework project pod)...
I want to create an Xcode workspace that has two projects:
Cocoa Touch Framework Swift project
Swift Demo app project for the framework
Nr. 2 should also contain a UI Testing target.
Then I want to use Cocoapods to provide the WHOLE workspace (both projects!) as a pod AND I want to 'link' the framework project into the demo app project so that it can be used there.
Can somebody guide me through this incl. how the pod file needs to look for this?
You need define the pods that will be common for all your projects first
# Uncomment this line to define a global platform for your project
platform :ios, '8.2'
# Uncomment this line if you're using Swift
use_frameworks!
# Define main pods.
def main_pods
#your main pods
pod 'AwesomeCache', '~> 5.0'
pod 'DZNEmptyDataSet', '1.8.1'
end
# Your FirstProjectName.
target 'FirstProyectName' do
main_pods
#here you can add any other for this specific project
pod 'Branch'
end
# Your SecondProjectName.
target 'SecondProjectName' do
main_pods
#here you can add any other for this specific project
pod 'Alamofire'
pod 'Fabric'
pod 'Crashlitycs'
end
target 'FirstProjectTestName' do
end
target 'FirstProjectTestUIName' do
end
post_install do |installer|
puts("Update debug pod settings to speed up build time")
Dir.glob(File.join("Pods", "**", "Pods*{debug,Private}.xcconfig")).each do |file|
File.open(file, 'a') { |f| f.puts "\nDEBUG_INFORMATION_FORMAT = dwarf" }
end
end
end
Hope this helps
I am using xcode 8 for development and cocoapods 1.0.1 for frameworks. After installing frameworks, i couldn't able to build my project. I am getting "ld: framework not found" error. I am using following lines in pod file:
# Uncomment this line to define a global platform for your project
platform :ios, '9.0'
target 'Sample' do
use_frameworks!
pod 'MBProgressHUD', '~> 0.9'
pod 'TPKeyboardAvoiding', '~> 1.2'
pod 'SDWebImage', '~> 3.7'
pod 'UIActivityIndicator-for-SDWebImage'
pod 'UITextView+Placeholder', '~> 1.2'
pod 'Alamofire', '~> 4.0'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
After installing the frameworks, did you closed your project and opened the newly created workspace?
Once you start using CocoaPods to install framework, you must use the workspace as it includes your Sample project and the Pod project containing the frameworks.
In you project directory, make sure to open the .xcworkspace instead of .xcodeproj.
Edit:
If that is not the issue, go to your Sample target/General/Linked Framework and Librairies
You should only have one that should be name something like: Pods_Sample.framework
If you are only using cocoa pods to install frameworks it should be the only one there as it includes all the pods.
select your target -> General ->Embedded Binary , click + ,and add Alamofire.framework
try adding project 'APP_NAME.xcodeproj' to your podfile after use_frameworks! and do pod install again
if you receive warnings like below, after pod install
[!] The `APP_NAME [Debug]` target overrides the `FRAMEWORK_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-BasePods-APP_NAME/Pods-BasePods-APP_NAME.debug.xcconfig'. This can lead to problems with the CocoaPods installation
Go to Build Settings of your target and add $(inherited) to Framework Search Paths
I had this problem, and it happened a while after renaming my project.
It was using my Pod_Old_Project_Name as a framework.
I fixed this by going to Build Phases -> Link Binary With Libraries, and removed that framework.
There are two reasons this error occurs
I have faced the same issue, This comes only due to change in the
pod file or maybe the pod file may not exist, double check the pod
file and run the cmd pod install
After successfully installing the pod file still if you getting this
error please restart the Xcode, error goes away
I have a workspace with several projects. Each customer has its own project and each customer's project depends on
Core project: Static library with common code
Interface project: Static library with common interface, i.e. UIViewController code
The Interface library depends on Core too.
Each one of the projects have two targets. The normal target and the tests target, so,
Core, CoreTests
Interface, InterfaceTests
Customer, CustomerTests
Since every aspect of the app is being heavily developed at the moment, I have all projects on the same workspace and also on the same repository because changes may occur in any part of the structure at any moment.
I want to use CocoaPods to manage the dependencies that the projects have. To keep it simple let's say I can to use OCMock on every test target, NewRelicAgent on every normal target and Reachability only on the Core target.
The Podfile looks like this:
workspace 'CompanyWorkspace'
xcodeproj 'Core/Core.xcodeproj'
xcodeproj 'Interface/Interface.xcodeproj'
xcodeproj 'Customer/Customer.xcodeproj'
target :Core do
platform :ios, '6.0'
xcodeproj 'Core/Core.xcodeproj'
pod 'NewRelicAgent', '~> 5.1'
pod 'Reachability', '~> 3.2'
end
target :CoreTests do
platform :ios, '6.0'
xcodeproj 'Core/Core.xcodeproj'
pod 'OCMock', '~> 3.1'
end
target :Interface do
platform :ios, '6.0'
xcodeproj 'Interface/Interface.xcodeproj'
pod 'NewRelicAgent', '~> 5.1'
end
target :InterfaceTest do
platform :ios, '6.0'
xcodeproj 'Interface/Interface.xcodeproj'
pod 'OCMock', '~> 3.1'
end
target :Customer do
platform :ios, '7.0'
xcodeproj 'Customer/Customer.xcodeproj'
pod 'NewRelicAgent', '~> 5.1'
end
target :CustomerTests do
platform :ios, '7.0'
xcodeproj 'Customer/Customer.xcodeproj'
pod 'OCMock', '~> 3.1'
end
I solved the dependencies between my structure by adding the static library Core.a into the build phases of Interface.a and by changing User Header Search Paths so it finds the headers. In the Customer project I added Core.a and Interface.a into the build phases and modified User Header Search Paths so it finds the code from Core and Interface.
The problem with this approach is that Core and Interface build an execute their tests properly but when I try to build Customer.app I get a number of duplicate symbols errors. I believe that this is because the target keyword in CocoaPods generates static libraries with the dependencies configured so when Customer is built it tries to include twice the code from Core.
Any idea as how to solve this problem?