I'm trying to understand the difference between the autolinking that exists in React Native 0.60+ and the automatic / manual linking we have in previous React Native versions.
When I add react-native-gesture-handler with npm i react-native-gesture-handler, no lines are added to my Podfile. So when I do pod install, I assume the Gesture Handler module isn't linked. However, if I link it manually as I did with previous React Native versions, by dragging the .xcodeproj files into Libraries etc, it throws an error and tells me to unlink it.
What I Want To Know:
Am I right that what autolinking does is adds a line for the given module to your Podfile, which then gets linked when you pod install? If so, why might it be that when I did npm i react-native-gesture-handler nothing was added to my Podfile? And given that nothing was added and linking the module manually throws an error, how should I link the module?
When you create a new project and react-native version >=60 , this line is automatically added in pod file (official site)
# example/ios/Podfile
require_relative '../../node_modules/#react-native-community/cli-platform-ios/native_modules'
This is path of script , so when you run "pod install" , it will check all libraries and install all pods files required
So when you add new library , no lines are added to my Podfile but you have to run "pod install" so that script file can run and install new pod files .
Please do not use manual linking as described in official site
This means that all libraries need to ship a Podspec either in the
root of their folder or where the Xcode project is. Podspec references
the native code that your library depends on.
The implementation ensures that a library is imported only once. If
you need to have a custom pod directive then include it above the
use_native_modules! function.
You have to do 2 steps
1 : Add library "yarn add react-native-gesture-handler"
2 : cd ios && pod install
Related
I'm following instructions here to add a package: https://github.com/joltup/rn-fetch-blob
It says to do npm install OR add to Podfile. What I did was
yarn add rn-fetch-blob
Then
cd ios
pod install
Is that correct? I didn't edit the Podfile but somehow it still knew to get the dependency. Output:
Analyzing dependencies
Downloading dependencies
Installing rn-fetch-blob (0.12.0)
Generating Pods project
Integrating client project
The Podfile doesn't have any reference to rn-fetch-blob. Can someone explain if I did it right or if I needed to edit the Podfile?
When you do pod install, it actually looks into your package.json dependancies to see what dependency requires pod installation. As you have already added it to node_modules but not in Podfile.
Assuming that you are using the latest React Native version like 0.60 and above, this process is simply called Autolinking
Basically, whenever you add a new library to your package.json as you did for rn-fetch-blob and run pod install after adding it, the whole node_modules folder is being scanned thanks to a script file called native_modules.rb to find an appropriate podspec file and install what is necessary to install a pod.
This is the definition of how iOS auto-linking works from the community docs:
Platform iOS
The native_modules.rb script required by Podfile gets the package
metadata from react-native config during install phase and:
Adds dependencies via CocoaPods dev pods (using files from a local
path). Adds build phase scripts to the App project’s build phase. (see
examples below) This means that all libraries need to ship a Podspec
either in the root of their folder or where the Xcode project is.
Podspec references the native code that your library depends on.
I am facing an error while making a flutter plugin on the iOS side while using pods. The pods are installed successfully then also I am able to import them in the file.
The pod in my case which I am trying to use is Freshchat iOS SDK
Steps I have followed to install the pod
Start a new Flutter plugin project.
In .podspec file add s.dependency 'FreshchatSDK'
Run pod install in example/ios folder.
I got an error
The 'Pods-Runner' target has transitive dependencies that include statically linked binaries: (/Users/nimish/FlutterProjects/freshchat_flutter/freshchat_flutter/example/ios/Pods/FreshchatSDK/FreshchatSDK/libFDFreshchatSDK.a)
I removed use_frameworks! from podfile following this comment .
I ran pod install again and the pods were successfully installed and Pods folder was created which had FreshchatSDK folder in it.
Now I need to have use_frameworks! in my project because other plugins are not compiling because of this.
I added s.static_framework = true in .podspec and use_frameworks! in podfile. Now pod install ran successfully,
After I added the import #import "FreshchatSDK.h" in my Plugin.h file I got the error
error: include of non-modular header inside framework module
I tried this answer but was not able to resolve it.
Please help me resolve this. I'll be respectful of your time.
There is another flutter plugin available here but it has many issues and one unhandled case is making my iOS app crash so I want to make it my own.
There may be problems in the PodFile due to unmatched Targets.
When this happens to me, I used these simple steps.
Delete Podfile
Open Terminal at the specific file
Pod init
Open Podfile and adds Dependencies
Pod install
I created a new React Native 0.60.5 project using react-native init, and added the two modules react-native-vector-icons and react-native-device-info using npm i react-native-vector-icons and npm i react-native-device-info, respectively. However, neither .xcodeproj file appears in my Libraries folder as they normally would, and nothing changes in my Podfile. I haven't tested out if they work in the actual project yet, but just noticed this unusual behaviour and wanted to understand why.
From React native version >= 0.60 Autolinking feature is added , you do not have to run link command .
When you install library using npm/yarn , the library is auto added in pod file and files will not be added in ".xcodeproj"(it is for project with out pod but in react native >= 0.60 , pod is mandatory) .
You just have to run this command
cd ios && pod instal
I am trying to link the #segment/analytics-react-native library in my iOs react-native project.
I followed these two steps given in their docs.
yarn add #segment/analytics-react-native
yarn react-native link
However the yarn react-native link step doesn't seem to work, as all it does is add a pod in the podfile, and modify some android project files that I don't need.
The project.pbxproj file is showed as modified but when I inspect it inside vs code, the only thing it does in that file is removing a line.
Please explain why is this happening
From the docs about linking
If your iOS project is using CocoaPods (contains Podfile) and linked
library has podspec file, then react-native link will link library
using Podfile.
This means that it will not add the dependencies inside your Xcode project.
If you are happy with this then make sure you cd into you iOS folder and run pod install
If you don’t want it installed via CocoaPods then you can either install it manually using the instructions on the dependencies repo (remembering to delete the line added to your pod file); or you can rename your podfile, run react-native link so it adds the files without the updating the podfile, then rename the podfile back to what it should be.
One further point to note you shouldn’t run react-native link without the dependency name. You should run react-native link <dependency name>. You can end up with duplicate entries and unforeseen issue if you don’t.
I spent my day trying to fix my problem, I tried every solution I found in other SO posts but unfortunately I can't figure out how to solve my problem.
I try to integrate TouchID inside my react-native project. I downloaded a npm package called "react-native-touch-id" (sounds perfects !). I followed installation guide and I manually linked library to my project.
But when I try to run application I get the following error :
I tried to clean my project :
rm -rf node_modules
yarn cache clean && yarn install
rm -rf ios/Pods/ && pod install
In xCode I even clean the build folder.
About my versions :
RN : 0.57.4
xCode : 10.1
react-native-touch-id : 4.3.0
Here's my Podfile :
def available_pods
pod 'TouchID', :path => "../node_modules/react-native-touch-id"
end
target 'App' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
available_pods
end
I added the .xcodeproj of react-native-touch-id package inside my project's libraries directory and in Build Phases I linked it.
But I still getting the same error again and again ... I don't understand why ... If someone have an idea some help would be really appreciated :)
It appeared the problem was the Podfile. It seems that Podfile use its own Podspec which caused troubles. So I simply delete the TouchId pod declaration from my Podfile, clean and re-install my pods.
Then, I manually linked the library to my xcode workspace. To do that, under your project name, Right Click on Libraries directory => Add files to "your project name" => Add the xcodeproj of the npm's package located inside your node_modules directory.
After that, in your project Build Phases under the Link Binary with Libraries you have to add the npm's package static library (example libTouchID.a in my case).
To be sure you can clean your project and try to rebuild, it should work now.
For information, I kept all of my softwares version I mentionned above.
If it shows react native(missing) in
product->scheme->manage scheme->project name->build
remove the ios folder
react-native eject
cd ios/
pod init
pod install
cd ..
react-native link
cd ios
open *.xcworkspace/
this happens when the react native package is not linked properly to the ios build. The npm link does it.