How can I deploy and execute an application on a d

2019-01-02 23:59发布

I have a requirement to deploy a test application and issue commands on a device connected to another machine in the same network.

I read through http://developer.android.com/tools/help/adb.html#directingcommands but I am not able to find the answer.

I tried using adb connect <remote machine IP> but I got unable to connect error.

Is there a way to deploy applications and execute adb commands on a device connected to a remote system?

3条回答
干净又极端
2楼-- · 2019-01-03 00:48

From the adb tag wiki:

Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client-server program that includes three components:

  1. A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
  2. A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
  3. A daemon, which runs as a background process on each emulator or device instance.

adb connect command is used to connect the local server with a daemon on a network connected device. But what you want is to connect a local client to a remote server. To achieve that you need the latest adb version installed on both local and remote systems.

Start an instance of adb server on the remote system (the one which you will be plugging the devices into) with this command:

adb -a -P <PORT_NUMBER> nodaemon server

Now you can force adb on the local system to use the other (remote) server instead of starting its own (local) instance by prepending -H <REMOTE_IP> -P <PORT_NUMBER> to your adb commands:

adb -H <REMOTE_IP> -P <PORT_NUMBER> devices

Alternatively setting ANDROID_ADB_SERVER_ADDRESS=<REMOTE_IP> and ANDROID_ADB_SERVER_PORT=<PORT_NUMBER> environment variables on the client side would let you avoid having to specify the <REMOTE_IP> and <PORT_NUMBER> for every adb command.

And if omitted the <PORT_NUMBER> would default to 5037.

查看更多
萌系小妹纸
3楼-- · 2019-01-03 00:49

Perhaps this will help:

Its a java library that I've developed few months ago specifically with that remote adb commands in mind. The basic idea was to provide some abstraction layer where devices could be similarly accessed on remote machine as it was locally connected. Check it out:

https://github.com/lesavsoftware/rem-adb-exec

PS. and it uses SSH tunnel so it should be secure enough.

查看更多
放荡不羁爱自由
4楼-- · 2019-01-03 00:55

What about using SSH to connect to the machine on which your device is attached and issue ADB command from there ? This is at least what we do in our company where we have dozens of devices we control like that.

查看更多
登录 后发表回答