How to run react native app on real android device? - android

I tried to run my app on an android device, but I got this error after usign
npx react-native run-android in my vscode terminal:
PS C:\Users\user\Desktop\NewProgram\ReactN\my-app> 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 2 workers...
info Starting JS server...
"adb" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
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...
Downloading https://services.gradle.org/distributions/gradle-7.2-all.zip
..............10%...............20%...............30%...............40%...............50%...............60%...............70%...............80%...............90%...............100%
Welcome to Gradle 7.2!
Here are the highlights of this release:
Toolchain support for Scala
More cache hits when Java source files have platform-specific line endings
More resilient remote HTTP build cache behavior
For more details see https://docs.gradle.org/7.2/release-notes.html
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:\Users\user\Desktop\NewProgram\ReactN\my-app\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 2m 53s
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:\Users\user\Desktop\NewProgram\ReactN\my-app\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 2m 53s
at makeError (C:\Users\user\Desktop\NewProgram\ReactN\my-app\node_modules\#react-native-community\cli-platform-android\node_modules\execa\index.js:174:9)
at C:\Users\user\Desktop\NewProgram\ReactN\my-app\node_modules\#react-native-community\cli-platform-android\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (C:\Users\user\Desktop\NewProgram\ReactN\my-app\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
at async Command.handleAction (C:\Users\user\Desktop\NewProgram\ReactN\my-app\node_modules\#react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.

Go to your React-native Project -> Android
Create a file local.properties
Open the file
paste your Android SDK path like below
in Windows sdk.dir = C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk
in macOS sdk.dir = /Users/USERNAME/Library/Android/sdk
in linux sdk.dir = /home/USERNAME/Android/Sdk
Replace USERNAME with your user name
Now, Run the react-native run-android in your terminal.

Related

Error connecting to emulator in react-native project

info JS server already running.
/bin/sh: 1: adb: not found
info Launching emulator...
error Failed to launch emulator. Reason: The emulator (Pixel_4_XL) quit before it finished opening. You can try starting the emulator manually from the terminal with: emulator #Pixel_4_XL.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
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 '/home/oem/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
BUİLD 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.
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 '/home/oem/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
BUİLD FAILED in 7s
at makeError (/home/oem/AwesomeProject/node_modules/execa/index.js:174:9)
at /home/oem/AwesomeProject/node_modules/execa/index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async runOnAllDevices (/home/oem/AwesomeProject/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:85:5)
at async Command.handleAction (/home/oem/AwesomeProject/node_modules/react-native/node_modules/#react-native-community/cli/build/index.js:108:9)
info Run CLI with --verbose flag for more details.
I'm using linuxmint. npx can't connect to emulator in react-native run-android code, what's the problem?

Build Failed in react native

I was working with react native in my windows 10 for months. after upgrading to windows 11 and installing previous tools , I am not able to run my react native project . I installed android studio , SDK, JDK, node and other tools like before. but I got this error after running npx react-native run-android command:
FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users\Username\Documents\React Native Projects\myapp\android\app\build.gradle' line: 1
What went wrong:
A problem occurred evaluating project ':app'.
Failed to apply plugin 'com.android.internal.application'.
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing org.gradle.java.home in gradle.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 38s
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
Note: C:\Users\Username\Documents\React Native Projects\myapp\node_modules\react-native-gradle-plugin\src\main\java\com\facebook\react\codegen\generator\SchemaJsonParser.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users\Username\Documents\React Native Projects\myapp\android\app\build.gradle' line: 1
What went wrong:
A problem occurred evaluating project ':app'.
Failed to apply plugin 'com.android.internal.application'.
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing org.gradle.java.home in gradle.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 38s
at makeError (C:\Users\Username\Documents\React Native Projects\myapp\node_modules\#react-native-community\cli-platform-android\node_modules\execa\index.js:174:9)
at C:\Users\Username\Documents\React Native Projects\myapp\node_modules\#react-native-community\cli-platform-android\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (C:\Users\Username\Documents\React Native Projects\myapp\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
at async Command.handleAction (C:\Users\Username\Documents\React Native Projects\myapp\node_modules\#react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
This question was asked many times before, but I did not get an answer from them . I tried gradlew clean but I get same error (Build Failed). for some developers chmod +x gradlew worked. but it is for Linux and Mac. I am using windows . is there any replacement command for windows or other way to fix this problem ?
thanks .
Open Android Studio Settings and follow this path. Open the dropdown for Gradle JDK and select 11 from the dropdown.

react-native program is not installed on the emulator

I created a new project with React Native in Windows 10 but it does not run with the run-android command.
I will summarize what I did because I think all the programs are installed:
I install both npm and node.
Java installation.
React installation.
In the Environment system, these are set.
ANDROID_HOME ---> C:\Users\IHC\AppData\Local\Android\Sdk
JAVA_HOME--> C:\Program Files\Java\jdk-۱۴.۰.۱
path--> C:\Users\IHC\AppData\Local\Android\Sdk\tools
C:\Users\IHC\AppData\Local\Android\Sdk\platform-tools
C:\Program Files\nodejs\
C:\Users\IHC\AppData\Local\Android\Sdk
C:\Users\IHC\AppData\Local\Android\Sdk\emulator
C:\Program Files\Java\jdk-۱۴.۰.۱\bin
The error is:
info Starting JS server...
info Installing the app...
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
.
.
.
.
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:832)
FAILURE: Build failed with an exception.
* What went wrong:
Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
* 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 44s
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
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
enter code here
Can you check on the android version installed, for latest version refer https://www.npmjs.com/package/#react-native-community/cli-platform-android and retry.
That is installed, well I did the following
remove jdk-۱۴.۰.۱ and i install jdk-8u261-windows-x64
first of all run Oracle VM VirtualBox next run Genymotion
and in powershell
npm start -- --reset-cache
npm install -g npm#4
react-native run-android

Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

MacBook-Air mlaapp % npx react-native run-android
warn The following packages use deprecated "rnpm" config that will stop working from next release:
- react-native-video: https://github.com/react-native-community/react-native-video#readme
Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1232 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Installing the app...
FAILURE: Build failed with an exception.
What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
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 1s
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
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 1s
at checkExecSyncError (child_process.js:631:11)
at execFileSync (child_process.js:649:15)
at runOnAllDevices (/Users/varmabiraju/projects/Joshi/MyProjects/mlaapp/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
at buildAndRun (/Users/varmabiraju/projects/Joshi/MyProjects/mlaapp/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/index.js:179:41)
at /Users/varmabiraju/projects/Joshi/MyProjects/mlaapp/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/index.js:133:12
at processTicksAndRejections (internal/process/task_queues.js:88:5)
at async Command.handleAction (/Users/varmabraju/projects/Joshi/MyProjects/mlaapp/node_modules/react-native/node_modules/#react-native-community/cli/build/index.js:182:9)
Try changing sdk versions in /android/build.gradle
compileSdkVersion = 30
targetSdkVersion = 30
from the comments, it seems that you are not using the gradle version 6.3. can you update your android build to use gradle 6.3 and see if the issue still persists?
another user faced a similar issue and reported this on github. you may want to take a closer look at it here.
This worked for me: Open task manager (of your OS) and kill adb.exe process. Now start adb again, now adb should start normally.
If this is your error
error for nativeDevServerPort
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
gradle 6.2 all zip causing this error for run-android please change or upgrade the distributionUrl version of gradle in
gradle-wrapper.properties to
distributionUrl=https://services.gradle.org/distributions/gradle-6.3-all.zip
Hope this could help you in installing your react-native application in android

React Native WebStorm Emulator cannot start - error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`

I'm new to WebStorm and React Native and I encountered an error while setting up my environment that appears unique compared to the other post I've seen.
Objective
I've set up a default project in WebStorm, my goal is to run that project on an Android emulator, I'm using a Windows PC.
What I've tried
I've set up a simple Debug configuration in WebStorm
I've also downloaded an Android Emulator thru Android Studio and I have it running on my computer.
Now when I click on run for my debug emulator I get the following error:
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
'adb' is not recognized as an internal or external command,
operable program or batch file.
info Launching emulator...
infoerror Installing the app...
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.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> 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:\Users\Nicol\WebstormProjects\Dog\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 13s
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> 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:\Users\Nicol\WebstormProjects\Dog\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 13s
at checkExecSyncError (child_process.js:621:11)
at execFileSync (child_process.js:639:15)
at runOnAllDevices (C:\Users\Nicol\WebstormProjects\Dog\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Other Information
Here is a picture of my Path System variables:
adb is not on your %PATH%; make sure to add the folder where adb.exe is located (usually $ANDROID_HOME/platform-tools, where $ANDROID_HOME is your Android SDK install dir, usually C:\Users\Your.Name\AppData\Local\Android\sdk, you can run where adb command in Windows cmd console to find it) to %PATH% under System environment variables and then restart WebStorm.
You also need defining %ANDROID_SDK_ROOT% environment variable per suggestion in the error message
Just to add, windows environment variables are case sensitive and adding %LOCALAPPDATA%\Android\Sdk like the react-native website says will not work, you need to add %localappdata%\Android\Sdk

Categories

Resources