I currently dont have a pc. I have two rooted devices Arm64 host device with Debian rootfs and the device to be debugged which contains the lldb-server binary armv7. I am trying to remote debug my android device using lldb. I pulled the lldb-server binary from àndroid ndk24 and put it in /data/local/tmp. Installed Debian Sid on Another term and apt installed lldb.
I then wifi hotspoted the client device(one with lldb-server) using the host with the linux rootfs.
The commands i ran on server device
./data/local/tmp/lldb-server platform --listen "*:2000" --server
Checked using netstat and the lldb-server had bound to all addresses(0.0.0.0:2000)
On host(client lldb) device in debian sid terminal i ran:
apt install lldb
lldb
platform select remote-android
platform connect connect://192.168.201.132:2000
Then i get error failed connect port.
However, using Gdb and gdbserver everything worked perfectly. I have tried installing lldb on debian buster but same result and even ran the lldb-server binary on the host(device with debian sid) but same result. Right now im stuck here. How do I solve this?
Help will be greatly appreciated. Thank you.
I dont know why, but lldb-server platform command is broken(mabe in my case) and should have used lldb-server gdbserver like this:
On lldb-server gdbserver command, the stub doesnt allow connections from other ips except the one it is bound to so do this:
iptables -I INPUT -t nat -p tcp -d 192.168.43.1 --dport 2000 -j SNAT --to-source 192.168.43.1:50000
./data/local/tmp/lldb-server g 192.168.43.1:2000
On lldb client do
gdb-remote 192.168.43.1:2000
Then do normal remote debugging.
Related
Since Xcode and Android studio consume a lot, I am having storage and processing capacity issues on my Mac, while developing React Native Applications.
My Question is that is there any way to run emulators (in my case android emulator) on another PC, while I am coding on Mac?
Thank you
I tried once the solution below, it might also work for you. And the source is in this repo.
If you want to write and compile an Android application on one machine and debug it remotely on the emulator launched on another follow the instructions below:
Preparation
First of all you need to install SSH server on your remote machine.
Ubuntu
You can use OpenSSH.
sudo apt install openssh-server
Windows
You can install OpenSSH on Windows following this link.
Connection
Now you must connect local machine to remote server using SSH tunnel.
The emulator listens on two TCP ports per instance: 5554 for the telnet interface and 5555 for control communication with tools like DDMS. So you could probably get away with only forwarding port 5555. Each subsequent emulator takes the next available even+odd port number tuple.
Note that you need to enter the ip address of emulator running on remote server instead of emulator-ip and also remote machine username and hostname instead of myuser and remote-server.
Ubuntu
On the local machine try:
ssh -NL 5554:emulator-ip:5554 -L 5555:emulator-ip:5555 myuser#remote-server
Windows
Follow this link instructions and add two source ports and destinations below:
Source port: 5554
Destination: emulator-ip:5554
Source port: 5555
Destination: emulator-ip:5555
then connect to remote server.
ADB
The emulator tries to notify a local adb server at startup; hence you need to restart adb in order for it to probe the local 5554+ ports.
adb kill-server; adb devices
adb devices shows a new emulator — emulator-5554 — and you can use it as if it is running on your local machine.
Running
Finally run:
react-native run-android
the app should be installed on emulator, but you may face an error:
error: more than one device/emulator
Could not run adb reverse: Command failed: path/to/sdk/adb -s emulator-5554 reverse tcp:8081 tcp:8081
you need to specify your debug host IP and port in app's Developer menu -> Dev settings -> Debug server host & port, that is your local machine ip address and 8081 for port.
Note that after APK installation you don't need to do any of these steps. You can just start the npm server: npm start in the project directory of your local machine, run the app on the emulator in remote machine and then reload.
if there was another error:
Exception in thread "Device List Monitor" java.lang.NullPointerException
try:
react-native run-android --deviceId
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.
adb reverse was introduced in Android 5.0
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.
Follow these steps carefully.
Note: All commands need to run inside a project only.
Run this command first:
npm react-native start
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"
This will create index.android.bundle in the assets folder
Run:
npm react-native run-android
Now you can get apk in the build folder which will work fine.
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.
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
Just use 10.0.2.2 instead of localhost/127.0.0.1 for your hostname. It will directly try to connect to the port on the host machine (same affect as reverse).
I have created a Docker image which contains the Android SDK and am trying to expose my Android phone in a container running this image. So I used the --privileged flag and mounted the USB devices as follows:
$ docker run --privileged -v /dev/bus/usb:/dev/bus/usb -d -P my-android:0.0.1
However, when I run ADB devices, it does not show me the USB device:
ubuntu#d56b666be455:~/Android/Sdk/platform-tools$ ./adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
ubuntu#d56b666be455:~/Android/Sdk/platform-tools$
lsusb inside the container lists the device:
ubuntu#d56b666be455:~$ lsusb
...
Bus 002 Device 017: ID 04e8:6866 Samsung Electronics Co., Ltd GT-I9300 Phone [Galaxy S III] (debugging mode)
The device is however visible on the host:
⇒ ./adb devices
List of devices attached
4d11abcd65b74045 device
Host OS
$ uname -a
Linux ananya 3.16.0-33-generic #44~14.04.1-Ubuntu SMP Fri Mar 13 10:33:29 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Docker version
$ docker --version
Docker version 1.5.0, build a8a31ef
What could be the issue?
I don't think the ADB daemon running on the device can be connected to two ADB servers. Try disconnecting it from your host machine's ADB and then connect it to the Docker container's ADB.
While I was trying the same, I ran into some other problems related to that, which I would like to share so that others may save their time:
Problem 1: lsusb was not installed in the container
In my case lsusb was not installed, so I installed it with the below command:
apt-get update
apt-get install usbutils
Problem 2: not able to see the device even after lsusb and ADB SDK installation
You need to restart your container with the -v option, and yes don't forget to kill the ADB server as stated in one of the answers.
On the host:
adb-kill server
docker run -ti -d --privileged -v /dev/bus/usb:/dev/bus/usb container_name
In case someone wanted do it from scratch, I have written a blog post on it:
How to connect ADB devices to Linux container
This doesn't answer the exact question you were asking, but does address what you were trying to accomplish - connecting to an android device connected to a docker host from an adb client running inside a docker container. I'm including this for anyone trying to accomplish the same thing (like I was).
The adb client supports a -H option which tells it where to find the adb server to connect to. Docker supports the hostname "host.docker.internal" which always maps to the IP address of the docker host. Assuming your device is connected to the docker host, you can do the following to get your containerized adb client to connect to the adb server running on the docker host:
adb -H host.docker.internal devices
Accomplishes the goal without having to mount the USB ports.
Reference: https://developer.android.com/studio/command-line/adb
Update:
I recently learned that host.docker.internal is only supported on Docker for Mac in versions 18.0 and above.
Running with just --privileged -v /dev/bus/usb:/dev/bus/usb did not work for me.
I tried forwarding the adb daemon's listening port using -p 5037:5037, but that did not help either.
It worked only after I added --net host.
This means the host machine's net interfaces are exposed to the docker so use it if you are fine with that. Maybe there are more ports that needed to be forwarded other than 5037....
This works for me.
Set your devices in PPT mode
(optionaly) Check if the devices is available localy $ adb devices
I try with many options and only one works. Using --network flag as the next example
Run container
$ docker run -it --net host ubuntu bash
output:
List of devices attached
464e128 device
I used this Dockerfile. Is for flutter projects
Update:
I ended up using --privileged and -v to map the whole of /dev/bus/usb and patching adb to accept one environment variable to specify the root USB device tree - /dev/bus/usb/001 etc.
This allowed us to use different USB busses for different containers for different groups of the same phone, and another environment variable patch allowed different VID:PID lists for different types of phone.
We're trying to allocate different USB buses to different Docker containers running TeamCity clients.
Each container needs ANDROID_ADB_SERVER_PORT setting to a different port (because we're not using segregated networking).
The host machine can't run adbd, because only one adbd can talk to a phone at any given time.
Each container gets one of the /dev/bus/usb/xxx directories, so we can plug phones into particular containers.
We have to synchronise the /dev/bus/usb/xxx directory every few seconds, to allow hot-plugging and reboots - just a shell loop on the host that runs tar cf devxxx.tar /dev/bus/usb/xxx, docker cp to transfer it, then docker exec to untar inside the container's /tmp, diff to detect nodes to delete, and mv -n to move new nodes in.
In fact, because we're running on Linux, we can probably just set up udev scripts, per Howto run a script when a USB device is pluged in.
Excuse me for offtop. But I cannot answer to this question so I write it down here.
I am using ubuntu:18.04 and tried to connect my Samsung Galaxy A3 2016 and debug it with ADB. Devices was unauthorized and no dialog popped up on the screen!
How I solved the problem:
I was interested will the problem still occure inside a Docker container? The answer was "No!".
Inside a Docker container, that I invoked with following: (this is the answer for this topic :) )
docker run --name android-adb -it -d --privileged -v /dev/bus/usb:/dev/bus/usb ubuntu:16.04 bash
I downloaded platform-tools (distribution with ADB). Added its path to environment. And restarted bash
After restarting ADB server inside Docker container AND killing ADB server on host machine. I found out that confirmation dialog appeared on the smartphone's screen!
So on the host machine the problem was in .android directory I think. Just move it to .android-backup. The next adb start-server command will create new one. Also I replaced platform-tools folder with most recent
Am trying to connect odbsim through bluetooth with my Samsung S4. After successfully pairing my devices with ubuntu, my results connecting obdsim with phone is never happened.
Whenever I tried running the command obdsim -b it always throwing error:
SimPort name: Not yet connected
I tried connecting it with windows too, with the help of com0com serial port, but couldn't succeded. And in windows, obdsim -b results in invalid options.
Please help me to connect the simulator with android device.
Thanks,
Boopathy.
I had the same problem on Linux and I resolved it installing some libraries and recompiling OBDSim.
I will put here the whole process to make a guide for new users like me.
Download OBDSim:
wget http://icculus.org/obdgpslogger/downloads/obdgpslogger-0.16.tar.gz
Or get the most recent version from: http://icculus.org/obdgpslogger/
Install OBDSim:
tar -zxvf obdgpslogger-0.16.tar.gz
cd obdgpslogger-0.16
mkdir build
cd build
I have to install only these libraries, but in your case keep attention to warning messages of cmake and install all that it ask you to install:
sudo apt-get install libbluetooth-dev libfltk1.1-dev libfltk1.1 fltk1.1-doc fluid fftw3-dev libgps-dev libftdi-dev
cmake ..
make obdsim
cd ../bin/
Run OBDSim:
./obdsim -b -g gui_fltk
Now you have OBDSim running, but you need a channel to communicate it with your app. You need a serial port working as a bluetooth interface.
Creating the serial->bluetooth interface:
sudo rfcomm bind 0 00:00:00:00:00:00 1 # Change this MAC address, putting the MAC of your device
sudo sdptool add SP
You can discover the MAC address of your device by using hcitool:
hcitool scan
It only works when the bluetooth configuration "Visible to all nearby Bluetooth devices" is on in your device.
I have used almost the same method described here and here and it worked. It worked without using com0com.
Pair the android device with the computer.
In Torque app, go to Settings -> OBD2 Adaptor Settings -> Choose Bluetooth Device. Select
your Computer Name.
Set the incoming COM Port of bluetooth as COM#Number . Assume it
is COM10 (Use https://www.verizon.com/support/knowledge-base-20605/)
Use obdsimwindows-2011-06-11 build. Can be downloaded from
http://icculus.org/obdgpslogger/downloads/obdsimwindows-latest.zip
Run obdsim.exe -w COM10
Run the Torque app and see whether it connects automatically.
-g option is used to give a generator type. By default it is gui_fltk which is the GUI interface.
adb port forwarding is not working for me and your insight is appreciated.
The following command is what I am trying
./adb forward tcp:5985 tcp:5984"
I don't see any errors(in logcat) but it just fails silently. When I try the following command
curl localhost:5985 after that, I get "curl: (56) Recv failure: Connection reset by peer"
When I try curl localhost:5984, I do see a message as I have a process running on port 5984 (Couchbase server).
I don't think this is an issue with adb itself as all other adb commands are working. Amongst other things I have tried are
a) kill-server followed by start-server (with sudo mode as well)
b) Restarting my machine.
Needless to say, neither of these have worked. I am working on x64 Ubuntu 11.10.
Please note that I am working with the emulator and my emulator device is running.
I do see other messages in logcat just not this one.
Thanks
-Venu
Have you read this document from Google?
https://developers.google.com/chrome/mobile/docs/debugging
It explains that you have to first make sure you can see your device with
adb devices
Then in Chrome on your Android device, go to Open Settings > Advanced > Developer tools and check the Enable USB Web debugging option as shown here:
Then enter the follow command:
adb forward tcp:9222 localabstract:chrome_devtools_remote
And go to this URL in Chrome on your desktop:
localhost:9222
Does that work?
On the original question , the answer is to make sure your device emulator is running. On Ubuntu you can use: netstat -tan to see the TCP ports that your development machine is listening on. Usually the port is 5554. When the emulator is not started, there will not be a process listening on this port.
Well, I finally got there. I'm not sure which one of these finally fixed the issue (but most are helpful):
ensuring that /etc/udev/rules.d/##-android.rules was chmod a+rw so that we don't need to sudo adb and can edit it again
On Ubuntu 12.04 the ATTRS{idVendor} is the simple 4 hex code (some pages will encourage you to take the full lsusb ####:#### code
I now do not have the SYMLINK+="android_adb" entry in udev
adb devices still shows ???????????? instead of my device code (but works now)
adb shell actually returns a # prompt
adb usb breaks it (it was not returning with curl which I thought was an improvement on the error, but no - it breaks it worse)
There is a bug in adb forward, such that small, fast data connections are simply dropped:
emulator> nc -lk 9998
host> adb forward tcp:9900 tcp:9998
host> date | nc localhost 9900 # Does not arrive at the emulator
host> ( date ; sleep 0.1 ) | nc localhost 9900 # Does arrive at the emulator
That said, when I try the above with curl, that data gets through - presumably because curl holds the socket open in the same way that (date ; sleep 0.1) does.
This issue started happening for me when I updated Android SDK Platform Tools from version 29.0.2 to 29.0.3
I followed this How to downgrade my SDK version?
Basically, you need to downgrade Android SDK Platform Tools to version 29.0.2:
Find your Android SDK folder
Rename platform-tools to platform-tools-29-0-3 (incase something goes wrong)
Download Android SDK Platform Tools 29.0.2 for your machine e.g. http://dl-ssl.google.com/android/repository/tools_r29.0.2-windows.zip
Extract it into your Android/SDK folder
And you are done