Unable to load script.Make sure you're either running a Metro server(run 'react-native start') or that your bundle - react-native

I want to start React native programming. so in CMD I tried react-native init AwesomeProject then tried react-native run-android but I had some errors that I could not find solution.
some of errors resolved by editing this project in android studio:
add implementation 'androidx.appcompat:appcompat:1.1.0' to build.gradle
and change classpath("com.android.tools.build:gradle:3.4.2") to classpath("com.android.tools.build:gradle:3.5.0")
but emulator showed me
Unable to load script....
showed in this image:
error in emulator
befor this message it showed me on my phone:
JSIExecutor+JSCRuntime does not support Sampling Profiler
so I tried to create the assets directory in
...AwesomeProject\android\app\src\main\
and run gradlew clean in my root project directory.then I tried
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
but this error is occurred:
....error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[
\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\
\.*)$/: Unterminated character class. Run CLI with --verbose flag for more detai
ls.
SyntaxError: Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\
]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__t
ests__\\.*)$/: Unterminated character class....
and that error is showed me again in emulator.
I clicked Reload in emulator but it show me this error:
could not connect to development server...
i run react-native info for mor details and its result is:
info Fetching system and libraries information...
System:
OS: Windows 7
CPU: (8) x64 Intel(R) Core(TM) i7 CPU Q 740 # 1.73GHz
Memory: 892.99 MB / 3.98 GB
Binaries:
Node: 12.11.1 - C:\Program Files\nodejs\node.EXE
npm: 6.11.3 - C:\Program Files\nodejs\npm.CMD
SDKs:
Android SDK:
API Levels: 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
Build Tools: 25.0.0, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.1, 28.0.2, 28.0.3, 29.0.1, 29.0.2
System Images: android-25 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.2 => 0.61.2
the screen shot of react-native run-android command is :
CMD screen shot
and logcat in android studio after runing react-native run-android show this error:
first screen shot of logcat in android studio
then i clicked on reload and logcat showed this error:
logcat screen shot when click on reload
what is problem and how can i resolve it?

my problem is solved.
I tried to run choco uninstall nodejs.install and choco uninstall npm in CMD then I run choco install nodejs.install --version=10.16.3 and choco install npm --version=6.9.0
when I run react-native run android I had other problems, So I opened my project in Android studio and add bellow codes to build.gradle:
implementation "com.facebook.react:react-native:0.61.2" // From node_modules
implementation 'com.android.support:appcompat-v7:27.0.1'
of course that project had some warnings that using Android studio resolved them.
finally react-native run-android work correctly without error.
Adnan comment was helpful but I could not understand why:
React causes lots of errors because of version incompatibility
when I followed official website?!

The way how I ran React-Native for the first time is by following these steps mentioned on the official site:
https://facebook.github.io/react-native/docs/getting-started.html
1) Download NodeJS from this link and install
https://nodejs.org/en/
2) Download Python from this link and install
https://www.python.org/downloads/
3)download JDK from this link and install
https://www.oracle.com/technetwork/java/javase/downloads/index.html
4) If you do not have android studio installed on your PC, download from this link and install
https://developer.android.com/studio/index.html
And later install SDK from within android studio
5) Configure the ANDROID_HOME environment variable
Go to Environment variables and create a new User variable ANDROID_HOME and add the SDK path to Variable path
The default SDK location: c:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk
If you changed the SDK location in step 4, add that path above
6) Add platform-tools to Path
Go to Environment variables and in User variables, click on Path>Edit>New
Add this path in the text field
c:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk\platform-tools
If you changed SDK location, then your SDK path/platform-tools
7) Install a nice text editor like this one, VS Code:
https://code.visualstudio.com
8)Goto Viw>Terminal in VS Code, run this command
npm install -g react-native-cli
9)Create a new project
react-native init NewProjectName
10)For running the project on a physical device, follow these steps:
https://facebook.github.io/react-native/docs/running-on-device
OR use a virtual device like Genymotion
11) Run the project
-Goto your project folder, run this in VS Code terminal:
cd NewProjectName cd means change directory
-Run the project:
react-native run-android
Hope this helps!
I ran my project without any errors following these steps
IMPORTANT
Do not forget to run VS Code As Administrator if your project is in C:/Users/.. folder because it needs administrative privileges to make changes to that folder.
Make sure Metro Server window is running. The Metro Server starts automatically after running react-native run-android.
See the picture below, the top window is the server window.

Related

How to run react-native app on Android emulator (or a physical device) in Android Studio?

