How to install extensions on React Native installed with Cocoapods? - ios

I just installed React Native following the instructions here:
http://facebook.github.io/react-native/docs/embedded-app-ios.html#content
However, I don't know how to install third-party extensions like react-native-icons. What I have tried so far is to npm install react-native-icons in ReactComponent directory. But when I run the app, it shows the error saying that react-native-icons cannot require react-native, which is understandable since react-native is NOT in node_modules. So what is the correct way to install extensions when React Native is installed with Cocoapods? Any hint is appreciated!

If the extension you want to use does not have one, you will need to create a Podspec for it. You can copy over most of the info from the extension's package.json file.
An example podspec, taken from https://github.com/fraserxu/react-native-couchbase-lite/blob/master/ReactNativeCouchbaseLite.podspec
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = "ReactNativeCouchbaseLite"
s.version = "0.2.2"
s.summary = "couchbase lite binding for react-native"
s.license = 'MIT'
s.platform = :ios, '7.0'
s.requires_arc = true
s.authors = "Fraser Xu <xvfeng123#gmail.com>"
s.homepage = "https://github.com/fraserxu/react-native-couchbase-lite.git"
s.source = { :git => 'https://github.com/fraserxu/react-native-couchbase-lite.git' }
s.source_files = 'ios/**/*.{h,m}'
s.dependency 'couchbase-lite-ios'
s.dependency 'couchbase-lite-ios/Listener'
end
Once you've confirmed its working, go ahead and send the author a pull request with the Podspec file like I did :)

Related

What should be the Podspec file for using local .xcframework in React Native library?

I created a React Native library that is a wrapper for using the native iOS framework in the React Native Projects. Earlier I was using .framework & it was working fine. Now I am facing an issue in using this library with .xcframework instead of .framework.
I added this library as a dependency to the project & then on running pod install getting the below error:
[!] [Xcodeproj] Generated duplicate UUIDs:
When I opened the project & try to build it, it builds successfully for the device but fails on the simulator.
Below is the Podspec file that I am using in the library project:
Pod::Spec.new do |s|
s.name = "react-native-myLibrary"
s.version = "1.0.0"
s.summary = "react-native-myLibrary"
s.description = <<-DESC
react-native-myLibrary
DESC
s.homepage = "https://github.com/geektimecoil/react-native-onesignal"
s.license = "MIT"
s.author = { "author" => "author#domain.cn" }
s.platform = :ios, "10.0"
s.source = { :http => 'file:' + __dir__ + '/' }
s.source_files = "**/*.{h,m,swift}"
s.requires_arc = true
s.vendored_frameworks = 'MyLibrary.xcframework'
s.dependency "React"
end
On searching for the solution I found that this error is caused by s.source_files = "**/*.{h,m,swift}". So, I commented this line & run pod install again. The error was gone but no dependency is being added to the Project target. Can anyone provide me the Podspec file to use for local .xcframework in React Native Library. Thanks in advance!
I was able to fix this issue using:
s.source_files = "ios/*.{h,m,swift}"
s.vendored_frameworks = 'ios/Frameworks/MyLibrary.xcframework'
& also by updating the Framework Search Paths from the Build Settings to $(inherited).
Try this:
s.preserve_paths = 'MyFraemwork.xcframework/*'
s.source_files = 'MyFraemwork.xcframework/ios-arm64_armv7/PicUPSDKv3.framework/Headers/*.{h,m,swift}'

Conflicts with FlutterFire and native GeoFire plugin on iOS

