NativeScript / nativescript-cli

Command-line interface for building NativeScript apps
https://www.npmjs.com/package/nativescript
Apache License 2.0
1.04k stars 195 forks source link

WSL2 - Unable to apply changes on device ECONNREFUSED livesync #5450

Open mrkvn opened 3 years ago

mrkvn commented 3 years ago

Environment

Details

After running tns run android, the app compiles properly but not hot reloading. Got an error: Unable to apply changes on device: emulator-5554. Error is: connect ECONNREFUSED 127.0.0.1:40547

After using --log trace, found that port 40547 (changes every run), in this particular run, is related to livesync, maybe.

spawn: /home/user/android/platform-tools/adb "-s" "emulator-5554" "forward" "tcp:40547" "localabstract:org.nativescript.application-livesync"
Result when throw error is false:
{ stdout: '40547\n', stderr: '', exitCode: 0 }

spawn: /home/user/android/platform-tools/adb "-s" "emulator-5554" "shell" "rm" "-rf" "/data/local/tmp/org.nativescript.application-livesync-in-progress"
Result when throw error is false:
{ stdout: '', stderr: '', exitCode: 0 }
Unable to apply changes on device: emulator-5554. Error is: connect ECONNREFUSED 127.0.0.1:40547.
Error: connect ECONNREFUSED 127.0.0.1:40547
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 40547
}
Will emit event runOnDeviceError with data {
  projectDir: '/home/user/code/vue-ns',
  deviceIdentifier: 'emulator-5554',
  applicationIdentifier: 'org.nativescript.application',
  error: Error: connect ECONNREFUSED 127.0.0.1:40547
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 40547
  }
}
Stopping webpack watch for platform android.
Webpack process exited with code null when we expected it to be long living with watch.

To Reproduce

tns run android

Expected behavior

Hot Reload.

Additional context

Trying to setup nativescript-vue in windows wsl2. Made it to work. It compiles correctly. For reference, I used the following write-ups/articles to set it up.

  1. rearct-native-app-in-wsl2
  2. Using the Android emulator on Windows 10 with WSL2

I only used the basic app template from vue init nativescript-vue/vue-cli-template.

tns doctor No issues were detected. ✔ Your ANDROID_HOME environment variable is set and points to correct directory. ✔ Your adb from the Android SDK is correctly installed. ✔ The Android SDK is installed. ✔ A compatible Android SDK for compilation is found. ✔ Javac is installed and is configured properly. ✔ The Java Development Kit (JDK) is installed and is configured properly. ✔ Local builds for iOS can be executed only on a macOS system. To build for iOS on a different operating system, you can use the NativeScript cloud infrastructure. ✔ Getting NativeScript components versions information... ✔ Component nativescript has 7.0.12 version and is up to date. ✔ Component @nativescript/core has 7.0.13 version and is up to date. ✖ Component @nativescript/ios is not installed. ✔ Component @nativescript/android has 7.0.1 version and is up to date.

I've already searched google looking for answers. I found same error asked in stackoverflow but there are no answers and their question has no details/context behind it, so I'm not sure if they really have the same issue as this.

Not sure if this is a WSL2 specific problem with ports. If it is, I hope someone could point me in the right direction on how to solve this. Thanks

lordkyuusei commented 2 years ago

Since this issue is still open even if a solution has been deployed, to anyone coming by:

Summary of the feature: what you have to do is to set the NATIVESCRIPT_LIVESYNC_ADDRESS env variable to whatever IP you used for the ADB Server socket (your WSL ADB connecting to the Windows one.).

// or put it in alongside your ADB_SERVER_SOCKET in any .bashrc / .zshrc file
NATIVESCRIPT_LIVESYNC_ADDRESS=172.16.0.1 tns run android