I am just starting to create a new react-native project and I followed the steps exactly as mentioned in setting-up environment for react-native.
My development OS: Mac; My target OS: Android
I created a local.properties file in my project/android directory which mentions sdk path. I have the android emulator up and running, then I do yarn react-native start, and in another terminal window, yarn react-native run:android but I get the following error:
BUILD SUCCESSFUL in 28s
27 actionable tasks: 27 executed
info Connecting to the development server...
warn Failed to connect to development server using "adb reverse": spawnSync adb ENOENT
info Starting the app...
error Failed to start the app. Run CLI with --verbose flag for more details.
Error: spawnSync adb ENOENT
at Object.spawnSync (internal/child_process.js:1066:20)
error Command failed with exit code 1.
yarn react-native run:ios command runs perfectly alright.
Could anyone help with this please? I have tried the various different suggestions mentioned in this stackoverflow question but no luck.
Related
I have that weird error when running "npx react-native run-android" that is only occuring in a specific react native project only on my Macbook with android simulator. Other RN apps are running fine on my mac with android.
On a windows pc this specific RN app is also working fine.
Error: spawn Unknown system error -8
at ChildProcess.spawn (node:internal/child_process:413:11)
at Object.spawn (node:child_process:743:9)
at module.exports (/Users/hannes/Projects/test2/mapp/native-frame/node_modules/#react-native-community/cli-platform-android/node_modules/execa/index.js:205:26)
I tried the following things:
deleting package-lock.json
rm -r node_modules + gradlew clean (in android folder)
creating a new virtual device in android studio with API level according to build.gradle
upgrading node to 18.8.0
upgrading npm to 8.18.0
npm cache clean –force
Somebody any ideas?
After using "run-ios" in the meantime I had to face the problem again and found a solution.
npx react-native run-android
this line is using the port 8081 and my macbook did sometimes use this port for another service
lsof -i tcp:8081
this command showed the process that was running
COMMAND PID FD DEVICE SIZE/OFF NODE NAME
node 44492 24u 0t0 TCP *:sunproxyadmin (LISTEN)
I terminated this process but still got the error message.
So I called the gradle command for building and installing the app myself.
cd android && ./gradlew app:installDebug -PreactNativeDevServerPort=8081
This worked, the app got build and installed on my android device but I got multiple error messages in the android studio run console starting with:
Could not find generated setter for class
this error was also addressed on GitHub and Stackoverflow
So building and installing the app in production mode solved the problem for me.
./gradlew app:installRelease
I am starting to build an Android application using React Native. But when I tried to run the application using "react-native run-android" command, it runs into a problem. This is what I have done so far.
I installed the react-native command line running the following commands
npm install -g react-native-cli
Then I created the react-native project running the following command.
react-native init {ProjectName}
At this point, I already have the Andriod Studio installed I have been doing the native Android development. So, I opened the Android Studio and started an emulator.
Then within the React Native project, I run the following command to start the project.
react-native run-android
Then I got the following error.
$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 903 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
'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...
> Task :app:installDebug
Installing APK 'app-debug.apk' on 'Pixel_XL_API_30_2(AVD) - 11' for app:debug
Installed on 1 device.
BUILD SUCCESSFUL in 6s
29 actionable tasks: 2 executed, 27 up-to-date
info Connecting to the development server...
warn Failed to connect to development server using "adb reverse": spawnSync adb ENOENT
info Starting the app...
'adb' is not recognized as an internal or external command,
operable program or batch file.
error Failed to start the app.
Error: Command failed: adb shell am start -n com.testreactnative/com.testreactnative.MainActivity
In an attempt to fix that, I added the following environment user variables pointing to the right location.
JAVA_HOME: C:\Program Files\Android\Android Studio\jre\jre
ANDROID_HOME: C:\AndroidSDK
Then I tried running the command again. It is still throwing the same error. What's wrong with my configuration and how can I fix it?
You see this error in console that says 'adb' is not recognized as an internal or external command,
This means that adb path is not added in Environment Variables
My adb path is = C:\Users\karti\AppData\Local\Android\Sdk\platform-tools
Find yours and add it to Path in Environment Variables
I created react-native project and when I run react-native run-ios it is working perfectly.
But the problem is android.
Whenever I run react-native run-android it gives me this error:
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
After this error it begins to install the app and in the end I get this error.
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 app:installDebug -PreactNativeDevServerPort=8081
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
I installed latest java and jdk tools.
I found some solutions on stack overflow and I followed one which suggested to clean Gradlew file in the android folder but it did not work either.
any suggestions please?
My OS is macOS Catalina
Just in case anyone encounters this problem.
I solved it this way
1.ANDROID STUDIO
I went to the android studio and updated all the tools needed for the emulator
2.Android folder inside the project
I went to the android folder of my project, inside of android/app/gradle Gradle-wrapper file and updated distributionUrl to the latest version
3.Clear cache
I ran npm --reset-cache start
4.Final step
After all of this I opened android emulator and ran react-native run-android in my app and it worked
I installed android studio, I configured the environment variables and everything, I installed genymotion and created a device, but running the react-native run-android in the project folder occurs the following error:
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.
please help me in this problem. React-native does not find Genymotion disositivo, in this link has more details: https://pt.stackoverflow.com/questions/382115/react-native-n%C3%A3o-reconhece-genymotion
It tries to connect the emulator to the ADB, by the IP of the device. To check the IP of the device, simply click on an emulator window, the IP address is in the title of the window.
No terminal will run the command:
$ adb connect ip_of_your_emulator:5555
Soon after, run:
$ adb devices
If the name of your file appears in the list, your emulator has been connected successfully!
With the emulator open, simply run the native run-android in the folder of your project.
I've had the same problem earlier this month. As far as I can tell the newer versions of Genymotion don't register on adb devices, a user in the Expo forums speculates it's because they have a paywall now.
I recommend switching to Android Studio, that's what I did to solve my problem.
I ran react-native with the --verbose flag, and got the following error:
...
error Failed to install the app. Make sure you have the Android development
environment set up: https://reactnative.dev/docs/environment-setup.
Error: spawn ./gradlew EACCES
...
So, I gave permissions to the android/gradlew folder as follows:
chmod 755 android/gradlew
But then, I got an error regarding Google Play Licenses:
error Failed to install the app. Please accept all necessary Android SDK
licenses using Android SDK Manager: "$ANDROID_HOME/tools/bin/sdkmanager --licenses".
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
So yeah, pretty the solution was:
Downloading Android Studio with its own SDK
Change the env variabe ANDROID_HOME to the one installed with Android Studio
Installing Google Play Licensing Library (In Android Studio, go to Settings>SDK Manager>SDK Tools, select Google Play License Library and then install)
I have the template code for my "Helloworld" app written in javascript and react-native on Windows. I connected my android emulator and wanted to launch the app on it. The following happens when I run "react-native run-android" command. Node.js opens as a separate window and it's written "Loading dependency graph, done". However, in the terminal window, there is following error message:
>User helloworld $ react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
FAILURE: Build failed with an exception.
>*What went wrong:
Could not create service of type ScriptPluginFactory using
BuildScopeServices.createScriptPluginFactory().
>Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().
>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
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
Command failed: gradlew.bat installDebug
Error: Command failed: gradlew.bat installDebug
at checkExecSyncError (child_process.js:616:11)
at Object.execFileSync (child_process.js:634:13)
at runOnAllDevices (C:\Users\User\helloworld\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
at buildAndRun (C:\Users\User\helloworld\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
at isPackagerRunning.then.result (C:\Users\User\helloworld\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
at process._tickCallback (internal/process/next_tick.js:68:7)
-Concerning whether emulator is connected:
$ adb devices
List of devices attached
emulator-5554 device
(Works similarly for my Android smartphone). USB debugging is enabled.
-Concerning what I have tried to solve the problem:
My user is set as administrator.
I had JDK11.0.1 version. I installed JDK1.8.0_201 and it is now set as my java version.
User helloworld $ java -version
java version "1.8.0_201"
I created ".gradle" folder in my project's directory in case there are problems with accessing/creating this kind of folder.
-I specified the path for sdk.dir in local.properties file
-My OS is Windows 8.1. Gradle's version is 4.7.
-I have installed Android Studio, JDK8 and 11.
-I am using GitBash for the terminal purposes.
-I have the following system's environment variables:
ANDROID_HOME = c:\Users\User\AppData\Local\Android\Sdk
GRADLE_HOME = C:\Users\User.gradle\wrapper\dists\gradle-4.7-all\4cret0dgl5o3b21weaoncl7ys\gradle-4.7
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_201
Path = C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Git\cmd;.\Plugins;C:\Users\User\AppData\Local\Programs\Python\Python37-32;C:\Program Files\nodejs\;c:\Users\User\AppData\Local\Android\Sdk\platform-tools;C:\Users\User\AppData\Local\Android\Sdk\platform-tools;%GRADLE_HOME%\bin;%JAVA_HOME%\bin
In case you are interested what was in the question before:
My initial problem was that there just was not any error shown, but still nothing was launched on the emulator. I went around that by putting my project's "android" folder into Android Studio and it launched the app on my smartphone. However, when I introduced small changes to App.js, the project could not be updated due to some unknown error, and I couldn't reopen it as a new project. So I had to solve this problem by trying to run the app by using "react-native run-android" through terminal, and now I'm at this state of the problem.
Mmmm... when you run react-native run-android on the console, 1 it should check if you have the android sdk's, second it should compile some things, and third, it should start metro bundler in ANOTHER console . The "Loading dependency graph, done" should appear on that OTHER console, while the main console is gonna still compile for about a minute or even more... then it's gonna launch the intent and open the app. Sometimes it just displays a blank screen after the first load, so you should exit the app and delete it from recents, and reopen the app
Post screenshots, it seems like you only see that secondary console while the main console is not displaying (?)
Do you want to run a react-native or purely java application for which you must have used Android studio?
If for the studio app: you must enable the developer's options from your phone for enabling that check this:
https://www.samsung.com/uk/support/mobile-devices/how-do-i-turn-on-the-developer-options-menu-on-my-samsung-galaxy-device/