Targets within a target in a Podfile - ios

I am trying to install the Google Mobile Ads SKD into my Xcode project. I installed Cocoapods and then initialized a Podfile into my project:
# Uncomment the next line to define a global platform for your project
platform :ios, '10.2'
target 'Cubical' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Cubical
target 'CubicalTests' do
inherit! :search_paths
# Pods for testing
end
target 'CubicalUITests' do
inherit! :search_paths
# Pods for testing
end
end
However, I don't understand why there are targets within my main project (Cubical). I never really used CubicalTests or CubicalUITests, since I don't really need to test my UI or any snippet of code. I was thinking of removing these two folders.
My questions are,
1) Is there any drawback in removing the Tests and UITests folders from my Xcode project? And if I do, can I just simply delete those two targets from my Podfile?
2) Let's say I was going to keep those two targets. Would I have to add the pod to all three targets? Or do the two nested targets inherit any pods of target 'Cubical'
3) Do I need to add to Linked Frameworks the Google Mobile Ads SDK? Or is this already done by Cocoapods?
My final pod would look like this:
# Uncomment the next line to define a global platform for your project
platform :ios, '10.2'
target 'Cubical' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'Google-Mobile-Ads-SDK'
# Pods for Cubical
target 'CubicalTests' do
inherit! :search_paths
# Pods for testing
end
target 'CubicalUITests' do
inherit! :search_paths
# Pods for testing
end
end

Question 1:
There is no issue when you are removing Tests,CubicalUITests targets & folders, If you don't need to perform that kind of tests.
Question 2:
You can share pods with several targets like below,
def shared
pod 'Google-Mobile-Ads-SDK'
end
target 'Target1' do
shared
end
target 'Terget2' do
shared
end
Global pods for multiple targets
#Global Pod for all targets
pod 'Google-Mobile-Ads-SDK'
target 'target1' do
pod 'Fabric' #Pod for nested Target. i.e., Google-Mobile-Ads-SDK + Fabric
end
target 'target2' do
pod 'RadioButton'#Pod for nested Target. i.e., Google-Mobile-Ads-SDK + RadioButton
end
Pods for nested targets:
#Global Pod for all targets
pod 'Google-Mobile-Ads-SDK'
target 'target1' do
pod 'RadioButton' #Available for target1 and target2
target 'target2 copy' do
pod 'Fabric' #Available for target2 only
end
end
Question 3:
The linked frameworks are automatically done by cocoapods. See here you need to link the framework by using frameworks without cocoapods.

Related

CocoaPods - Duplicate symbols when app & framework share a dependency

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

Linking an Objective-C framework with multiple targets in the same workspace with CocoaPods

I have a workspace with multiple framework targets and one application target. All of these targets depend on a common CocoaPod (GoogleMaps in this case). How should I write my Podfile so that all these targets can use GoogleMaps without it being duplicated across these targets?
My current Podfile is as follows:
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'FrameworkA' do
# Comment the next line if you're not using Swift and don't want to use
# dynamic frameworks
use_frameworks!
# Pods for FrameworkA
pod 'GoogleMaps'
end
target 'FrameworkB' do
# Comment the next line if you're not using Swift and don't want to use
# dynamic frameworks
use_frameworks!
pod 'GoogleMaps'
# Pods for FrameworkB
end
target 'FrameworkTest' do
# Comment the next line if you're not using Swift and don't want to use
# dynamic frameworks
use_frameworks!
pod 'GoogleMaps'
# Pods for FrameworkTest
end
This allows me to use GoogleMaps in all targets but it ends up being duplicated in these targets. I can see errors like these being logged in the console:
Class GMSReverseGeocodeResponse is implemented in both /Users/harshad/Library/Developer/Xcode/DerivedData/FrameworkTest-ccpoenicmupoxyadfsxniyjogcjk/Build/Products/Debug-iphonesimulator/FrameworkA.framework/FrameworkA (0x104b73a30)
and /Users/harshad/Library/Developer/Xcode/DerivedData/FrameworkTest-ccpoenicmupoxyadfsxniyjogcjk/Build/Products/Debug-iphonesimulator/FrameworkB.framework/FrameworkB (0x1043b0a30).
One of the two will be used. Which one is undefined.
How can I fix this?
Edit: Here's the link to the Github project
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
def shared_pods
pod 'GoogleMaps'
end
target 'FrameworkA' do
shared_pods
end
target 'FrameworkB' do
shared_pods
end
target 'FrameworkTest' do
shared_pods
end

