I have a problem with RN. I'm a newbie in RN, but I know a little bit of React.
So I tried to clone and open this project: https://github.com/mapbox/store-locator-react-native/
But I couldn't. I tried putting expo and running the project on an Android emulator, but even after I tried installing and uninstalling multiple packages, I always get some error. I also tried with npx react-native run-android but it doesn't work (in the folder with the project, not the base).
Could please someone tell me how to make this project work on my local machine and maybe even upgrade it to the newest RN?
Thanks
you have to navigate to your project
follow the steps
i am assuming your project on Desktop
launch terminal and write
cd Desktop/RNStoreLocatorExample
if you have IOS platform
do
npm install
cd ios
then
pod init
pod install
cd ..
react-native run-ios
or if you have android
write
react-native run-android
Hope it will work
Related
Just a quick question, how to run an existing older version of react native project. Lets say version 0.59.10 , without upgrading it. what would be the command line commands. Thanks
You should navigate to project directory (if you aren't yet)
cd PATH_TO_PROJECT_DIRECTORY
run the following command to install the dependencies
npm install
then if the react-native version is 0.59.10 and lowers you should also run the command below to link the dependencies to your native android and ios project.
react-native link
and then run one the following commands based on your device
for android
react-native run-android
for ios
react-native run-ios
I am trying to recreate ios and android folders for my react-native project. As far as I know this is done with the command:
react-native eject
But I get the error:
error Unrecognized command "eject".
I am doing something wrong? How should I recreate android and ios folders?
react-native-cli: 2.0.1
npm i react-native-eject
npm i #react-native-community/cli
react-native eject
will generate the both android and ios folder
It did work in 0.59.9. This threw me too this morning after I upgraded to 0.60. Apparently you now have to run react-native upgrade --legacy true. react-native eject was much easier IMHO.
yarn add react-native-eject
react-native eject
This two-line of code solved my problem with the eject error.
Nikita is 100% correct. If the project was initialized in expo running react native eject will "eject" the project from the expo dependencies (and expo environment) and create a standalone react native project outside the expo environment. This typically adjusts the dependencies in the pakage.json file.
The command exists as a part of expo.
To initialize a project from scratch react-native init will create android and ios folders. Also ensure if you have cloned the directory to run either npm install or yarn to install the dependencies.
If the project was initialized the way I imagine yours was the commmand you are looking for would be one of the following:
react-native run ios or react-native run ios --device
react-native run android or react-native run android --device
For RN projects, which are initiated by react-native init there is no such command, by default RN is using metro bundler instead of web-version of React, where you can configure Parcel/Webpack/Rollup or run create-react-app where actually you can eject.
This question is suitable for expo where you can actually eject, if you need some native modules that are not included in expo.
Try to use expo
react-native eject and upgrade --legacy true aren't working for me.
In the end, I just created a new blank RN project and this had an ios folder. Copied the folder over to my existing project and ... seems to work.
Run npm i react-native-eject
Run npm i #react-native-community/cli --force
Note: use npx instead of npm
npx react-native eject
cd android
./gradlew.bat installDebug
cd..
npm run android
i have a problem with react native in ubuntu, i have installed,
java jdk 8 (both javac --version) as well as echo $JAVA_HOME gives the proper output.
I have also installed android studio and set the android environment variables as well as the tools and echo $ANDROID_HOME gives output of the sdk location.
I have also installed gradle version 4.4.
I am unable to start the android app using react-native run-android. can any one let me know if i have missed something during installation.
And react-native as well as android studio works fine as I am currently using react-native start to start the metro builder as well as the other react-native cli commands. also android studio and gradle is also able to generate debug as well as release apks with no problems.
The error i get,
Scanning folders for symlinks in /home/igate-naveed/Documents/ReactNative/mobile-app-android/node_modules (16ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
First of all you need to create a project like this:
react-native init myProjectName
Then, start an emulator from Android Studio... Afterwards:
npm install && npm start
in your project directory, and from another terminal, inside your project directory, run :
react-native run-android
Is this working?
Instead of using the npm install manager, I used yarn and it worked for me. In your project directory, just do:
(project-directory)$ yarn
Update the gradle version.
Create new project:
react-native init projectname
Uninstall the npm pack.
Reinstall the npm pack again.
npm start
react-native start
react-native run-android
I have messed the files up in the Android folder and would like to rebuild the Android project inside of the Android folder. How do I do this?
Is it safe to delete the Android folder and then run react-native run-android, will that make it again?
Everything I've coded was wrote in index.android.js.
EDIT: Original answer was written in 2017 (RN v.0.47?). React-native environment evolved and AFAIK this solution is no longer valid.
Probably safe to remove.
I had similar problem, and ./gradlew clean
didn't work, but i found hacky solution from How can I regenerate ios folder in React Native project?
Delete android folder (probably ios too), and then hacky part ->:
react-native upgrade
(it regenerates folders, but it shouldn't be used to upgrade RN..)
And then
react-native link
react-native run-android
It worked for me :)
EDIT : one observation -> react-native sometimes goes crazy and cannot run some commands. Launching a new terminal helps. Bizarre :)
The solution if ur version of react-native >= 0.61.0 :
sudo rm -rf android/ ios/
yarn add react-native-eject
npx react-native eject
enjoy !
Try to do this:
cd android
gradlew clean
cd ..
react-native run-android
Here my solution: (I'm doing this for android)
First command:(Navigation to the Android folder of your react-native project)
cd Android
Second command:
./gradlew clean
Third commmand:
./gradlew cleanBuildCache
I'm not fan of deleting android folder. (I think this not a best approaches)
To generate apk file for production: (First one from /Android)(second one from root project)
./gradlew bundleRelease
react-native run-android --variant=release
Happy coding!!!
Running following commands should do the trick:
sudo rm -rf android/ ios/ #Delete Android and ios folders first...
react-native eject
react-native upgrade //rebuilds android/ios folders
react-native link
react-native run-android
react-native run-ios
Below command will create the android and ios folders.
react-native eject
EXPO users: If you've used Expo then you can run expo run:android
If the folder is malformed (or not present) it will clear and rebuild.
Yes, it is safe to delete the Android and IOS folder and you can make it again by following steps:
1.First Method:
react-native eject <=0.59.0
React-native had this command in the previous version. Running this command will check if the ios and android directories exist and then rebuild whichever one is missing.
sudo rm -rf android/ ios/
react-native eject // Will create new Android and IOS folder.
react-native link
react-native run-android
2.Second Method:
react-native upgrade --legacy true>=0.60.0
Now you should use the react-native upgrade --legacy true command to back up your android folders or ios as the case may be as this command will replace your files.
Funny solution here
Create a new react native app and copy the new android folder over and then run $react-native run-android
In 2022 January:
I am using windows.
Inside my VS code terminal:
rm android/
But to delete Android and ios folders first you do "rm android/ ios/"
It may warn you of your action, accept.
Next:
npm run android //rebuilds android/ios folders
npm run ios //rebuilds android/ios folders
I'm new to React and React-Native I'm trying to open a React-native app I cloned from github. I've done a npm install and I did a npm start in the command line. It says: "Running Packager on port 8081" and then a bunch of other builds beneath it. I tried going to local host 8081 and 8081/hot but I can't see the app. Does anyone know how to run and test an react-native app on the browser?
follow the below step
1) Go to project directory
after use this CLI
2) react-native run-android
it can run only either emulator or real device so we can first start the emulator after the try above command
more details see this doc
Inside your project directory for bundle js.
3) react-native start
or
3) react-native start --reset-cache
After installing packages,
open src folder--->open in terminal
--->$ npm start
react-native run-ios --simulator="iPhone 5s"
If you have an installation with android and ios folders, you should run yarn android or yarn ios.