React Native IOS, library linking is not working - react-native

I am working on react native application, I have updated react native version of my app. After installing packages and updating pods, I run command to link all libraries::
react-native link
But it doesn't work then I have tried manual linking, now there is no library file inside target -> Build Phases -> Link Binary With Libraries
If I am trying to add ".a" file it gives me an error.
I am quite surprised, my project still running properly on the simulator without linking to libraries.
You can check this image, I am using react-native-navigation. It's running properly without linking.
After adding the library I am getting "Dependency Analysis Error"
Unable to run command 'Libtool libReactNativeNavigation.a' - this
target might include its own product.
Now my project is running properly but there is no library inside "Link Binary With Libraries" section.
The environment I am using as follows::
react-native : 0.59.9
xCode: 10.1
react: 16.8.6
Please suggest to me what I am doing wrong here. Or is this right methodology?

Related

how to add ios support for existing React Native application with only Android support?

I know it might be very basic question. But I am very new and got a codebase with only android support. I need to add iOS for it. Please help me
As you're aiming to build a cross-platform app, React Native provides two ways to organize the code and seperate it by platform: platform module or platform-specific file extensions.
As you already have an Android app, I assume it has more complexity so you might want to split the code out into separate files.
You say you have an Android app but i don't thing that at any point you specified that the app should only build for Android (you can review in the package and the project configuration). So, the following command should be enough:
react-native run-ios
If you created your react native app from a template (e.g. using npx react-native init ProjectName), it already provides an ios and android folder, so it already supports it. If the file is not there, you could follow the instructions that #Rajan shared above to recreate the ios folder.
If your problem is running the iOS application using npm run ios, and its failing to build or the javascript throws an error, the quickest thing to try is cd ios, then pod install. If this does not work, it might be because you have additional dependencies you have installed, which require specific instructions and configuration to be done in the ios folder. This is library dependent, if needed, will be explained in depth in the README.md of the library. For example, react-native-firebase has a lot of steps, and is different to the android configuration.
Sometimes it is helpful to modify these configurations in XCode instead of editing the files manually (e.g. plist, xml, xproj). You can open xcode quickly using xed ios when in the root project folder.
Note: As usual, remember to have the libraries available in the node_modules folder, npm install.
In the future, you might choose to run different javascript code based on the platform (platform-specific code). React native allows that by using file.android.js and file.ios.js. However, your IDE is likely to struggle with the 2 files, and won't be as helpful compared to file.js. Alternatively, you can import Platform and conditionally check at runtime, what your platform is.
If you used Expo, you don't have access to the native code, but will already support iOS.

is it necessary to rebuild react-native project after linking

I would like to know if it's necessary to rebuild react native project after installing and linking libraries that includes native codes.
Yes, as react-native-link updates some native files that are under the ios/android folder, that won't be checked during a reload/hot-reload/live-reload. All those files aren't checked in your jsBundle and are compiled during a run-android or run-ios.
Of course, if you added a new dependecy to the project and linked it, and you haven't used it anywhere in your code yet, you don't need it. If you are using that dependecy, your project instance will, most likely, die.
if your react native version is below 0.60 then you have to run react-native-link after you install any react-native module. However after react-native version 0.60 and above, this is done automatically using the new "autolinking" feature added.
Read the changelog here:
https://facebook.github.io/react-native/blog/2019/07/03/version-60
However you still need to rebuild your project after you install a native module but you dont need to run the react-native-link command anymore after installing every library after react-native#0.60 and above. Just type react-native run-android

What is the right way to import custom react native module on Xcode?

I'm building a custom RN module for iOS and Android. Following some others modules, I notice that the dependencies it's never imported to the module itself, but always imported in the main app. For example for iOS:
react-native-admob has Google Mobile Ads SDK as dependency, but the developer has to add on the app.
That said, I have my custom module only building on Xcode, because when I try to run react-native run-ios I get the error:
info In file included from /Users/.../node_modules/react-native-my-module/ios/MyModuleViewManager.m:2:
/Users/.../node_modules/react-native-my-module/ios/RNMyModule.h:8:9: fatal error: module 'PrebidMobile' not found
#import PrebidMobile;
~~~~~~~^~~~~~~~~~~~
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening myapp.xcworkspace
What could I be doing wrong, that react-native command can't find the import library from Link Binary With Libraries?

Init IOS project with pods using react-native init command

Is there any way to create the IOS project with pods using react-native init command?
Currently there is different installation instruction for react native libraries.
Example: Some of them install using react-native link command while other requires to setup using cocoapods. Missing both will leads to lots of compilation errors.
Could anyone suggest what is best way to create project using react-native.
Thanks
On the official react native documentation, there are 2 ways to start up your project, which is using 'CRNA' or 'Build With Native Code'.
For CRNA, it is the fastest and easiest way to start up your project.
It really easy to run your React Native app on a physical device without setting up a development environment. If you want to run your app on the iOS Simulator or an Android Virtual Device, please refer to the instructions for building projects with native code to learn how to install Xcode and set up your Android development environment.
The react native link is used if you want to link your library through the terminal. But in some cases, there are several problem occurred related to library compatibility. I rather suggest use pods or manually link your library through XCode.
Pods is a dependency manager for native code that we use on our native code project. It will automatically generate and link the library.
If you want to have pods on your ios project. After you install cocoapods, you could follow these steps :
1. Open terminal and direct to your project (cd YOUR_PROJECT/ios
2. pod init
3. And then Podfile will be generated within the ios project.
And from now on, you should use YOUR_PROJECT.xcworkspace if you want to manage the project. Thats because Pods should be placed and included same with your project but '.xcodeproj' does not include your Pods.

Linking a your own library with native code on React Native

I build my own library for react-native and I want to make it available to the public. However, my library have some native implementation.
I want to use make the linking through react-native link avaialable, but I don't know how to start.
I have been looking on the RPNM project but I can't figure how to add it.
Today I basically have to do everything manually. Adding the compile dependencies on the build.gradle files.
How to automate my library linking using react-native link?