I am not iOS engineer so installing react-native library was really hard.
I managed to install react-native-linear-gradient finally so write this article here to remember my struggle.
An awesome library to create gradation component in React Native.
The api is clear, easy to use.
But its installation process is really complicated. Every time Xcode creates lots of errors.
DO NOT USE CocoaPods
Instead, manually install it.
It looks obviously to use cocoapods. If you are web engineer, it is common to use package management system such as npm, yarn, composer, rubygem, pip, and so on.
But in React Native with Xcode projects, that common sense does not work. If you use CocoaPods, you will face Linker Error every time you build, fetch packages,
I don't know this problem is because of CocoaPods or ReactNative or
react-native link or Xcode.
(There is CocoaPods alternative named
Carthage so I will try it someday.)
Let's show how I struggled to install rnlg.
First I used CocoaPods to install rnlg. Its Readme said we should do:
yarn add react-native-linear-gradient react-native link
Oh it's quite simple. Just two commands we could add a library. Great.
I hit the commands and
open MyProject.xcworkspace with hope.
Then I faced this error:
Apple Match O Linker error ld: Framework not found: BVLinearGradient
This might be because Xcode cannot recognize third party framework.
I tried a lot of things:
Framework search paths
pod React, :path => '../node_modules/react-native/React'
pod yoga, :path => '../node_modules/react-native/ReactCommon/yoga'
- Clean build
- Delete derived data
- add GCC settings
But I couldn't solve problems.
In this round, I searched google a lot and found many issues.
React Native is new and its development speed is very high. So solutions over half a year ago are not reliable today.
At this point, I noticed that CocoaPods might cause problems.
CocoaPods is really kind guy. It resolve dependencies, download source and stati binary, then link library with Xcode project.
But it does not set correct settings sometimes.
react-native link links node_modules and Xcode automatically but sometimes the paths is not correct.
So in this round I decided not to use CocoaPods to install rnlg.
I read README again. IT contains procedure for manual installation.
I did the procedure and got this error:
Duplicate interface definition for class 'RCTView'
Thanks to this issue I fixed it. https://github.com/shoutem/ui/issues/134
solved the problem and everything goes well.
It is bothering to modify import path manually after install packages, so I wrote a script to do this:
#!/bin/bash find ./node_modules/react-native-linear-gradient/BVLinearGradient/ -type f \ | xargs perl -i -pe 's/"(RCT.+\.h)"/<React\/\1>/'
It is unstable to use libraries without much understanding. Someday it brakes your code.