Integrate New relic using carthage package manager - ios

Is there any way i can integrate New Relic sdk into my iOS project using carthage package manager? I don't want to use cocoa pods to do this since i am already using carthage package manager in my project.

Fetch the package via Carthage
To use Carthage there are a few steps. First inside of your Carthage/ Directory add a file called new_relic.json and add this to it:
{
"6.7.0": "https://download.newrelic.com/ios_agent/NewRelic_iOS_Agent_6.7.0.zip"
}
Then in your Cartfile add this line:
binary "./Carthage/new_relic.json" == 6.7.0
Finally run carthage update --platform ios
Integrate New Relic
After you run your update command and you have the package, go to the general tab and add all of these packages to the Linked Frameworks and Libraries section:
Add a bridging header to your project and add this line of code
#import "NewRelicAgent/NewRelic.h"
Then add this script to your build phases section:
SCRIPT=`/usr/bin/find "${SRCROOT}" -name newrelic_postbuild.sh | head -n 1`
/bin/sh "${SCRIPT}" "Your token here"
And this line of code to didFinishLaunchingWithOptions
NewRelic.start(withApplicationToken:"Your Token Here")

Related

Swift and Xcode: How to Build and Run a GitHub repository of iOS Application?

I'm interested on Running this GitHub repository of an iOS Application: https://github.com/septadev/SEPTA-iOS I opened the iSEPTA.xcodeproj file on XCode from the iSEPTA folder, but I'm getting these Buildtime Errors. For example: No such module 'ReSwift', and this is the window I get prompted when I select any of the yellow alerts, I'm not sure if I should perform these changes, yet.
Could it be some incomparability with my XCode and Swift versions?
Please, help!!
This project uses Carthage as a dependency management system for using external dependencies.
You should install Carthage to your computer and then run carthage update from the terminal in the root directory of the project. This will instal the dependencies and will allow you to run the project.
Take a look at Cartfile: it indicates this repo is using Carthage package manager. Follow their instructions to install dependent libraries
This repository requires Carthage ( https://github.com/Carthage/Carthage ) - this is a dependency manager. You can install it using Homebrew (https://brew.sh/)
brew install carthage
then you have to run carthageBuild.sh script (which runs carthage update):
./carthageBuild.sh
and then you have to open: Septa.xcworkspace file
This would be the correct solution if the project used Cocoapods. Since it uses Carthage, look to others answers unless you are referencing this answer to a similar issue.
You need to use Cocoapods to integrate the pods attached to the project. Often times projects will not come with them precompiled. Either you opened the blue project file with the *.xcodeproj extension instead of the white project file with the *.xcworkspace extension.... or you don't have the pods installed at all. In which case read below.
Instructions as follows:
cd to project directory
Install Cocoapods
sudo gem install cocoapods
Ensure the you have the given pods in your repo collection for install
pod repo update
Install the pods
pod install
Validate Project Settings
This is necessary until cocoapods v1.6 release (beta is out).
Open the white project file with the *.xcworkspace extension
After those steps are complete, the project should run normally.

Setting up library with CocoaPods and Swift Package Manager

I have created a swift (iOS/MacOS) library on CocoaPods (BillboardSwiftLibrary). Generally, it has its assets and Classes folders which contain the source files.
I want my library to support Swift Package Manager, so I moved the source files from the Classes folder into a Sources folder outside the pod. However, they are still accessible from the Development pods.
Now my library won't build for Cocoapods launch but compiles for Swift Package Manager, I get the error below when I run pod lib lint BillboardSwiftLibrary.podspec
ERROR | file patterns: The source_files pattern did not match any
file.
I wrote a long series from scratch about "Creating iOS framework with CocoaPods, Carthage, SPM support and Travis for running test and Fastlane for release automation" on Medium. I hope it helps.
Creating Swift framework is easy but adding CocoaPods, Carthage and Swift Package Manager support at the same time can sounds like scary in the first place. In addition to that adding Travis to run test for all commits and adding Fastlane to automate release processes for all dependency managers looks like a horror movie. But don’t be afraid. After you finished this series, you can easily create your own Swift frameworks that uses all these tools to make it perfect!
Part 1 — Create CocoaPod and release it.: You will create your own CocoaPod and release it.
Part 2 — Add Carthage support: Your CocoaPod that is created and released at Part 1 will be installed via Carthage.
Part 3 — Add Swift Package Manager support: Your CocoaPod that is created and released at Part 1 will be installed via Swift Package Manager.
Part 4 — Integrate Travis to build example project and run tests for framework: Your framework that can be installed via CocoaPods, Carthage and Swift Package Manager runs tests automatically on Travis for every push on GitHub.
Part 5 — Integrate Fastlane to automate release processes by running just one line of command.:
Every time you want to release new version of your framework via CocoaPods, Carthage and Swift Package Manager, you have to go through following steps:
1- Implement changes for new version
2- Run tests to be sure they are working
3- Commit and push changes for new version.
4- Tag new version to git
git tag 0.1.1
git push origin 0.1.1
Carthage and Swift Package Manager installs your framework from GitHub. If you configure your framework correctly, it can be installed via Carthage or Swift Package Manager after this step. However, CocoaPods has 4 more steps to complete release processes.
5- Increment podspec version => i.e. s.version = '0.1.1'
6- Validate local podspec:
pod lib lint ODCustomFramework.podspec
7- Validate pod for release
pod spec lint ODCustomFramework.podspec
8- Release
pod trunk push ODCustomFramework.podspec
After Travis and Fastlane integration, steps 2, 4, 5, 6, 7 and 8 are automated and those steps are no longer needed to repeat every time you want to release new version.
1- Implement changes for new version
2- Commit and push changes for new version.
3- Travis runs tests automatically after every push.
4- Run following fastlane command to automate all release processes. (step 4, 5, 6, 7, 8)
exec fastlane major | minor | patch
From #Larme's comment, I found the answer.
In your podspec file, change the location of your classes to the sources folder.
So changed my s.source_files from to BillboardSwiftLibrary/Classes/**/* to Sources/**/* and pod lib lint BillboardSwiftLibrary.podspec worked fine.

Quickest way to add Carthage in Xcode Project

What is quickest way to add dependencies in Xcode project using Carthage.
How to add or edit dependencies later.
Install Carthage
Download Carthage
Open terminal
Terminal: cd ~/Path/To/Folder Containing Project
Create Carthage file as:
Terminal: touch Cartfile
Open Cartfile file from project folder and add required dependency
Example Cartfile file
github "Alamofire/Alamofire" == 4.5
github "Alamofire/AlamofireImage"
After Editing Cartfile file save it.
Run following command from terminal
Terminal: carthage update --platform iOS
xCode > Build phases
Plus button on top left > New Run Script Phases
Run Script > Shell script window > add following:
/usr/local/bin/carthage copy-frameworks
Run Script > Input file window > add following:
$(SRCROOT)/Carthage/Build/iOS/DependencyName.framework
Link Binary With Libraries > Plus button > Add Other > Navigate to
Project Folder > Carthage > Build > iOS >
Framework to add
Done
Using Carthage flow
[iOS Dependency manager]
TL;DR:
Download dependency -> build fat binary -> it should be imported -> slice for release
Long version:
Installing Carthage
//Homebrew
brew install carthage
Create Cartfile file at the project(.xcodeproj)/workspace(.xcworkspace) directory
Modify Cartfile. Add necessary dependency == repo
github "<owner>/<repo>" == <version>
Run carthage update under Cartfile location. High level logic:
`carthage update [dependency]` {
- reads `Cartfile`, resolves dependency graph and generates `Cartfile.resolved` to store a list of versions that will be actually built
//--no-use-binaries - this flag force a Carthage to not use a `Prebuilt framework`
//--no-build - this flag skip a building step - `carthage build`
`carthage bootstrap [dependency]` {
- reads `Cartfile.resolved`
`carthage checkout [dependency]` {
`carthage fetch <path>` {
- fetch dependency from `Cartfile.resolved` into `~/Library/Caches/org.carthage.CarthageKit/` folder
}
- checkout/move a dependency from `~/Library/Caches/org.carthage.CarthageKit/` to generated `Carthage/Checkouts` folder
}
`carthage build [dependency]` {
- builds all `shared frameworks schemes` from `Carthage/Checkouts` into generated `Carthage/Build` folder
//--no-skip-current - (+current consumer)this flag also builds all `shared frameworks schemes` of a consumer workspace/project(in addition to `Carthage/Checkouts` folder)
}
}
}
Drag and drop builded frameworks to General -> Frameworks and Libraries
//framework location
<cartfile_path>/Carthage/Build/
Run the next script. This step is important because carthage build a fat binary(arm64... + x86_64) using lipo[About]. Apple reject application which uses it. That is why you should add this extra step to cut architecture for simulator(x86_64)
Build Phases -> + -> New Run Script phase ->
// /usr/local/bin/carthage - path to Carthage, copy-frameworks - command which sets a necessary architecture and copies framework to an application bundle
Shell -> /usr/local/bin/carthage copy-frameworks
//path to a generated Carthage/Build
Input files -> + -> $(SRCROOT)/Carthage/Build/<platform>/<name>.framework
*Any carthage command should be called from Cartfile folder
If you run into some error
This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/2q/jhrcxkmx49g21lydqfrf26ph0000gn/T/carthage-xcodebuild.AySUH3.log
//you can use open command to review the log
open /var/folders/2q/jhrcxkmx49g21lydqfrf26ph0000gn/T/carthage-xcodebuild.AySUH3.log
Crear Carthage cache
rm -rf ~/Library/Caches/org.carthage.CarthageKit
Get stuck on update
carthage update --platform ios --verbose --new-resolver
//e.g.
//The dependency graph contained a cycle
Use XCFramework[About] --use-xcframeworks
//error
Building universal frameworks with common architectures is not possible. The device and simulator slices for "<schema_name>" both build for: arm64
Rebuild with --use-xcframeworks to create an xcframework bundle instead.
//solution
carthage update --platform ios --verbose --new-resolver --use-xcframeworks
[Carthage --no-use-binaries]
[Fast Carthage build]
[Local Carthage]
Install carthage on your mac: brew install carthage
Create a Cartfile in the project root directory, e.g. vim Cartfile and paste:
github "AFNetworking/AFNetworking" ~> 4.0
Build the frameworks: Run carthage update --platform iOS
Warning: dependending on the library you are using, you'll need to follow their instructions on what carthage update command to run specifically. You may need to run e.g. carthage update --use-xcframeworks --platform iOS --no-use-binaries instead. Check their readme.
Add it to Xcode: In finder, navigate to $project_dir/Carthage/Build. You will find a FrameworkName.framework or FrameworkName.xcframework. Drag the .framework/ .xcframework into your Xcode Project (in the project navigator).

What's the equivalent of "development pods" under Carthage?

The teams developing frameworks for our iOS app are migrating from Cocoapods to Carthage.
Under Cocoapods, I could set up dependencies as "development pods". For example, instead of having the main app download a specific version of an xyzzy dependency, I could set up xyzzy as a development pod and point it to my local directory where I had checked out xyzzy from its Git repo. While I was working in the main app's project, any edits I'd do to xyzzy's files would be made in that directory. This let me build and test changes immediately, and when I was ready to check them in, Git would find them in the xyzzy project's directory.
Under Carthage I haven't found a way to do this. I see http://allocinit.io/ios/debugging-carthage-dependencies/ which explains how to create symbolic links so that I can see the dependency source files to make debugging easier, but any edits I make to them are under the main application's Carthage/Builds directory.
How do I set up the equivalent of development pods under Carthage?
I believe Carthage doesn't have something similar to "development pods" yet.
But you could simulate "development pods" just following these steps:
Steps:
Add the .xcodeproj to your workspace
Remove all the dependencies you have in your project of the framework you added in step 1. (probably you may need to remove it from Build Phases -> Run Script -> Input Files too )
Go to General tab of the target you want to run, add the framework under Linked Frameworks and Libraries (it is going to take the one added from the .xcoproj)
(optional) you may need to run carthage bootstrap in the framework's repo you want to add locally.
That's it.
After that you will be able to run your project and update framework's code in the same workspace.
This works just as well as development pods for me, as of Xcode 8.3.3 and Carthage 0.24.0:
In app path, rm -rf Carthage
Point at the appropriate branch or tag in Cartfile
carthage update --use-submodules (generates .gitmodules and clones repo into Carthage/Checkouts)
In Xcode under project -> Build Phases -> Run Script, comment out the line that ends with carthage update --cache-builds if present.
Change to the General tab and remove the lib from Embedded Binaries
Right-click project, Add Files to app..., add lib from Carthage/Checkouts
Under project -> General, re-add the library, choosing the one you added in the previous step.
App should now build with the local lib. Make sure that your .gitignore has Carthage/{Build,Checkouts} and .gitmodules.
This answer is a summary of a successful implementation of the solution introduced here.
A cleaner solution is using local paths for dependencies in Cartfile.
Environment
Xcode 10.1
macOS 10.13.6
Step 1. Symbolic linking
1.1 Change $(SRCROOT_MAIN)/Carthage/Checkouts/$(DEVELOPING_FRAMEWORK_NAME) directory to a symbolic link pointing to source root directory of your developing framework $(SRCROOT_DEVELOPING_FRAMEWORK), where $(SRCROOT_MAIN) is source root directory of your main app. Backup existing directories before this change.
This linking enables version-controlled changes in your developing framework.
Syntax when using ln utility,
$ ln -s "$SRCROOT_DEVELOPING_FRAMEWORK" "$SRCROOT_MAIN/Carthage/Checkouts/$DEVELOPING_FRAMEWORK_NAME"
1.2 Change $(SRCROOT_DEVELOPING_FRAMEWORK)/Carthage/Build directory in your framework to a symbolic link pointing to $(SRCROOT_MAIN)/Carthage/Build directory. Backup existing directories before this change.
This linking enables access to all frameworks built by Carthage from both your developing framework and your main app.
Syntax when using ln utility,
$ ln -s "$SRCROOT_MAIN/Carthage/Build" "$SRCROOT_DEVELOPING_FRAMEWORK/Carthage/Build"
Step 2. Framework Replacement

2.1 Remove your developing framework in Xcode > YOUR_MAIN_APP > General > Linked Frameworks and Libraries (that is, the one located in $(SRCROOT_MAIN)/Carthage/Build/iOS).
2.2 Add $(DEVELOPING_FRAMEWORK_NAME).xcodeproj (found in directory pointed by $(SRCROOT_MAIN)/Carthage/Checkouts/$(DEVELOPING_FRAMEWORK_NAME) symbolic link) into your main app
2.3 Build the developing framework product for device and simulator
2.4 Add the new developing framework auto-detected by Xcode in Xcode > YOUR_MAIN_APP > General > Linked Frameworks and Libraries.
2.5 Add $(DEVELOPING_FRAMEWORK_NAME).framework as a target dependency by adding $(DEVELOPING_FRAMEWORK_NAME).framework in Xcode > YOUR_MAIN_APP > Build Phases > Target Dependencies.
2.6 Copy $(BUILT_PRODUCTS_DIR)/$(DEVELOPING_FRAMEWORK_NAME).framework to $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/$(DEVELOPING_FRAMEWORK_NAME).framework by adding a new input file $(BUILT_PRODUCTS_DIR)/$(DEVELOPING_FRAMEWORK_NAME).framework and a new output file $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/$(DEVELOPING_FRAMEWORK_NAME).framework in Xcode > YOUR_MAIN_APP > Build Phases > Run Script of Carthage Embed Framework.
Reference
Debugging Carthage Dependencies
https://allocinit.io/ios/debugging-carthage-dependencies/
Build Setting Reference
https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html

How do I use SwiftyJSON in my iOS App?

I recently added SwiftyJSON into my xCode project using Carthage.
Cartfile
$ cat Cartfile
github "SwiftyJSON/SwiftyJSON" >= 2.1.2
I ran this command to install SwiftyJSON
$ carthage update
I added the built Framework to my xCode project
I imported the Framework at the top of my project
But I still get this error:
Use of unresolved identifier 'JSON'
Seriously, what am I doing wrong? I'm new to iOS development.
UPDATE: I tried removing the Frameworks and re-dragging the frameworks to the Linked Frameworks and Libraries and Adding the "Run Script" section to "Build Phases" as the instructions in Carthage asked.
I'm convinced that something went awry during the Carthage Update process because I received this error on my initial attempt:
$ carthage update
*** Fetching SwiftyJSON
*** Fetching Alamofire
*** Checking out SwiftyJSON at "2.1.3"
*** Checking out Alamofire at "1.1.4"
*** xcodebuild output can be found in /var/folders/0x/swzt630n3_575tglljpwhn4h0000gn/T/carthage-xcodebuild.Pc6rLg.log
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
*** Building scheme "Alamofire OSX" in Alamofire.xcworkspace
*** Building scheme "SwiftyJSON" in SwiftyJSON.xcworkspace
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
After looking up the problem, I was told that you could run
carthage update --configuration Debug
Which installed it fine, but something is still amiss...
It seems like you missed a step during the addition of SwiftyJSON and Alamofire frameworks from Carthage. Check out these steps from the Carthage readme page :
Steps :
Create a Cartfile that lists the frameworks you’d like to use in your project.
Run carthage update. This will fetch dependencies into a Carthage/Checkouts folder, then build each one.
On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.
On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script with the following contents:
/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input Files”, e.g.:
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework
$(SRCROOT)/Carthage/Build/iOS/SwiftyJSON.framework
Looks like you missed step 4. I tried these steps myself in a demo Swift project and they are working great. Try these steps out, and if you still have problems, leave a comment. Thanks!
I switched over to Cocoapods and it just worked. Again, I'm a total noob when it comes to iOS development. When looking for a dependency manger I looked at Cocoapods and Carthage for what they had to offer. I was intrigued by Carthage's claim of keeping things simple:
"Carthage because we wanted the simplest tool possible—a dependency manager that gets the job done without taking over the responsibility of Xcode"
While I always will choose the simpler tool when given a choice, I think I don't know enough of the iOS ecosystem (read: Xcode) to use Carthage.
TL,DR: Can't use it inside of Emulator, Use iPhone.
I also followed your way, and I found out that --configuration debug will code-sign "iOS Developer" identity as SwiftyJSON's project property.
AFAIK, Code-signed "iOS Developer" identity wasn't run with Emulator.
My issue was resolved when I run it at my iPhone 6.
I do not know why you can not add this resource with help of Carthage but if you need use SwiftyJSON you only need:
Enter this URL: SwiftyJSON
Clic the button "Clone or download" and then in "Download ZIP" like the next image shows:
Clic the button "Clone or download" and then in "Download ZIP" IMG
You will get a ZIP file with name "SwiftyJSON-master"
Extract the files
Enter the path:
SwiftyJSON-master/Source/
You will see a file with name:
SwiftyJSON.swift
Copy that file into the files of your project.
Add that file into your project directory.
That file will be like other class into your project that you may use.

Resources