I'm trying to run my react native app on either an Android Studio emulator or my physical device. I've followed the instructions at https://reactnative.dev/docs/environment-setup under the React Native CLI Quickstart tab, and initialised the 'AwesomeProject' app from that page, but I'm finding the instructions unclear. For instance it says do the following on the command line: npx react-native start which starts up a process of some sort. Then it says to enter: npx react-native run-android, but the command line is blocked by the previous process. If I try the latter either in another command prompt or without first running the former command, I get an error Unrecognized command "run-android". I should say I have an emulator running from Android Studio before doing all this.
So failing getting it running via the react-native CLI, how do I get it running from within just Android Studio? I've never used Android Studio before, so I have no idea what the process is. Googling hasn't helped either. But as I said, I have managed to get an emulator installed and running.
Any help getting this going either via react-native CLI or from within Android Studio would be greatly appreciated.
edit: I've found how to run my app in Studio, but it pops up an 'Edit configuration' dialogue and says there's no Module selected. But in the module dropdown box there's nothing to select.
You can try following the below steps:
Make sure that you have 2 environment variables set in your system.
ADB variable which is set to the path of "platform-tools" in your system like below:
ANDROID_HOME variable set to SDK path, where android was installed.
Now execute below commands in command prompt and start you emulator or connect your phone which has development settings ON before this:
Open your command prompt in admin mode.
Delete node_modules folder
Execute: npm install
Execute: npm install -g react-native && npm install -g #react-native-community/cli
Execute: npx react-native init
Go to android folder in your react-native project and execute: npx gradlew clean
Come back to main folder and execute: adb reverse tcp:8083 tcp:8083. (You need to check the status of your connected devices by executing adb devices. It will show you the connected devices.)
You also need to make sure that your index.bundle is created. If not than you may create it by executing: npx react-native bundle --platform android --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --dev false --reset-cache --assets-dest android/app/src/main/res/
Finally execute: npx react-native run-android --port=8083

Building and running a finished project on iOS

I have a project downloaded from GIT in React-Native
What steps should I take to run the application in Debug mode on iOS:
on Emulator
on my Device
Firstly, install the node_modules using npm or yarn as per the git project readme.
If your react native version is above 60, it get default cocoapods support. Move to ios folder and run pod install from commandline.
Now you have 2 options to run the project:
1. Navigate to ios folder and run the command 'react-native run-ios'.
2. Open Xcode,Navigate to ios folder and open projecname.xcworkspace file. You can see the run command on top-left of the IDE.

react-native-camera: sdk manager plateforms-tools 28.0.1 can't be installed

I'm trying to install react-native-camera. I'm on Ubuntu 18, Webstorm for IDE. Targeting Android.
For the Android SDK, I don't have a full Android Studio install. I've instead install only android-sdk and I'm using the sdkmanager. That works fine with my stub app, it compile and runs on Android with
react-native run-android
I've installed react-native-camera as a module with npm as per the indications:
npm install react-native-camera --save
react-native link react-native-camera
So far so good. It links. If I try to launch the app however (even before trying to actually use the camera), I get some warnings:
> Configure project :react-native-camera
Checking the license for package Android SDK Platform-Tools in /usr/lib/android-sdk/licenses
License for package Android SDK Platform-Tools accepted.
Preparing "Install Android SDK Platform-Tools (revision: 28.0.1)".
Warning: Failed to read or create install properties file.
WARNING: platform-tools package is not installed, and automatic installation failed.
So I've tried to install the platforms tools using the sdk manager & instructions provided here:
sdkmanager "platform-tools" "platforms;android-28"
Which yields:
Warning: Failed to read or create install properties file.
So I am guessing it really has to do with the sdkmanager...
Do I absolutely need 28.0.1 for react-native-camera? If so, how can I get around this issue with the SDK manager? I've tried various similar syntax for the install of the platform and it didn't work. I checked with sdkmanager --list that it's the proper name (seems to be). And if I go under android-sdk/platforms-tools all I see there is the adb file (or perhaps the install is supposed to just update that file?)
Silly me.
I needed to run the SDK manager as sudo. To do that:
sudo bash sdkmanager [installations args as per post above].
I will leave the post - I lost a ridiculous amount of time for that, hopefully it can help others....
And yes - if the platform-tools install has worked then under /platform-tools you should see a bunch of files, not just the adb one.

react-native run-android not working on ubuntu 16.04

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

ReactNative fails to deploy build to iOS simulator but does deploy it to Android emulator

ReactNative fails to deploy build to iOS simulator but does deploy it to Android emulator
Attached are screenshots showing this on both.
Steps:
Created react native app
react-native init proto
Run app on Android emulator after I started emulator
react-native run-android
this is running fine on Android emulator
Run app on iOS simmulator
react-native run-ios
This produces error as per screenshot
Error
** BUILD FAILED **
The following build commands failed:
CompileC /Users/dinob/reactnativework/proto/ios/build/Build/Intermediates/React.build/Debug-iphonesimulator/React.build/Objects-normal/x86_64/RCTShadowView+Internal.o Views/RCTShadowView+Internal.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
Installing build/Build/Products/Debug-iphonesimulator/proto.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist
Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/proto.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
Versions
MacBookPro OSX El Capitain
react-native 0.55.3
react-native-cli 2.0.1
npm 5.5.1
node v8.9.1
watchman 4.9.0
Please have a look here for help with troubleshooting
I would suggest you try all the solutions described in that thread to try and fix this issue. Good Luck!