google / bundletool

Bundletool is a command-line tool to manipulate Android App Bundles
https://g.co/androidappbundle
Apache License 2.0
3.57k stars 388 forks source link

Should support ADB_SERVER_SOCKET #90

Open sleekweasel opened 5 years ago

sleekweasel commented 5 years ago

We use adb servers on remote machines, and our tests on our CI, so we need this to support ADB_SERVER_SOCKET just like adb, without killing the remote server in case someone else is using one of the remote devices.

Version 0.10.1

Steps

  1. remote.machine> adb -a -P 9125 nodaemon server
  2. local> ADB_SERVER_SOCKET=tcp:remote.machine:9125 adb devices 2a. emulator-5554 device
  3. local> ADB_SERVER_SOCKET=tcp:remote.machine:9125 java -jar bundletool.jar get-device-spec --output x.json 3a. No connected devices found.

Expected behavior

It would honour ADB_SERVER_SOCKET just like adb does - without killing the remote server.

4.15.0-51-generic #55-Ubuntu SMP Wed May 15 14:27:21 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

sleekweasel commented 5 years ago

Although ddmlib support DdmPreferences get/set AdbHostValue and UseAdbHost, it doesn't seem that it finished implementing it.

I have a proof of concept working by setting DdmPreferences to ${ADBHOST} in BundleToolMain and copying ddmlib/AndroidDebugBridge.java and replacing the two places where it uses DEFAULT_ADB_HOST with references to

      String adbHost = DdmPreferences.getUseAdbHost() ? DdmPreferences.getAdbHostValue() : DEFAULT_ADB_HOST;

but I can't find the label to configure in my Android source checkout to propose the fix - would you be able to tell me that?

sleekweasel commented 2 years ago

I don't see a link to my pull request (which requires a ddm lib file to be patched too) so I'll put it here. I think you need ddmlib changed to get this working.

https://github.com/google/bundletool/pull/93

sleekweasel commented 2 years ago

Also, I found some kind of workaround - if the remote emulators' adb is running in promiscuous mode, you can use 'socat' to publish the remote port locally. It's not very nice and if there are connection issues then good luck trying to diagnose them, but:

socat -d tcp-listen:$EMULATOR_ADB_PORT,reuseaddr,fork,bind=$CONTAINER_IP tcp:127.0.0.1:$LOCAL_EMULATOR_ADB_PORT &