What are the difference between these React Native start commands? - react-native

I have been using react native for a couple months now. However, I really don't know the difference between the starting commands. Currently, I use npm on my project. However, I know yarn can be used. These are the commands I really don't understand the difference with:
exp start, exp ios, exp android
react-native run-ios, react-native run-android
npm start, npm ios, npm android
Which ones are better in what cases and why? Currently, I am using exp but others use react-native run-ios. I used to use npm ios.
Thank you in advance.

It might help to have an overview of the React Native architecture.
In react native, when you write, say, <View/>, it gets sent across the bridge to the native code and dynamically translated into UIView on iOS or android.view.View on Android. Every basic component in the react-native package has been implemented this way. If you want additional native functionality on both platforms, say a library which uses native map components, you will end up having to include the native libraries separately into your Android build.gradle and your iOS .xcodeproj.
The exp CLI is used to start apps built with the Expo SDK. Expo is essentially a prebuilt app with a certain set of native components already included for convenience; all you supply is your JSX; thus the recommendation to "eject" to a regular react native app if you need to use any other libraries.
react-native run-ios and run-android builds the native .app or .apk using the iOS or Android toolchains, starts the Metro Bundler, which minifies and serves the JSX and other assets such as images over to your device in debug mode (You might see something like Loading from localhost:8081).
On Android, it starts the adb server to push the APK with all the native libraries included onto your device, if you have USB debugging enabled. run-ios does the same with the .app; if you install to a simulator it has automatically configured AppDelegate.m to communicate with localhost:8081, whereas live reload over USB has to be configured manually on a physical device.
react-native start simply starts the Metro bundler, which is useful if you already have the app installed.
Commands that begin with npm are defined as scripts in your package.json file. As of RN 0.57, npm start simply calls node node_modules/react-native/local-cli/cli.js start; which is the same as running react-native start; according to the docs react-native-cli installed separately will call the locally installed version of the CLI in node_modules.

Related

ReactNative, What's the benefit of using expo bare workflow?

There was create-react-native-app just like create-react-app
However I see https://github.com/react-community/create-react-native-app has been merged to expo.
Since I need native (android or ios) support, I can do either of theses
expo bare workflow
https://docs.expo.io/versions/v34.0.0/bare/exploring-bare-workflow/
react native init
https://facebook.github.io/react-native/docs/getting-started (react native cli quickstart)
What do I gain by going through expo bare workflow?
If you use Expo, you can use the module in Expo. Of course, Expo needs to install modules for APK availability starting with SDK33. However, you do not need to link the Expo separately.
If you use Expo, it will automatically reload the code when it is refreshed and not restarted, making it easy to see the code change.
And with fast feedback, the development cycle will be faster. Because the process of communicating from simulator to native apps is still slow, build time will be increased when using Web versions that run directly into the browser, until HMR creates a basic framework for the app because it is fast and fully available with Chrome Developer tools.
Also, if you want to install a React-native module that requires a link, you can use the 'expo eject' command to eject Expo. Then you can use React-native.

Ejected expo react native app requires expo?

