我有一个问题,这两天来一直让我发疯。我已经按照官方页面的说明创建了一个新的空React Native应用程序。问题是我不能让它在我的手机上工作。当我试着运行它时,我得到了这个:
PS C:\A\MyApp> 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.
我知道错误说这是一个连接问题,但我已经检查了所有可能阻止它的应用程序。我已经完全禁用了我的防火墙(我使用的是Windows 11)。我快没主意了。任何帮助都将不胜感激。我正在使用Visual Studio Code,但我也尝试过Android Studio,并直接在PowerShell上输入命令,结果相同。
更新:
我在conf文件上为我已经安装在PC上的Gradle更改了版本。显然,通过这种方式,编译过程不必下载该文件,并且以前的错误消失了。但现在我得到了这个:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\A\MyApp\node_modules\@react-native\gradle-plugin\build.gradle.kts' 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.
也许问题只是因为一些奇怪的原因,我仍然没有联系???
2条答案
按热度按时间vojdkbi01#
您是否已检查您的设备是否正确连接...你可以使用这个命令来获取所有连接到你的系统
adb devices
的设备的列表或者你可以尝试在android studio中运行你的项目,你可以选择连接的设备并直接在该设备上运行应用程序
xbp102n02#
好吧,终于在三天后,我能够解决我的问题。当我删除我家的.gradle文件夹并在Android Studio上同步Gradle时,一切都正常。再次下载所有需要的文件花了一些时间,但之后一切都工作得很顺利。我想是一些gradle文件坏了。我希望这个答案能帮助到外面的人。