Getting “error: closed” twice on “adb reverse”

2019-01-08 11:09发布

I am trying to reverse-forward port through ADB, but it just returns cryptic error of error: closed. Normal forwarding works. Session snippet:

$ adb forward tcp:59778 tcp:59778
$ adb forward --list
015d2109ce0c1a0f tcp:59778 tcp:59778
$ adb forward --remove-all
$ adb forward --list
$ adb reverse --list
error: closed
error: closed
$ adb reverse tcp:59778 tcp:59778
error: closed
error: closed

I am connecting via USB to non-rooted Nexus 7 2012 Android 4.4.4 from Windows 7 Pro x64 on Boot Camp.

5条回答
萌系小妹纸
2楼-- · 2019-01-08 11:57

Since adb reverse is not supported in Android versions lower than 5.0, you need to use an alternative method, for example connecting via Wi-Fi instead. If you are using React Native, Facebook has added official documentation to connect to the development server via Wi-Fi. Quoting the instructions for MacOS, but they also have them for Linux and Windows:

Method 2: Connect via Wi-Fi

You can also connect to the development server over Wi-Fi. You'll first need to install the app on your device using a USB cable, but once that has been done you can debug wirelessly by following these instructions. You'll need your development machine's current IP address before proceeding.

You can find the IP address in System Preferences → Network.

Make sure your laptop and your phone are on the same Wi-Fi network. Open your React Native app on your device. You'll see a red screen with an error. This is OK. The following steps will fix that. Open the in-app Developer menu. Go to Dev Settings → Debug server host for device. Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081). Go back to the Developer menu and select Reload JS.

查看更多
对你真心纯属浪费
3楼-- · 2019-01-08 12:00

cause of adb reverse isnt working on android prior 5 you could propably use adb forward with a service listening on android and tunneling other connections through this inbound connection. I am doing this mostly with ssh, but you would need an ssh server on android. you than can connect using ssh -R incommingreverseportonandroid:hostyouwanttoforwardto:portyouwanttoforwardto sshuseronandroid@localhost -p portyouhaveusedforadbforwaqrdtoaccessandroidssshserver

but i dont know how to enable an ssh server on android and maybe there is a better way cause ssh uses encryption which isnt needed over usb and using up cpu.

i am using this way with my server to share a service when i am forced behind a nat...

hope someone will find a way to bring this teoretical way into practical possibility

查看更多
Anthone
4楼-- · 2019-01-08 12:05

adb reverse requires Android 5.0+. For devices previous to that, you'll need to use a workaround like so.

If you have busybox installed on your Android device (most Genymotion images do), you can emulate adb reverse using this incantation:

adb shell busybox nc -ll -p {guest port} -e busybox nc {host IP} {host port}

In this case, "guest" is the Android OS running in the emulator and "host" is the computer running the emulator.

查看更多
Rolldiameter
5楼-- · 2019-01-08 12:12

Follow these steps carefully.

Note: All commands need to run inside a project only.

  1. Run this command first:

    npm react-native start
    
  2. Open another window in the same project and run:

    curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
    
  3. This will create index.android.bundle in the assets folder

  4. Run:

    npm react-native run-android
    

Now you can get apk in the build folder which will work fine.

查看更多
太酷不给撩
6楼-- · 2019-01-08 12:14

adb reverse was introduced in Android 5.0

查看更多
登录 后发表回答