react-native run-android gives an exception about the PATH connection - react-native

I am trying to run the react-native run-android command in window 10. I set up the path to the SDK folder using ANDROID_HOME in System Variables of Environment Variables
ANDROID_HOME | C:\Users\owner\AppData\Local\Android\Sdk
And I also set up sdk.dir in the local.properties file
sdk.dir=C\:\\Users\\owner\\AppData\\Local\\Android\\Sdk
However, when I run the command lines
react-native run-android
in my project folder C:\Users\owner\Documents\React_Native\MyApplication> It gave me an exception as follow.
C:\Users\owner\Documents\React_Native\MyApplication>react-native run-android
Scanning folders for symlinks in C:\Users\owner\Documents\React_Native\MyApplication\node_modules (34ms)
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.305 secs
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/android-setup.html

Related

Failed to run a react native app run on Android emulator

I have a problem with building react native app on android emulator. I tried to crate app with Expo and everything works great on android device, android emulator(Android studio) and web. But when I try to create with React Native CLI a have a build error.
admin#users-MacBook-Pro secondProjectReactNative % npx react-native run-android
warn Multiple Podfiles were found: ios/Podfile,vendor/bundle/ruby/2.7.0/gems/cocoapods-core-1.11.3/lib/cocoapods-core/Podfile. Choosing ios/Podfile automatically. If you would like to select a different one, you can configure it via "project.ios.sourceDir". You can learn more about it here: https://github.com/react-native-community/cli/blob/master/docs/configuration.md
info Starting JS server...
/bin/sh: adb: command not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings
5 actionable tasks: 5 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/admin/secondProjectReactNative/android/local.properties'.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/admin/secondProjectReactNative/android/local.properties'.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
at makeError (/Users/admin/secondProjectReactNative/node_modules/execa/index.js:174:9)
at /Users/admin/secondProjectReactNative/node_modules/execa/index.js:278:16
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async runOnAllDevices (/Users/admin/secondProjectReactNative/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction (/Users/admin/secondProjectReactNative/node_modules/#react-native-community/cli/build/index.js:142:9)
info Run CLI with --verbose flag for more details.
What can be wrong? Thanks a lot.
I did everything what was in react native CLI quick start https://reactnative.dev/docs/next/environment-setup
I'm sure that PATH is added
admin#users-MacBook-Pro secondProjectReactNative % echo $PATH
/Users/admin/.rvm/gems/ruby-2.7.5/bin:/Users/admin/.rvm/gems/ruby-2.7.5#global/bin:/Users/admin/.rvm/rubies/ruby-2.7.5/bin:/Users/admin/.rvm/bin:/usr/local/opt/ruby#2.7/bin:/usr/local/opt/ruby#2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/local/opt/ruby#2.7/bin:/Users/admin/Library/Android/sdk/tools:/Users/admin/Library/Android/sdk/platform-tools:/Users/admin/Library/Android/sdk/emulator:/Users/admin/Library/Android/sdk/platform-tools
I downloaded SDK through Android Studio.
Start android studio emulator before "run android" doesn't help.

React Native CLI Android installation error

I am new to react native, I was trying to follow an example on how to launch react native app with react native CLI but I keep getting this error in my CMD.
C:\React Native Workspace\RN-CLI\FirstCli>npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 863 file(s) to forward-jetify. Using 12 workers...
info Starting JS server...
'adb' is not recognized as an internal or external command,
operable program or batch file.
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:\React Native Workspace\RN-CLI\FirstCli\android\local.properties'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 10s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:\React Native Workspace\RN-CLI\FirstCli\android\local.properties'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 10s
at makeError (C:\React Native Workspace\RN-CLI\FirstCli\node_modules\execa\index.js:174:9)
at C:\React Native Workspace\RN-CLI\FirstCli\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (C:\React Native Workspace\RN-CLI\FirstCli\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
at async Command.handleAction (C:\React Native Workspace\RN-CLI\FirstCli\node_modules\#react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
I need help with resolving these issues.
Assuming that you already have the Android SDK installed, you need to create a file named local.properties at the root of you Android project your-react-native-project-android/ and you should also add it to .gitignore if you are using git.
The file must indicate the path of the SDK on your computer, for macOS for example
local.properties
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Oct 26 14:02:40 CEST 2021
sdk.dir=/Users/username/Library/Android/sdk
If you never installed the SDK, you need to start here

react-native not working on physical device

I am new in react native so please help me start with that .I just create my first react-native project by using this command
npx react-native init AwesomeProject
I already install android studio and add path of sdk in environment. Also done with developer option in my android. When I run that command
npx react-native run-android
it gives me a lot of errors like that
* What went wrong:
Could not determine the dependencies of task ':app:installDebug'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'E:\react_native\AwesomeProject\android\local.properties'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 7s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
Go to the android/ directory of your react-native project
Create a file called local.properties with this line:
sdk.dir = /Users/USERNAME/Library/Android/sdk
Where USERNAME is your macOS username
More Info found here

native_modules.gradle file is deleting as soon as react-redux is installed

I have created an app in react native for my project. When I copy my projects file in the app folder then run the app it said that in node_module react-redux does not exist then I installed react-redux using npm install react-redux#7.0.3 in my app folder after that when I run run-android command in command prompt for this project it is telling that -
Could not read script 'E:\AppFolder\MyApp\node_modules\#react-native-community\cli-platform-android\native_modules.gradle' as it does not exist. .
After that, I wiped the data of emulator and run run-android, but it is still giving me the same error and app is not installing in the emulator.
Here is the error which command prompt is displaying :
info Building and installing the app on the device (cd android && gradlew.bat app:installDebug)...
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* Where:
Settings file 'E:\AppFolder\MyApp\android\settings.gradle' line: 4
* What went wrong:
A problem occurred evaluating settings 'TribeBond'.
> Could not read script 'E:\AppFolder\MyApp\node_modules\#react-native-community\cli-platform-android\native_modules.gradle' as it does not exist.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 10s
error 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
error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.```
Here I follow these steps to solve my problem-
I build a new app and run it using react-native run-android command.
Then I installed all dependencies one by one, which is going to use in the app.
Then run npm install command in the project.
After that, I re-build the app using react-native run-android.
And Tada! the app is re-built without any error.

React Native wont run on Android Device. Missing ANDROID_HOME [duplicate]

This question already has answers here:
React Native - java.lang.RuntimeException: SDK location not found. Define location with sdk.dir in the local.properties
(5 answers)
Closed 6 years ago.
When I execute react-native run-android in the terminal, I get the following:
JS server already running.
Running adb -s HT68X0201778 reverse tcp:8081 tcp:8081
Building and installing the app on the device (cd
android && ./gradlew installDebug)... Failed to notify
ProjectEvaluationListener.afterEvaluate(), but primary configuration
failure takes precedence. java.lang.RuntimeException: SDK location not
found. Define location with sdk.dir in the local.properties file or
with an ANDROID_HOME environment variable.
FAILURE: Build failed with an exception.
Where: Build file '........./android/app/build.gradle'
line: 110
What went wrong: A problem occurred evaluating project ':app'.
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I have already done the following: Installed the Android Studio 2.2.3. I checked the boxes in the installer that it said to on the RN website. I installed Marshmallow SDK, AVD, HAXM, and JDK 1.8. I added ANDROID_HOME to /.bashrc and even executed set ANDROID_HOME=~/Library/Android/sdk on the terminal. (I double-checked the path.) I am running on react-native-cli version 2.0.1. Operating system is Mac OS Sierra.
I'm not sure where to go from here. Any help would be appreciated.
Thanks! --Anthony
Create a file called local.properties and add it to the android folder and then define sdk.dir(The location of your android SDK directory) in my case it is:
NOTE: you do not need to include it in quotes.
sdk.dir = /home/kbuhiire/Android/Sdk
I changed the ANDROID_HOME path from ~/Library/Android/sdk to /Users/myusername/Library/Android/sdk. That did the trick. Refer to React Native android build failed. SDK location not found