I created a RN with create-react-native-app, and I have now decided to eject. It didn't work initially, and required some packages to be installed (#babel/...), but now, it complains that Module 'expo' does not exist in the Haste module map.
Why does it still require expo, now that it has been ejected? Or have I misunderstood what ejection does?
N.B. during the ejection I chose the option to eject to an RN app, not to ExpoKit. This is on iOS, currently.
When ejecting expo app you'll be asked about using expo-kit or just react-native and it's up to you to choose, plus Module 'expo' does not exist in the Haste module map means you still using expo in your code so double check your code to be sure that you're not importing expo anywhere and try again.
TL;DR
Ejected expo react native app requires expo? the short answer is no.
when using expo app you have the ability to build your app using the expo server so you don't have to have Android Studio or XCode installed all you have to do is $ expo build:[android|ios] and download your built package after the build process is done also you can run your app using expo client app on Android and Ios but once ejecting you'll lose the ability of using expo server as your build environment instead you have to use Android Studio or XCode, but the main difference here is when you choose expo-kit you still have the ability of using expo client to run your app and you still have the ability to use expo modules inside your code but when you choose react-native you can't use expo client instead you have to use the native tools, anyway in all cases once you eject your project you have to build it yourself and you can't undo this step.
Sidenote
You can build very powerful apps using only JavaScript without any need to eject especially when using `expo SDK 31+, I'm working on an app now with features like detecting location, live maps, social login and chat and I don't need to eject it at all.
Please take a look here and here
Update:
One last thing you have to remember is that when using expo or expo-kit you can keep developing ios app on any OS but when using react-native you can't do this you MUST have a mac.

Expo React-Native App doesn't work when run as a standalone APK

My Expo-based React Native App works without a problem when run in the Expo tool but gave the following errors when built as an APK to be installed and run standalone.
A series of white screens keep flipping before the blue screen comes up.
Here are my App.JSON and Package.JSON files
Package.json
App.json
And here are the screen capturing the error message.
Actually there are two ways to create a React Native application
create-react-native-app (CRNA)
react-native init
As you stated in comment section, You created your project using CRNA
CRNA will gave you some form of solid project structure, which is really useful for beginners to get started with react native, you code the app with pure javascript and the app will work inside Expo.
Now if you want to take build and run as a standalone apk for android,
There are two methods
You can run command: exp publish:android
You can eject your app from expo
Dont use exp publish for standalone apks,
You can use second method:
To eject your app:
First if you dont use any expo apis inside your apps, it is very easy to eject and build as a stand alone apk.
just do yarn eject
This will gave you some instructions and follow that.
After that your CRNA project structure will be converted into react-native init project structure, now you will be able to see "Android" and "iOS" folders inside your application
To take build Run: connect your phone with USB debugging ON and react-native run android.
That's all.
Solved my own problem. The 'eth-lightwallet' library works perfectly within the Expo development tool but when I build into an APK, it just made the white screen turns up with no meaningful error messages.
The solution is to replace it with a pure web3js implementation.
This may be useful if you are developing a mobile app for Ethereum.

Uninstall expo sdk and setup firebase instead

We developed a React Native application with Expo Kit SDK. Now, We would change the native full Firebase SDK, but before we have to uninstall Expo SDK (Expo doesn't support external native sdk services). Is there a best practice to do that as easy as possible?
Hey I believe for Expo it's called detaching, like CRNA is ejecting...
https://docs.expo.io/versions/latest/expokit/detach
1. Install exp
If you don't have it, run npm install -g exp to get our command line library.
If you haven't used exp or XDE before, the first thing you'll need to do is log in with your Expo account using exp login.
2. Make sure you have the necessary keys in app.json
Detaching requires the same keys as building a standalone app. Follow these instructions before continuing to the next step.
3. Detach
From your project directory, run exp detach. This will download the required dependencies and build native projects under the ios and android directories.
4. Set up and Run your native project
Congrats, you now have a native project with ExpoKit! Follow the directions under Developing with ExpoKit to get things set up and running.
5. Make native changes
You can do whatever you want in the Xcode and Android Studio projects.
To add third-party native modules for React Native, non-Expo-specific instructions such as react-native link should be supported. Read more details about changing native dependencies in your ExpoKit project.

react-native-azure-ad not launching with latest update of Expo app

To fix it, I also update iphone to the latest version.
Is it an issue with react-native-azure-ad OR expo ?
Getting below error:
If you get this error:
ScrollView has no propType for native prop RCTScrollView.onScrollAnimationEnd of native type BOOL
If you haven't changed this prop yourself this usually means that your versions of the native code and JavaScript code are out of sync. Updating both should make this error go away.
It's very likely that your device is trying to run JS code that doesn't correspond to the native code on your device. The first thing to do is look at your Expo SDK version. In app.json, you should see a field called "sdkVersion" -- for example, it might be "21.0.0" -- which tells the Expo client which version of the native code to run.
Using the correct version of React Native
We highly recommend that you use a release of React Native that has been tested to work with Expo. In the case of SDK 21, you'd put this in your package.json's "dependencies" section:
"react-native": "https://github.com/expo/react-native/archive/sdk-21.0.2.tar.gz",
The above snippet works only for Expo SDK 21! If you are using a different SDK version, you must use a different version of React Native!
Clearing your caches
We also want to ensure that your device doesn't try to run a stale copy of your code. There are several caches with Expo and React Native, so let's clear them just to be safe:
Stop the React Native packager. Close exp or XDE.
Force quit the Expo client on your device
Clear the Watchman cache (if you are using Watchman): watchman watch-del-all
Clear the Metro bundler cache: rm -fr $TMPDIR/react-*
Make sure your npm dependencies are rebuilt and installed correctly: yarn --force
Start up exp (exp start --clear to make sure we clear the Metro bundler cache for good) or XDE
Open your project on your device in the Expo client