CocoaPods - iOS, add new OSX target, not linking properly? - ios

I've got an iOS app, that now needs an osx build. As it's 80%-ish shared code I've added an OSX build to the project.
With my cocoapods I'm getting a few build errors (after pod install, also tried pod update)
Also found I had explicitly add a pod to the osx target to get it do the link and build phase magic in the workspace file.
The first and key error:
Target 'Pods-scoreosx' of project 'Pods' was rejected as an implicit dependency for 'Pods_scoreosx.framework' because it doesn't contain platform 'macosx' in its SUPPORTED_PLATFORMS 'iphonesimulator, iphoneos'
Any one know what I'm doing wrong?
edit:
Current Podspec file:
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
use_frameworks!
pod 'EmitterKit'
pod 'SwiftDate'
pod 'CocoaAsyncSocket'
pod 'ReactiveKit', '~> 1.0'
pod 'ReactiveUIKit', '~> 1.0'
pod 'ReactiveFoundation', '~> 1.0'
pod 'AsyncSwift'
target 'score' do
end
target 'scoreTests' do
end
target 'scoreUITests' do
end
target 'scoreosx' do
pod 'EmitterKit'
end
target 'scoreosxTests' do
end
target 'scoreosxUITests' do
end

The error message says you need to explicitly configure the platform for the target. Setting declaring the platform in the target would help.
target 'scoreosx' do
platform :osx
pod 'EmitterKit'
end

Related

Module not found - cocoapods

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.

Xcode and Cocoapods "No such module" error

I recently upgraded to Xcode 8 and an existing project to Swift 3. After having a variety of issues with Cocoapods, I decided to start over from scratch. After running pod deintegrate and deleting Podfile, Podfile.lock, and [Project].xcworkspace, I had a blank slate as far as Cocoapods was concerned.
I then took the following actions:
Opened a terminal at the project location and ran pod init, then pod install (using the stub Podfile that pod init creates).
This appeared to be successful, but came with the following two warnings:
[!] The `Xena [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-Xena/Pods-Xena.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `Xena [Release]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-Xena/Pods-Xena.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
At this point, opening Xcode and building the project gives the "No such module" error, which is entirely expected.
Following the instructions at this question solves this problem and rerunning pod install is a success.
Closed Xcode, added the modules I'm using to the Podfile (see below), the ran pod install again. According to the terminal output, this is successful.
Opened Xcode and built the project. I again receive the "No such module" error, specifically No such module 'ReactiveCocoa'
I have confirmed that the same problem occurs with SnapKit, Hue, KMPlaceholderTextView, KeychainSwift, and Siren, depending on the order of the import statements. For some reason, none of the Google modules are affected by this problem.
My Podfile:
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'Xena' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Xena
pod 'ReactiveCocoa', :git => 'https://github.com/ReactiveCocoa/ReactiveCocoa.git'
pod 'SnapKit', '~> 3.0.2'
pod 'Hue', '~> 2.0.1'
pod 'KMPlaceholderTextView', '~> 1.3.0'
pod 'GooglePlacePicker'
pod 'GooglePlaces'
pod 'GoogleMaps'
pod 'KeychainSwift', '~> 7.0'
pod 'Siren'
target 'XenaTests' do
inherit! :search_paths
# Pods for testing
end
target 'XenaUITests' do
inherit! :search_paths
# Pods for testing
end
end
Make sure you are opening .xcworkspace and not .xcodeproj file.
You may further look into this post.
Also under : Target > General > Linked Frameworks and Libraries
Make sure your frameworks are there. Even Pods_Xena.framework is there
Try:
Xcode ->Preferences ->Location ->DerivedData
open the folder DerivedData and move it to Trash
Uncomment the next line to define a global platform for your project
platform :iOS, '9.0'
Uncommenting the second line in your pod file will help you.

The bundle UITests couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle

