How can I deploy and execute an application on a device connected to a remote system?
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:
- 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.
- 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.
- A daemon, which runs as a background process on each emulator or device instance.
adb connect
command is used to connect the local adb
server with the adbd
daemon on a network connected device. But what you want is to connect the local adb
client to the remote (running on another system) adb
server. The default behavior of the adb
executable is to connect to the local instance of the adb
server. If none found it would try to start one. This approach works great for most environments where all development is being done on a single system. But in more complicated environments it may result in multiple instances of adb
server being launched. And because adbd
daemon only supports being connected to a single adb
server at a time - the device will get recognized by one system and will appear missing everywhere else.
So in order for adb
to reliably recognize devices in those more complicated configurations you need to tell adb
to stop guessing and manually specify which part of adb
(i.e. server or client) should be running on which system.
First off make sure that you have the same and sufficiently recent version of adb
(the latest Google official version usually works the best) installed on both local and remote systems. And that no adb
servers are currently running on either system.
Then start an instance of the 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
client on the local system to use the other (remote) server instead of starting its own (local) instance by adding -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 allow you to avoid having to specify the <REMOTE_IP>
and <PORT_NUMBER>
for every adb
command.
And if omitted the <PORT_NUMBER>
would default to 5037
.
This official built-in solution for adb
orchestration is not a mutually exclusive alternative to the SSH tunneling - it just addresses another more important issue. You can add tunneling on top of this to add extra security or help with routing issues in a multi site network environment. But the tunneling alone will not be able to solve all the adb
connectivity problems.
Same goes for the virtualized environments - running multiple adb server
instances between host and guest systems will also result in the adb
connectivity issues.
Can a program run through Remote Desktop call a program on the client computer?
Yes, this is possible using Remote Desktop Virtual Channels. See here for a C# sample. Since virtual channels have both a client and server piece, this would of course require that all RD clients that want to use the virtual channel have the client bits installed.
How to execute an installer executable on a remote machine with Powershell?
Your executable path is based on a drive letter, X:
.
However, in remote sessions mapped drives (drives connected to network shares) aren't available by default, so you have two options:
Establish a (temporary) drive mapping with
New-PSDrive
before calling the executable (e.g.,$null = New-PSDrive X FileSystem \\foo\bar
)More simply, use the full UNC path of the target executable (e.g.
& \\foo\bar\downloads\spotfire\install.exe ...
)
If the target executable isn't actually accessible from the remote session, you'd have to copy it there first, which requires establishing a remote session explicitly and using Copy-Item
-ToSession
- see the docs for an example.
Is it possible to debug an app with a device connected on a remote network?
This is pretty dangerous, as exposing the debugging bridge of your personal device to the internet could prove problematic and unsafe for your personal data.
That aside, the only way I could see this working would be if the client were to port forward the debugging port to the IP address of their device (this would need to be completed on their router)
By default I believe the port to be 5037.
Once the port is forwarded, you should be able to connect to that device in particular by using
adb connect <their external IP>
Again, I cannot stress enough how dangerous this could potentially be.
Related Topics
How to Get the Height and Width of the Android Navigation Bar Programmatically
Passing Arraylist Through Intent
How to Create Custom Button in Android Using Xml Styles
How to Set Onclicklistener on a Radiobutton in Android
Android Singletask or Singleinstance Launch Mode
How to Send a Sms Using Smsmanager in Dual Sim Mobile
Change Locale Not Work After Migrate to Androidx
Android Map V2 Zoom to Show All the Markers
Execute Asynctask Several Times
Changing Screen Brightness Programmatically (As with the Power Widget)
Media Player Called in State 0, Error (-38,0)
How to Import Existing Android Project into Eclipse
Turn Off Autosuggest for Edittext