Reference to cocoapods when running unit tests - xcode

I've created a brand new static library project for iOS in Xcode 5 called 'MyApi'. After that I create a Podfile adding AFNetworking as a dependency so far so good. Lets say that I need to use AFNetworking in my MyApi.h file, #import . Finally I want to run tests on my code. I start by adding #import "MyApi.h" in my MyApiTests.m. If I hit CMD+U to test my code it will complain that the tests can't find AFNetworking. I can solve this by adding link_with "MyApi", "MyApiTests" in my Podfile. But now when I hit Test it will complain about duplicate symbol _OBJC...... (on all AFNetworking classes). I managed to get around this by removing libPods.a in Link Binary With Libraries in the MyApiTests target and everything works fine. But every time I run pod install I will have to do this manual step of removing the libPods.a. Since we don't keep the workspace that cocoa pods creates in our git repo. And since this is running on a jenkins server automatically I can't manually remove the libPods.a file. Can this be done in a better way that works without the manual step?
(Please don't make this a discussion about if you should checkin the xcworkspace).

Related

Building a React Native bridge but a file within the framework can't be found

I'm trying to build a React Native wrapper for the RichRelevance iOS SDK.
I've created the wrapper project and imported it into my React Native app. I'm using Cocoapods to add the RichRelevance SDK to the app
I'm now attempting to import the RichRelevance SDK into the wrapper project using:
#import <RichRelevanceSDK/RichRelevanceSDK.h>
The problem I have is that when the compiler attempts to compile the RichRelevanceSDK, it throws an error that one of the files is not found:
Line 63 is the original import that was written in the SDK. I added Line 62 to show that the file can be found if the type of import is changed. However, this isn't really an option since I don't want to modify the SDK (I don't own it).
In either type of import, I'm able to cmd+click the file and go to the definition. So XCode seems to know about the file. Additionally, I see the file in the Project browser under:
Pods -> Pods -> RichRelevanceSDK -> RCHImportable.h
The primary difference with this file is that, if I look in the file browser, that file is located in a sub-folder, relative to all of the other files in the SDK:
I'm hoping there's a way to change my wrapper project so that this file can be found, so I don't have to edit or fork the SDK files.
So far, I've attempted to update the various Search Paths in my wrapper project but with no luck. I've added the following two paths to all of the Search Paths:
UPDATE:
I was able to make some progress and I can now get it to compile.
I ended up:
cloning the SDK's repo to my computer
removing the SDK from the Podfile
adding the SDK's xcodeproj file to MyApp/Libraries
adding the SDK.framework file to MyApp -> Embedded Binaries
I can now import the SDK into my bridge module
I would still prefer to find a better way to do this though. This method either involves me committing the SDK to our repo or asking all of my colleagues to clone the repo to their machine. NPM can't seem to install the repo; my guess is this is due to the repo missing a package.json file
There does appear to be something wrong with the packaging, as the header in question would appear to be captured in the public_header_files glob in the Podspec.
However, I think more direct path is to simply include the RCHSDK.h file, as RCHSDK is the entrypoint to the SDK functions. The RichRelevanceSDK.h serves primarily as a shorthand for importing additional headers versus specifying them individually.
Alternatively, you can follow the instructions in Include of non-modular header inside framework module, this seemed to correct the issue in local tests.

Cocoa Pods without workspace?

I have read about a possibility to add CocoaPods to an XcodeProject without getting the xcworkspace file, instead you get a xcodeproj file that you can integrate into your current project. How can I do that? Would love to use the xcodeproj file instead of xcworkspace.. I'm programming in swift (if that makes any difference).
Yes, its possible. But, we need to do few steps to proceed.
Check this Github thread.
The below line in pod.file will not let the client integration process.
install! 'cocoapods', :integrate_targets => false
We can drag and drop the Pods.xcodeproj to the main project
Link the target dependencies and Link Binary with Libraries in Build phases.
Thats it.
You can not do this.
The CocoaPods website guide to using CocoaPods found here directs you to using the .xcworkspace it creates. Several other guides found across the Internet all direct you to use this file indicating that using the .xcodeproj file will now result in build errors.
There is simply no evidence that this is a possibility at all.
From the CocoaPods website guide on using CocoaPods:
Save your Podfile.
Run $ pod install
Open the MyApp.xcworkspace that was created. This should be the file you use everyday to create your app.
More from their website:
Now you can install the dependencies in your project:
$ pod install
Make sure to always open the Xcode workspace instead of the project
file when building your project:
$ open App.xcworkspace
And from the Ray Wenderlich guide regarding using CocoaPods with Swift:
Open the project folder using Finder, and you’ll see that CocoaPods
created a new IceCreamShop.xcworkspace file and a Pods folder in which
to store all the project’s dependencies.
And from an NSHipster article on CocoaPods:
CocoaPods will create a new Xcode project that creates static library
targets for each dependency, and then links them all together into a
libPods.a target. This static library becomes a dependency for your
original application target. An xcworkspace file is created, and
should be used from that point onward. This allows the original
xcodeproj file to remain unchanged.
In older versions of cocoapods it was possible to install and update pods with the option '--no-integrate'. It allows you to create a library project, which could be imported into an existing project (read more). But this option is missing now. I've build a Xcode project for a maven-build with this option earlier. Today I've updated the pods of this project with the newest cocoapods version (1.0.0) but without the '--no-integrate' option and it still works. So eventually there is a way...

File headers are not being found in Xcode project

i just bought the newest imac.
running OS 10.9.5- 64 bit
I am using cocoapods version 0.34.1
xcode latest stable build (6.01)
And for some reason the repo ive been working on for a year now is having all kinds of trouble finding pod header files.
for parse, im getting 'Parse/Parse.h' file not found,
I could be wrong but i dont think its specific to parse.
Nothing is different about my project environment except for the new computer.
If you are using pod 'Parse-IOS' change it to pod 'Parse', '~> 1.4' because has been deprecated.
Also, does it happen for pods to not been found by ProjectTests?
If so, add at the top of the podfile this line:
link_with ['ProjectName', 'ProjectNameTests']
and at your project Build Setting->Other Linker Flags, add $(inherited).
If you dont need the test target, remove it from the build to solve this.
Go to edit scheme under project and expand all the items in the left column. Highlight any references to test and hit the minus button.
This information can save you from banging your head into the wall.

Crashlytics file not found

Recently opened a project that I had compiled and submitted to Apple.
I haven't touched it for a couple of months but I'm getting this odd compile error at:
#import <Crashlytics/Crashlytics.h>
The error reads:
'Crashlytics/Crashlytics.h' file not found
Clearly the framework can't be found but I'm puzzled as to why, when the project was working a few months ago, it's suddenly stopped.
Any suggestions why?
Xcode: 4.6.3
Mac OS X: 10.8.4
Just add $(SRCROOT) to the Framework Search Paths in Project Build Settings (Search Paths).
Crashlytics installation process drops its Crashlytics.framework to your project folder (or creates the symlink).
If you moved Crashlytics.framework somewhere deeper in the project folder hierarchy - set 'recursive' to the right or just point directly to its parent folder in Header Search Paths:
$(SRCROOT)/Path/to/the/folder/containing/Crashlytics.framework
Delete frameworks from you project and disk. Check that you have the newest version of Fabric plugin.
Copy frameworks from plugin folder to desktop with this commands:
ditto -xk ~/Library/Caches/com.crashlytics.mac/5b91b14e832a7b1c29441ec5ba109810/sdks/ios/com.twitter.crashlytics.ios-default.zip ~/Desktop/
ditto -xk ~/Library/Caches/com.crashlytics.mac/5b91b14e832a7b1c29441ec5ba109810/sdks/ios/io.fabric.sdk.ios-default.zip ~/Desktop/
Add frameworks from desktop to your project.
Info from: https://twittercommunity.com/t/error-upgrading-from-crashlytics-on-ios/36196/2
I'd recommend just using CocoaPods to add the Crashlytics framework. No need to care about paths anymore.
Podfile:
pod 'Crashlytics', '~> 3.4.1'
Script Build Phase for dSYM Upload:
./Pods/Crashlytics/iOS/Crashlytics.framework/run <your_crashlytics_id>
Import:
#import <Crashlytics/Crashlytics.h>
For me, this worked:
Remove the fabric and crashlytics frameworks from your project, and delete the files from the disk for our project.
Comment the lines in your appdelegate.m file, if you added them for the following:
import Fabric/Fabric.h
import Crashlytics/Crashlytics.h
and
[Fabric with:#[CrashlyticsKit]];
In the fabric app, choose "New app", and select your Xcode project file
Recopy the build script and build as instructed. The build step is why you needed to comment the lines above-- it won't work if you leave those lines in.
After the build script runs, it will prompt you to drag the frameworks from the app window into your project navigator. This will copy the latest versions of he frameworks (which include the .h files) into your project
I have tried manually downloading, and copying from other projects, but this is the only way I could recover after losing the frameworks files for an app.
In my case, the Framework was in the project folder, but not in the Project Navigator. I dragged it to the project and everything worked fine.
I've had this issue working with distributed teams (through github) after checking in then checking out Crashlytics. The Crashlytics.framework will only have one folder inside it -- "Versions". You need to save a version of the contents inside Crashlytics.framework to another location, then copy-paste them into Crashlytics.framework later.
Remove Crashlytics.framework from the project and disk. Copy and add it again. It helped me.
In my case, I was migrating from an old Crashlytics install through the Mac app to Cocoapods. A lot of the answers to this question recommend completely removing everything and starting over. I started doing this and noticed a discrepancy between code found in Fabric's documentation and the code shown in the Fabric app during the step where it tells you what to copy into your Run Script Build Phase.
Fabric's documentation has double quotes surrounding the entire string: "${PODS_ROOT}/Fabric/Fabric.framework/run <Your_API_Key> <Your_Build_Secret>"
The Fabric App only had double quotes around the path to the run executable: "${PODS_ROOT}/Fabric/Fabric.framework/run" <Your_API_Key> <Your_Build_Secret>
So before you delete everything and start over, try updating your Run Script Build Phase to this:
"${PODS_ROOT}/Fabric/Fabric.framework/run" <Your_API_Key> <Your_Build_Secret>
I have changed the name of the working folder and Craslytics fails. Check this in Build Settings (Search Paths).
Good luck!
I have tried to play with the frameworks search path and relocating & reconnecting the framework file; checked the build settings (Link binary with libraries section) but the error persisted.
Finally, I have reinstalled the framework, which only takes 2-3 minutes. The problem might be caused by that you have relocated the Crashlytics.framework to another subfolder from the root directory, but I am not sure about the exact reason.
Delete everything regarding to the Crashlytics
Start crashlytics app, login and select your project
Add run script
Drag & drop the .framework file (I have kept it in the root folder)
Add the import and startWithAPIKey statements back
Completely Remove the Crashlytics Frameworks on your proj include the shell script in App Build Phases Run Script.
Reinstall the Fabric follow the guide,everything will be OK.
I had previously upgraded to Fabric and had no issues. A couple of days later, I reopened the same project and had the missing crashlytics.h file problem.
I couldn't simply reinstall from the plugin due to a non compiling project (I had so many CLS_LOG messages and references to the missing crashlytics.h file in my project, it would have taken a long time to remove them just to allow the build to work - refactor wouldn't work on CLS_LOG).
So instead, I deleted the crashlytics.framework from my project and did the following to reinstate it from the plug in directly:
Download the Fabric plugin again and double click the zip file to unpack the Fabric application.
Right click the Fabric icon and "Show Package Contents"
Copy the Crashlytics.framework folder to your Desktop and then re-add it to your project via File -> Add Files to ....
If step 3 doesn't work for you, you can also add crashlytics.framework to your project folder on your computer directly, and then also add it into your project list via Xcode same as in step 3 but uncheck "Copy Items if Needed" as you already put the files there yourself.
My project then compiled and worked fine again.
In terms of a guess as to why the file went missing? Part of the upgrade process got me to delete the old frameworks and then run the scripts etc. from the plugin. I think what happened is later when I emptied my trash, that some references were lost. I also had the problem where I'd put Crashlytics into my .gitignore file so it disappeared out of ALL my projects every committed which wasn't great.
Hope this helps someone!
I have same error.
Please try pod update
and fix it.
If FirebaseCrashlytics 9.0.0 installed , problem will be fixed.
stalling FirebaseCoreDiagnostics 9.0.0 (was 8.9.0)
Installing FirebaseCoreExtension (9.0.0)
Installing FirebaseCoreInternal (9.0.0)
//hrer
Installing FirebaseCrashlytics 9.0.0 (was 8.9.0)
Installing FirebaseFirestore 9.0.0 (was 8.9.1)
Installing FirebaseInstallations 9.0.0 (was 8.9.0)

Cocoapods pod install as a target dependency

I've created an external build system target in my Xcode project and made it a dependency of the main target, so I want this target run before the main target starts building. In this external build system target I simply reference a bash script to run pod install from the SRCROOT dir.
As expected, my new target runs first and Pod install runs fine but then the build stops. It does not fail however, it just reports the Build stopped with no issues. The exit code from pod install is 0 so the script should return as successful yet the build stops.
Does anyone know why this may be happening?
I tried to implement the same functionality directly in CocoaPods and experienced the same behavior. I think that Xcode aborts the build as CocoaPods performs changes in the Pods project, which is recreated from scratch at the moment.
This approach might be viable once we start to edit in place the Pods project in CocoaPods.

Resources