I can't run my test case due to this following errors :
The bundle “UITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
Library not loaded: #rpath/Alamofire.framework/Alamofire.
Reason: image not found
Try searching and solving since two days but couldn't get through this issue can someone please help.
I was able to reproduce this issue with the project generated by Xcode 10.1. I used Swift 4.2 and CocoaPods 1.10.0 as a dependency manager. I had the following Podfile:
# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'
target 'MyApp' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for MyApp
pod 'Alamofire', '4.8.1'
target 'MyAppTests' do
inherit! :search_paths
# Pods for testing
end
target 'MyAppUITests' do
inherit! :search_paths
# Pods for testing
end
end
Then I removed use_frameworks!, see this link for more details:
# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'
target 'MyApp' do
# Pods for MyApp
pod 'Alamofire', '4.8.1'
target 'MyAppTests' do
inherit! :search_paths
# Pods for testing
end
target 'MyAppUITests' do
inherit! :search_paths
# Pods for testing
end
end
I also received some warnings like this:
[!] The `MyAppUITests [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-MyApp-MyAppUITests/Pods-MyApp-MyAppUITests.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
That's why I removed this line from the MyAppUITests build settings:
After that run pod deintegrate && pod install and then the problem disappeared.
Probably for projects with more dependencies (like here) you need to use another solution.
It's because your pods only apply to your Framework target and no the tests one. Add the tests target to your podfile.
Example :
target 'MyFramework' do
use_frameworks!
pod 'Alamofire', '~> 4.5'
end
target 'MyFrameworkTests' do
use_frameworks!
pod 'Alamofire', '~> 4.5'
end
In your tests target change inherit! :search_paths to inherit! :complete.
See the documentation for what this does.
Check that the deployment target in your UITest target Build Settings is set to the same as the host application you are trying to test. In my case, I added the UITesting target later on, and it created it with a default of deployment target iOS 12. If you then try to run the UITest on iOS lower than 12, it gave me the error mentioned in the question.
In my case, I needed to separate the UI tests target with use_frameworks!.
Moving the UI tests target from nested structure to its own will not help, if you specified use_frameworks! globally somewhere in the top of the Podfile.
The Podfile with error (original):
platform :ios, '10.0'
inhibit_all_warnings!
use_frameworks!
target 'MyProject' do
pod 'R.swift', '~> 5.0'
pod 'Moya/RxSwift', '~> 12.0'
# and other pods
target 'MyProjectTests' do
inherit! :search_paths
pod 'iOSSnapshotTestCase', '~> 6.0'
end
target 'MyProjectUITests' do
inherit! :search_paths
end
end
The Podfile with error (first try to fix):
platform :ios, '10.0'
inhibit_all_warnings!
use_frameworks!
def shared_pods
pod 'R.swift', '~> 5.0'
end
target 'MyProject' do
shared_pods
pod 'Moya/RxSwift', '~> 12.0'
# and other pods
target 'MyProjectTests' do
inherit! :search_paths
pod 'iOSSnapshotTestCase', '~> 6.0'
end
end
target 'MyProjectUITests' do
shared_pods
end
The final working Podfile:
platform :ios, '10.0'
inhibit_all_warnings!
def shared_pods
pod 'R.swift', '~> 5.0'
end
target 'MyProject' do
use_frameworks!
shared_pods
pod 'Moya/RxSwift', '~> 12.0'
# and other pods
target 'MyProjectTests' do
inherit! :search_paths
pod 'iOSSnapshotTestCase', '~> 6.0'
end
end
target 'MyProjectUITests' do
shared_pods
end
I had to add the location of my frameworks to Runpath search Path under targets>mytestTarget>Build Settings>Runpath Search Path
This error happened to me when I added a framework to the project (that's a framework itself, too), and tried to run the tests. I made it optional instead of required, and the tests succeeded.
Switching to legacy build system fixed thi issue with Xcode 10.
For anyone encountering this issue using Carthage, I solved it by adding the /usr/local/bin/carthage copy-frameworks run script phase to the UITest target (rather than just my main app target), and added the framework as an input file.
The bundle UITests couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle
I have run on this problem when tried to run UI Testing Bundle for testing a Framework
The solution is simple:
Build Phases -> + -> New Copy Files Phase -> <select a framework> -> Destination Frameworks
As a result <UI_Testing_Bundle_name>-Runner.app is generated
]3
Go To Build Phases
Open Copy Pods Resources and copy the path
Paste the path that you have copied from Copy Pods Resources and change tag name resources with frameworks
Clean and Build
Run your UITestsFile
What solved my problem was following the following steps:
1) delete the UITests target from the pod file.
Initially, I had the following in the pod file:
target 'XUITests' do
inherit! :search_paths
end
2) Deintegrate the pods (with pod deintegrate)
3) Install the pods (with pod install)
4) Clean your project and run the project or your UITest
In my case, just removing inherit! :search_paths without changing the structure of the file or duplicating any pod fixed my problem.
I saw the answer but without an explanation so decided to post mine.
The issue is that UI tests performed in a separate application that controls the main one and so it can't use the main application's frameworks and so if you just inherit paths to frameworks using Cocoapods UI tests app will crash at the startup.
To fix the issue you need to actually copy frameworks to UI tests app or update your Podfile:
use_frameworks!
target 'App' do
pod 'Alamofire'
target 'App_UnitTests' do
inherit! :search_paths
pod 'Quick'
pod 'Nimble'
end
end
target 'App_UITests' do
pod 'Alamofire'
end
Xcode 11.2 using Apollo framework within another framework. Instead of changing to optional/required, I fixed it by setting to embed.
With this specific error:
The bundle “XXX” couldn’t be loaded because it is damaged or missing
necessary resources. Try reinstalling the bundle. Library not loaded:
#rpath/Apollo.framework/Apollo
I had to embed the framework
For me, the error was when build the UITests.
The solution:
The Targer was with a wrong iOS version, I replace with the same version that the tested Target and everything works!!
For me, this problem was caused by me referencing a property from an extension on a UIKit class from a framework which wasn't imported in the file where it was referenced. Fixed by not using that property. I'm not sure why it compiled in the first place - that should have been a compile-time error, not a runtime error.
In my case simply choosing "My Mac" instead of "My Mac (Mac Catalyst)" allowed me to run the tests.
Try copy every pod for your app target to the UI testing target.
2019 it works.
If you are in fact using Cocoapods, you probably just need to run "pod install" and the build settings will be updated automatically.

Unable to find a target named `ProjectName`

I added new pod in PodFile and ran command
pod install
It deleted all previous pods and failed with following error
Unable to find a target named `ProjectName`
However I recovered all deleted pods by using Git, but now my project is not being compiled, it's giving me the following error:
/Users/userName/Library/Developer/Xcode/DerivedData/Project_Name-fhktwvetozjdorboqdzfwlpzrcyw/Build/Intermediates/Project_Name.build/Debug-iphonesimulator/Project_Name.build/Script-D7BB987C75C5AEC6033AA28E.sh:
/Users/userName/Desktop/iOS_Workspace/Project_Name/Pods/Target Support
Files/Pods-Project_Name/Pods-Project_Name-resources.sh: /bin/sh^M: bad
interpreter: No such file or directory
I tried every solution regarding pods, but neither worked for me.
Any help will be appreciated. Thanks
After spending hours on Google just opened Podfile and found that project name is wrong. So I have just written correct project name in Podfile and issue has been resolved.
Before:
target 'Wrong Project Name' do
pod 'Parse'
pod 'SDWebImage'
end
After:
target 'Correct Project Name' do
pod 'Parse'
pod 'SDWebImage'
end
According to the error, you specify a target named ProjectName but this does not exist in your project. Read the podfile syntax reference carefully and make sure you add the right target name (in my case it's called Tester:)
It is due to target name changed.
just opened Podfile and replace target name with new target name.
(In my case “GoogleMapSample” was “Map Sample”,
“GoogleMapSampleTests” was “Map SampleTests”,
“GoogleMapSampleUITests” was “Map SampleUITests”,
means I just replace “Map Sample” with “GoogleMapSample” for all targets)
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'GoogleMapSample' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'GoogleMaps'
pod 'GooglePlaces'
pod 'Alamofire', '~> 4.4’
pod 'SwiftyJSON', '~> 4.0'
# Pods for GoogleMapSample
target 'GoogleMapSampleTests' do
inherit! :search_paths
# Pods for testing
end
target 'GoogleMapSampleUITests' do
inherit! :search_paths
# Pods for testing
end
end
Take backup of podfile (copy paste at specified location).
Remove pod file. Move to Trash (from) Xcode.
Go to terminal, After locating your pods directory, Hit: pod init
Paste contents from backup-ed file (1st step)...Copy only pod libs. ex. pod 'Firebase/Core'
pod install
Re-start your project then open YourProjectName.xcworkspace.
In my case, the target name was the same,
but it was case sensitive wrong.
"myTarget" // podfile
"MyTarget" // Xcode
make sure your current name for project in Podfile Matching with right name
target 'Project name' do
use_frameworks!
# Pods for Project name
pod 'SwiftMessages'
end
I have a lot of schemas like below. So, we should map a schema in pod file.
Wrong : target 'MobileBranch' do
Correct : target 'Test-MobileBranch' do
Correct : target 'Main-MobileBranch' do
If you are here in 2022 using SwiftUI, I just uncomment the line and specified the latest iOS version. I am using Xcode 14.0.1.
# Uncomment the next line to define a global platform for your project
platform :ios, '16.0'
FIXED
Just I changed App to the correct name of the product which is Mevenda:
target 'Mevenda' do
capacitor_pods
# Add your Pods here
pod 'FirebaseStorage'
end

Cocoapods can't find header xcode 6

I have a problem xcode can't find the headers of my pods in my wokspace.
The headers search path for the target seems ok
Here is the content of my podfile
target "MyApp" do
pod 'AFNetworking', '~> 2.0'
pod 'Reachability'
pod 'ViewDeck', '2.2.11'
pod 'MBProgressHUD', '~> 0.8'
end
But when i build the project i have this error in the prefix.pch
/Users/...../MyApp-Prefix.pch:17:13: 'AFNetworking.h' file not found
I have tried to add platform :ios, "8.0" in my podfile and do a pod update but still no luck
I have also tried to add $(inherited) like suggested in the SO question :
Xcode 6 doesn´t find cocoapods libraries
I'm using xcode 6 on mavericks
I found solution. In your project properties replace this:
You might also want to link your pods with both your targets like so:
platform :osx, '10.7'
link_with 'MyApp', 'MyApp Tests'
pod 'AFNetworking', '~> 1.0'
pod 'Objection', '0.9'
From Cocoapods docs and this answer
Update: This no longer works for Cocoapods 1.0+, the correct way to implement the Podfile is:
platform :ios, '9.0'
inhibit_all_warnings!
target 'MyApp' do
pod 'ObjectiveSugar', '~> 0.5'
target "MyAppTests" do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
end
Source: https://guides.cocoapods.org/syntax/podfile.html#podfile
I was able to fix this in my project. I had a second target for tests. I never used this target and the error disappeared after I deleted it from the project. So maybe not your main target is the source of the problem, but another one.
I agree with jwswart's answer because quite many times I have realized that the issue with just defining dependencies for the 'MyApp' and leaving out 'MyAppTests' as in:
target :'MyApp' do
..
end
breaks the build process because the classes defined in 'MyApp' make use of the dependencies which are not visible in the 'MyAppTests'. Thus as jwswart suggested:
link_with 'MyApp', 'MyApp Tests'
Just have a try to comment this line for your target
# use_frameworks!
~~

Resources