Reputation: 173
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 :
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?
Upvotes: 1
Views: 5822
Reputation: 173
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?!
Upvotes: 1
Reputation: 343
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.
Upvotes: 0