Should I generate a native build when i add native libraries in react native 0.61+? - react-native

I have been using RN 0.61.+ for my android and ios app with Codepush for remote JS updates.
With react native auto-linking enabled in 0.60+. When we add a native library, there is no native code added in the android and ios folders except that we need to do a pod install for iOS.
Does this mean I can simply do update to users with JS Bundle on codepush? Or do I have to still create native builds and release on stores?

Yes you have to create new builds.
Here is why
When you add a new native library that supports auto linking you may not see any change in the Android folder but the magic happens in build time where the cli would go through the dependencies and link everything for you. In the case of ios as you said you install them using pod install.
I can simply do update to users with JS Bundle on codepush
You can do this but there is a high chance your app would crash during run time. Let say you update a library to a newer version and you update your JS Bundle, when your JS code access a newly added method in native code there will be a problem. If both signatures match it might work but its an unwanted risk.
So if you are adding a native library always go for a new build.

Related

Code-Push with CI/CD and native dependency changes

I am readying an app for release to the app stores and I'm concerned with CI/CD pipeline and Code-Push.
How does this scenario play out:
If a developer makes NPM dependency updates and there is a package updated that has native code changes that the JS relies on, will Code-Push still update the JS bundle on user devices ahead of their device downloading the native code updates?
Just so my question is clear, I'm not trying to OTA update native code - I'm referring to a situation where some package like react-native-device-info has native Java/Swift code and also has JS code that requires some api or event constant from the native code. If you bump the package version for react-native-device-info to a new release and there is changes to both native and JS code, would code-push have any way to know to not update the bundle until the native code/app was updated because the JS bundle has code that depends on the native code?
Or, am I thinking of using the tool Code-Push wrong?
The way codepush works is that it updates the JS bundle of your app. Your requirement is to update a NPM package which has a native change and update only your client side which is not possible.
If you do this you will probably end up with a crash of your app when the JS contacts the native code.
would code-push have any way to know to not update the bundle until the native code/app was updated because the JS bundle has code that depends on the native code?
Simple answer NO
Codepush is targeted on a version number so your new version which hits the stores will have a new version number so no point of updating the bundle of the old version of the app.
If you really want all your users to move to a new version push an alert or some sort of message using codepush asking the user to update.

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.

code push react native not changed library updates on users App

When I changed a library (like 'react-native-image-crop-picker') version on package.json and distribute it with code push in users app the version not changed.
They see older version of that library in app.
what should I do?
Code Push only works with JS code. It doesn't allow to push native binaries. In your case, you have to update app bundles in stores to update your native dependencies.
The CodePush plugin helps get product improvements in front of your end users instantly, by keeping your JavaScript and images synchronized with updates you release to the CodePush server.
Taken from Code Push docs.

How to recompile react native app without rebundling assets

I am working on a react native app, but on its native side.
If I run react-native run-android or run-ios it will first build
the native packages, to then start and complete the packager (at least for production). This process takes a long time. Is there a way to tell the script to use the latest built version of the assets, and just recompule the native binaries?
EDIT: I found out that you can add org.gradle.configureondemand=true to your gradle.properties, in order to skip bundleJsAndAssets. However, I can't find how to add the assets manually later.
you can install Webstorm IDE and then install React Native Console plugins for this.
Finally, link to the your project.
It's likely that you can see what you want

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.