I have a problem that has been driving me crazy for two days now. I have created a new empty React Native app following the instructions of the official page. The problem is that I can´t make it work on my cellphone. I´m getting this when I try to run it:
PS C:AMyApp> npm run android
> [email protected] android
> react-native run-android
info JS server already running.
info 💡 Tip: Make sure that you have set up your development environment correctly, by running react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor
Exception in thread "main" java.net.ConnectException: Connection refused: connect
at java.base/java.net.PlainSocketImpl.waitForConnect(Native Method)
at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:107)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
at java.base/java.net.Socket.connect(Socket.java:609)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:177)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:509)
at java.base/sun.net.www.http.HttpClient$1.run(HttpClient.java:561)
at java.base/sun.net.www.http.HttpClient$1.run(HttpClient.java:559)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/sun.net.www.http.HttpClient.privilegedOpenServer(HttpClient.java:558)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:599)
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:373)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:216)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1208)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:193)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1592)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
at org.gradle.wrapper.Download.downloadInternal(Download.java:109)
at org.gradle.wrapper.Download.download(Download.java:89)
at org.gradle.wrapper.Install$1.call(Install.java:83)
at org.gradle.wrapper.Install$1.call(Install.java:63)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
at org.gradle.wrapper.Install.createDist(Install.java:63)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:109)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:66)
error Failed to install the app.
I know the error says that is a connection problem but I have checked all the possible applications that could be blocking it. I have completely disabled my firewall (I´m using windows 11). I´m running out of ideas. Any help would be deeply appreciated. I´m using Visual Studio Code but I have also tried with Android Studio and by typing the command directly on the PowerShell with the same result.
Update:
I changed the version of the gradle on the conf file for the one I have installed on my pc. Apparently, in that way the compilation process doesn´t have to download that and the previous error disappears. But now I get this one:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:[email protected]' line: 13
* What went wrong:
Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.8.20'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.8.20')
Searched in the following repositories:
MavenRepo
Google
Gradle Central Plugin Repository
* 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.
Maybe the problem is just that I´m still without connection for some strange reason???
2
Answers
Ok, finally after three days on this I was able to solve my problem. Everything worked when I deleted the .gradle folder on my home and synchronized the Gradle on Android Studio. It took some time to download all the required files again but after that everything worked like charm. I guess there was something broken on some gradle files. I hope this answer helps somebody out there.
Have you checked whether your device is connected correctly … you can use this command to get the list of all devices connected to your system
adb devices
or you can try running your project in android studio from there you can select the connected device and the run the app directly on that device