I'm getting an error when I'm trying to add GeoFire to my iOS Flutter project which has the FlutterFire Database plugin included. This is what the error looks like:
Resolving dependencies of `Podfile`
[!] Unable to satisfy the following requirements:
- `Firebase (~> 2.1)` required by `GeoFire (1.1.0)`
Specs satisfying the `Firebase (~> 2.1)` dependency were found, but they required a higher minimum deployment target.
My podspec file looks like this atm:
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'geofire'
s.version = '0.0.1'
s.summary = 'A new flutter plugin project.'
s.description = <<-DESC
A new flutter plugin project.
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => 'email#example.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'GeoFire', '>= 1.1' # Adding GeoFire
s.ios.deployment_target = '8.0'
end
I also tried using the git page in to add Geofire in my podspec file as suggested here: GeoFire giving problems with CocoaPods
s.dependency 'GeoFire', :git => 'https://github.com/firebase/geofire-objc.git'
Is there a (simple) solution for this?
I faced the same kind of issue few days ago.
I think I fixed it by doing the following steps:
Run the command 'pod repo update' (it will update your repo information)
Then run the command 'pod update' (it will update your pods using the latest repo information)
Let me know if this is solving your issue :)
Please try the approach suggested by Bjørn Børresen here:
Since Flutter kind of abstracts away this Cocoapods process. Here's what I did to be able to run "pod repo / update":
Run pod repo update
Set the environment variable FLUTTER_FRAMEWORK_DIR to something that looks like /Users/youruser/bin/flutter/bin/cache/artifacts/engine/ios/. You can do a locate Flutter.podspec to find this directory
From YourFlutterProject/ios run pod update
After this you should be able to run your app again

Cannot Lint/Push a Swift Cocoapods podspec

I tried to create my first podspec combining ObjC and Swift code, but I soon stumbled uppon a stubborn error that I cannot solve while uploading
Copying MyLibrary from /Users/lukasschwoebel/Library/Caches/CocoaPods/Pods/External/MyLibrary/540307feb534d63ad9015f3f6452b3ad-be661 to
../../../../../../private/var/folders/2p/_pc_vts51b3_pfydgm7_2n200000gn/T/CocoaPods/Lint/Pods/MyLibrary
- Running pre install hooks
-> MyLibrary (0.1.0)
- ERROR | [iOS] Encountered an unknown error (Pods written in Swift can only be integrated as frameworks; this feature is still in beta. Add use_frameworks! to your Podfile or target to opt into using it. The Swift Pod being used is: MyLibrary) during validation.
Here is the command I use:
pod repo push test-podspecs MyLibrary/MyLibrary.podspec --use-libraries --allow-warnings --verbose
As you might see, this is the minimum untouched sample project from CocoaPods as described here: https://guides.cocoapods.org/making/using-pod-lib-create.html
As I can not even make this sample running, I suspect something wrong with my cocoapods configuration.
I made sure there is no single Objective C line in the pod that is to be uploaded (though in the end, I would like to have a podspec with ObjC and Swift code mixed, but at this time I just want to have a working podspec with Swift).
I cannot even upload this simple pod with pure Swift. I first tried with CocoaPods v0.39.0, then downgraded to 0.38.2 and after that 0.38.0, even 0.36.0. Even with a complete un-install of CocoaPods.
It seems I need to configure something in CocoaPods to be able to upload a Swift podspec? The error I get obviously is during the building-phase of the pod where the Podfile needs use_frameworks! to be included. So how can I make CocoaPods use it while compiling the pod during the podspec verification?
Also, I have Xcode 7.0.1 and OSX 10.10.5 installed and it is Swift 2.0 code.
Thank you in advance!
Here is the complete podspec, adapted from the original created MyLibrary.podspec (and yes, that is a local Podspec-Repo, but that does not cause/change the error)
Pod::Spec.new do |s|
s.name = "MyLibrary"
s.version = "0.1.0"
s.summary = "A short description of MyLibrary."
s.description = 'Sample Description'
s.license = 'MIT'
s.author = { "Luke A." => "ls#mymail.to" }
s.source = { :git => "file:///Users/.../test/MyLibrary/", :tag => s.version.to_s }
s.platform = :ios, '8.0'
s.requires_arc = true
s.source_files = 'Pod/Classes/**/*'
s.resource_bundles = {
'MyLibrary' => ['Pod/Assets/*.png']
}
s.frameworks = 'UIKit'
end
I just found the answer, which seems a little obvious.
The command to upload/push the pod was in a bash-script so I did not always have to type all the flags but just and over the filename/path to the podspec. So in the default bash-script I had the flag --use-libraries which is required for one of my pods.
As I was trying something out and had a typo in the pod repo push .. command I stumbled across the man-page:
--use-libraries
Linter uses static libraries to install the spec
With static libraries, this flag seems to be incompatible with Swift podspecs. Removing that flag lints and pushes my podspec successfully.

