目前我正在尝试设置我的环境,以便使用安装在Windows 11中的Android Studio在WSL2中开发React Native。我知道这是可能的,因为我在上一台笔记本电脑上做过这件事......但是,当我执行npx react-native run-android
时,构建在**app:installDebug上挂起了97%。**通过阅读上面的日志消息,似乎adb存在问题:
info Starting JS server...
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
01:23:35 D/DeviceMonitor: Opening adb connection
01:23:35 D/DeviceMonitor: Opening adb connection
01:23:35 D/DeviceMonitor: Unable to open connection to ADB server: java.io.IOException: Can't find adb server on port 5037, IPv4 attempt: Connection refused, IPv6 attempt: Connection refused
...
> Task :app:installDebug
基本上,adb服务器会不断地重启。运行adb kill-server && adb start-server
并不能解决这个问题,原因很明显。我意识到这个日志消息来自gradle,因为这是project/android
目录中./gradlew
的完整输出:
01:22:36 D/DeviceMonitor: Opening adb connection
01:22:36 D/DeviceMonitor: Opening adb connection
01:22:36 D/DeviceMonitor: Unable to open connection to ADB server: java.io.IOException: Can't find adb server on port 5037, IPv4 attempt: Connection refused, IPv6 attempt: Connection refused
01:22:36 D/ddms: Launching '/mnt/c/Users/aoeif/AppData/Local/Android/Sdk/platform-tools/adb start-server' to ensure ADB is running.
01:22:36 D/DeviceMonitor: Unable to open connection to ADB server: java.io.IOException: Can't find adb server on port 5037, IPv4 attempt: Connection refused, IPv6 attempt: Connection refused
01:22:36 D/ddms: Launching '/mnt/c/Users/aoeif/AppData/Local/Android/Sdk/platform-tools/adb start-server' to ensure ADB is running.
01:22:36 D/ddms: '/mnt/c/Users/aoeif/AppData/Local/Android/Sdk/platform-tools/adb start-server' succeeded
01:22:36 I/DeviceMonitor: adb restarted
01:22:36 D/ddms: '/mnt/c/Users/aoeif/AppData/Local/Android/Sdk/platform-tools/adb start-server' succeeded
01:22:36 I/DeviceMonitor: adb restarted
> Task :react-native-gradle-plugin:compileKotlin UP-TO-DATE
> Task :react-native-gradle-plugin:compileJava NO-SOURCE
> Task :react-native-gradle-plugin:pluginDescriptors UP-TO-DATE
> Task :react-native-gradle-plugin:processResources UP-TO-DATE
> Task :react-native-gradle-plugin:classes UP-TO-DATE
> Task :react-native-gradle-plugin:inspectClassesForKotlinIC UP-TO-DATE
> Task :react-native-gradle-plugin:jar UP-TO-DATE
01:22:37 D/DeviceMonitor: Opening adb connection
01:22:37 D/DeviceMonitor: Opening adb connection
01:22:37 D/DeviceMonitor: Unable to open connection to ADB server: java.io.IOException: Can't find adb server on port 5037, IPv4 attempt: Connection refused, IPv6 attempt: Connection refused
01:22:37 D/DeviceMonitor: Unable to open connection to ADB server: java.io.IOException: Can't find adb server on port 5037, IPv4 attempt: Connection refused, IPv6 attempt: Connection refused
01:22:37 D/ddms: Launching '/mnt/c/Users/aoeif/AppData/Local/Android/Sdk/platform-tools/adb start-server' to ensure ADB is running.
01:22:37 D/ddms: Launching '/mnt/c/Users/aoeif/AppData/Local/Android/Sdk/platform-tools/adb start-server' to ensure ADB is running.
01:22:37 D/ddms: '/mnt/c/Users/aoeif/AppData/Local/Android/Sdk/platform-tools/adb start-server' succeeded
01:22:37 D/ddms: '/mnt/c/Users/aoeif/AppData/Local/Android/Sdk/platform-tools/adb start-server' succeeded
01:22:37 I/DeviceMonitor: adb restarted
01:22:37 I/DeviceMonitor: adb restarted
> Task :help
Welcome to Gradle 7.5.1.
To run a build, run gradlew <task> ...
To see a list of available tasks, run gradlew tasks
To see more detail about a task, run gradlew help --task <task>
To see a list of command-line options, run gradlew --help
For more detail on using Gradle, see https://docs.gradle.org/7.5.1/userguide/command_line_interface.html
For troubleshooting, visit https://help.gradle.org
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
BUILD SUCCESSFUL in 1s
6 actionable tasks: 1 executed, 5 up-to-date
我试过禁用我的防火墙和防病毒软件,也试过在Windows文件系统中创建一个React Native项目,以为这是系统间的网络问题,但都没有用。
export WSL_HOST=$( tail -1 /etc/resolv.conf | cut -d ' ' -f2 )
export ADB_SERVER_SOCKET=tcp:$WSL_HOST:5037
adb似乎在WSL2中工作正常,因为我可以看到AVD列在adb devices
之后,并在adb reboot
之后重新启动,但不是在用于React Native的上下文中。
1条答案
按热度按时间e3bfsja21#
你能检查两个ADB版本在WSL2和Windows上是否相同吗?如果不是,请在两者上安装相同的版本,然后再试一次。