How to fix missing module in unit-test file?

So I'm very new with unit test in Swift. In my project I'm using a couple of frameworks installed in my cocoa pods, but when I was about to write some code in my test file, I always get this error. missing module: Firebase, Eureka, ImageRow
I tried to import these modules above the #testable, but somehow it didn't recognize the module. it keeps on saying module not found. I've also tried to remove my pods inside the inherit search paths, and it still on asking that I need to import these module. Here's my cocoa pod.
target 'ProjectRed' do
use_frameworks!
pod 'Firebase'
pod 'Eureka'
pod 'ImageRow'
pod ‘Firebase/Database’
pod ‘Firebase/Storage’
# Pods for ProjectRed
target 'ProjectRedTests' do
inherit! :search_paths
# Pods for testing
end
target 'ProjectRedUITests' do
inherit! :search_paths
# Pods for testing
end
end
target 'ProjectRedTests' do
inherit! :search_paths
pod 'Firebase'
pod 'Eureka'
pod 'ImageRow'
pod ‘Firebase/Database’
pod ‘Firebase/Storage’
For me putting those modules in ProjectRedTests worked.
You need to add those frameworks to your test target also.
Select your test target in the Targets section of your project.
Select the Build Phases tab.
Add your frameworks to the Link Binary With Libraries section.
(Note: you may need to add a Copy Files phase before Link Binary With Libraries to get them into the right position.)

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.

iOS , ld: framework not found GoogleMaps for architecture arm64

I'm developing an app using google maps. I will explain what I did with google maps, and maybe you can help me.
I was using Google maps frameworks without POD, but after a few errors about Google map Key I deleted the google map frameworks reference and I installed it using POD. Everything is working fine, but when I hit
Product -> TEST
now I get this error:
ld: framework not found GoogleMaps for architecture arm64
Any idea how fix this?
Thank you!
Podfile looks like this Cocoapods v1.0 beta 6):
platform :ios, '8.0'
use_frameworks!
target 'Project' do
pod 'GoogleMaps'
target 'ProjectTests' do
inherit! :search_paths
pod 'Mockingjay'
end
end
Update Please check if you have same build settings in the Architectures and Build active Architectures only keys of the targets
Your podfile should look like this
platform :ios, '8.0'
use_frameworks!
target 'Project' do
pod 'GoogleMaps'
end
target 'ProjectTests' do
//inherit! :search_paths
pod 'Mockingjay'
end
End the project target before you start the ProjectTest target, also why you add inherit! :search_paths? it's usually not needed unless you have some special requirement
Old Answer
If you want to you pods in the Test target than you have to add then in the test also the same way you have added in project's main target
So your cocoa pods like this if "SwiftCocoaPods" is your main target name
//other top level imports
target “SwiftCocoaPods” do
pod "GoogleMaps"
end
target “SwiftCocoaPodsTests” do
pod "GoogleMaps"
end
Then you should add pods for the test also like "SwiftCocoaPodsTests". you may replace the name with whatever you Test target name is
Else if you want to add the same pods in the multiple target you can use def and use that in all the targets which looks like this
def project_pods
pod "GoogleMaps"
//add other pods which you want in all the targets
end
target “SwiftCocoaPods” do
project_pods
end
//only add project_pods instead of pods individually
target “SwiftCocoaPodsTests” do
project_pods
end
This works for me:
platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
def all_pods
pod 'GoogleMaps'
end
abstract_target 'Map Base' do
all_pods
target 'Map' do
end
target 'Unit Tests' do
end
target 'Device Tests' do
end
end
You can try this workaround by opening Xcode with Rosetta as suggested in https://github.com/googlemaps/google-maps-ios-utils/issues/355#issuecomment-800912985
It will hit your performance but works.
1 - With Xcode closed (Important) Go to finder -> Applications
2 - Right Click on Xcode and select "Get Info"
3 - On the info panel check "Open using Rosetta"
4 - Double Click in the large bottom preview of the info panel.
See this comment:
https://github.com/googlemaps/google-maps-ios-utils/issues/355#issuecomment-1060959728

Resources