Building a Cocoapod with Swift and dependency on Objective-C framework

I know there are already a few questions on this theme here on SO, but very few have accepted answers, and I don't think I have found the exact same problem as mine.
I'm building a Swift pod, and in my code I rely on the Google Maps iOS SDK, which is bundled as a .framework file. The project builds OK in Xcode, however I have troubles publishing the lib to Cocoapods.
I managed to have a Podspec file that almost validates using the pod lib lint command. However, now that I've added the Google-Maps-iOS-SDK pod as a dependency in the Podspec file, it fails with the following message:
$ pod lib lint
[!] The 'Pods' target has transitive dependencies that include static
binaries:
(/private/var/folders/n2/qyjfpk6n7zz_mngtwswlmsy00000gn/T/CocoaPods/Lint/Pods/Google-Maps-iOS-SDK/GoogleMaps.framework)
$
Is this expected? Why can't I add the Google Maps iOS SDK as a pod reference in my own Swift-based pod?
Here's the Podspec:
Pod::Spec.new do |s|
s.name = '(name)'
s.version = '1.0.0'
s.summary = '(summary)'
s.platforms = { :ios => '8.0', :osx => '10.10' }
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10'
s.license = { :type => 'BSD', :file => 'LICENSE' }
s.source_files = 'Sources/*.{h,swift}', '*.framework'
s.source = { :git => "https://github.com/(Github repo).git", :tag => "1.0.0" }
s.requires_arc = true
s.frameworks = "Foundation", "CoreLocation"
s.author = { 'Romain L' => '(email)' }
s.dependency 'Google-Maps-iOS-SDK'
end
If I don't include the Google Maps iOS SDK as a dependency, then pod lib lint fails in the Bridging Header, and complains it cannot find <GoogleMaps/GoogleMaps.h> (file not found).
I'm stuck, and I don't know if it's a bug from Cocoapods 0.36 (still in Beta) or if I'm doing something wrong.
Thanks for your help!
I finally found another thread on SO dealing with similar problems: Linker errors in a Swift project with Google Maps for iOS added via CocoaPods.
It appears that the errors were due to a combination of bad Podspec file (on the Google Maps iOS SDK side), and bugs in Cocoapods 0.36 Beta.
It's actually possible to workaround the issues by using #fz.'s revised Podspec file for Google Maps: https://stackoverflow.com/a/28471830/145997. Another article that also was of great interest to understand how the vendored_frameworks setting works in Podspec is: http://codereaper.com/blog/2014/creating-a-pod-with-crashreporter/.
So, to correctly import the Google Maps iOS SDK in a Pod project, first use the following Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
# altered version of Google's Podspec
pod 'Google-Maps-iOS-SDK', :podspec => "https://raw.githubusercontent.com/Reflejo/GoogleMapsPodspec/master/Google-Maps-iOS-SDK.podspec.json"
use_frameworks! # don't forget this!
I'm now able to reference Google Maps classes from my Swift code simply by doing import GoogleMaps. And, to distribute the Pod, my final Podspec now resembles the following:
Pod::Spec.new do |s|
s.name = 'MyPod'
s.version = '1.0.0'
s.homepage = "https://github.com/..."
s.summary = '(pod summary)'
#s.screenshot = ""
s.author = { 'Romain L' => '(email)' }
s.license = { :type => 'BSD', :file => 'LICENSE' }
s.social_media_url = "https://twitter.com/_RomainL"
s.platforms = { :ios => '8.0' }
s.ios.deployment_target = '8.0'
s.source_files = 'MyCode/*.{h,swift}'
s.module_name = 'MyPod'
s.source = { :git => "https://github.com/....git", :tag => "1.0.0" }
s.requires_arc = true
s.libraries = "c++", "icucore", "z" # required for GoogleMaps.framework
s.frameworks = "AVFoundation", "CoreData", "CoreLocation", "CoreText", "Foundation", "GLKit", "ImageIO", "OpenGLES", "QuartzCore", "SystemConfiguration", "GoogleMaps" # required for GoogleMaps.framework
s.vendored_frameworks = "Dependencies/GoogleMaps.framework" # Put the Google-provided framework in that subfolder of your Pod project
#s.dependency 'Google-Maps-iOS-SDK' # Careful! this will cause errors if enabled!
end
I am now able to start a new iOS app in Xcode and use the following Podfile to link against my own pod, itself referencing the Google Maps iOS SDK:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'MyPod'
use_frameworks! # do not forget this!
Not that easy, but feasible after all! Hoping Google will soon patch its Podspec file for Swift developments, though.

