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
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 have flutter module added to the existing iOS app. Not all but few of the packages installed (via pubspec.yaml file) could not be found by the iOS app when compiled, and I'm getting 'Module not found' error in XCode. Those problematic packages are: razorpay_flutter, google_maps_flutter, webview_flutter, and url_launcher until now. Please have a look at screenshot below:
Same is the case with other 3 packages.
Steps to reproduce issue:
Add razorpay_flutter: ^1.1.3 in the pubspec.yaml file of the
flutter module
Run flutter pub get. The package will install
Run Xcode project to which flutter module is added. Got error!
One more thing I observed after step 2, that there is some warning regarding issue for add to existing app:
Running "flutter pub get" in lib_smazing...
The plugin `razorpay_flutter` is built using an older version of the Android plugin API which assumes that it's running in a full-Flutter environment.
It may have undefined behaviors when Flutter is integrated into an existing app as a module.
The plugin can be updated to the v2 Android Plugin APIs by following https://flutter.dev/go/android-plugin-migration.
I guess there is issue with the packages using platform channel/code when added to an existing app, but not sure whether its package-specific issue or a flutter issue with add-to-app.
After few trials and error I found simply running pod install on iOS project directory fixed the issue.
Rather trivial but realized my packages were not found because I opened and executed the wrong file in XCode - so open Runner.xcworkspace and not Runner.xccodeproj
There are multiple solutions available for any kind of library/module not found.
Solution # 1
flutter clean
flutter run again
rebuild it from ios or vscode tool again.
if still problem
pod update
pod repo update
pod install
Solution# 2
delete build folder
delete pod.lock file
delete .syslinks folder
delete pods folder
change your directory in your terminal by
cd ios
pod install --repo-update OR pod repo update
pod install
flutter clean
flutter pub get
Solution# 3
please open Runner.xcworkspac with xcode because app will get local
lib from pod install lib that installed. , but don't Runner.xcodeproj
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
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.