Podspec validates but files are not installed

I'm in the process of writing my very first pod spec, and while I have managed to write a spec that passes validation and pod install seems to install the pod OK the actual source-files are nowhere to be found in my workspace. This is my podfile:
platform :ios, '7.0'
xcodeproj 'NORLabelNodeiOStest'
pod 'NORLabelNode', :path => '~/Programmering/Development/NORLabelNodePodSpec'
pod 'AFNetworking'
As you can see the NORLabelNode pod is installed through a local version of the podspec which looks like this:
Pod::Spec.new do |s|
s.name = "NORLabelNode"
s.version = "0.9.2"
s.summary = "Extension of Apple's SKLabelNode. Allowing multiple lines through the use of \n in the text-string. "
s.description = <<-DESC
Behaves like an ordinary SKLabelNode with the one difference that adding newline characters to the text- property actually adds line-breaks. This is achieved by creating SKLabelNodes as child-nodes, but keeping these as part of the internal (private) logic.
DESC
s.homepage = "https://github.com/nickfalk/NORLabelNode.git"
s.license = 'MIT'
s.author = { "T. Benjamin Larsen" => "benjamin.larsen#noreagle.no" }
s.source = {
:git => "https://github.com/nickfalk/NORLabelNode.git",
:tag => 'v0.9.2'
}
s.social_media_url = 'https://twitter.com/noreagle'
s.platform = :ios, '7.0'
s.ios.deployment_target = '7.0'
s.osx.deployment_target = '10.9'
s.requires_arc = true
s.frameworks = 'SpriteKit'
s.source_files = 'NORLabelNode.{h,m}'
end
Running pod install gives no indication that anything has gone amiss:
Analyzing dependencies
Fetching podspec for `NORLabelNode` from `~/Programmering/Development/NORLabelNodePodSpec`
Downloading dependencies
Installing AFNetworking (2.2.3)
Installing NORLabelNode (0.9.2)
Generating Pods project
Integrating client project
[!] From now on use `NORLabelNodeiOStest.xcworkspace`.
The AFNetworking pod installs the files as expected, but my own NORLabelNode does not. Anyone?
As you can see the NORLabelNode pod is installed through a local version of the podspec which looks like this
That's not how the path option works. It expects a path to the project itself, not the spec.
From the docs:
Using this option CocoaPods will assume the given folder to be the root of the Pod and will link the files directly from there in the Pods project.
If you would like to just use your spec without adding it to the master repo you can create your own repo of specs (docs). Or just place your spec in the correct folder structure in ~/.cocoapods/repos/master

Resources