What is the ADB? - android

I keep reading tutorials where I'm supposed to enter something into the ADB command line and that it's in my Android sdk/platform-tools. So I find it, click on it, and a black screen comes up for about 2 seconds and while it's up, it scrolls through a bunch of text. So how am I supposed to use this "adb"?

It is called the Android Debug Bridge, and the Android Developers Site documentation does a better job of explaining it than I can:
http://developer.android.com/guide/developing/tools/adb.html
If you are looking for the adb command line, navigate to <sdk>/platform-tools/ and run
adb.exe shell
from the command line.

Pretty sure that is well documented since day 1 on the Android Debug Bridge
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.
So plain old English, ADB can be found on %ANDROID_HOME%/platform-toos/, and it's this magical command line that allows you to comunicate with your mobile device, either a physical or a Virtual device (AVD), so whenever you deploy you are passing the application through the device thanks to the ADB on a specific client port on your computer to the daemon port on the device.
Interesting things you can do with it?
Logcat: ./adb logcat allows you to see the log trace of each proces.
Install: ./adb install allows you to install apk to the device.
Killing:./adb kill-sever
Starting:./adb stat-server
Enter SQLite3: adb -s your_device shell
Use the monkey: adb shell monkey -v -p your.app.package 500 to
generate random events
And a lot more! Read the documentation it's beatiful and self-explanatory.

Related

See app background processes in Android Studio

Maybe I'm just missing it but is there a way to view WHAT is running in the background on-device in android studio?
I'm getting a battery usage alert on my phone (galaxy s8 - OS v8.0), indicating my app is doing something in the background and I'd like to see what it is.
Thank you
Yea, via the terminal function. This is one of options at the bottom of the Android studio.
You need to run ADB to connect to the device. Once connected you can use Unix command lines to see the processes running.
From google dev : https://developer.android.com/studio/command-line/adb
Also, the command I use to connect an emulator to run unix commands is:
adb -s <DEVICE> shell
Normally the ADB is stored :
USER\AppData\Local\Android\Sdk\platform-tools
and then once connected you can use the following to see the running processes :
https://www.howtogeek.com/107217/how-to-manage-processes-from-the-linux-terminal-10-commands-you-need-to-know/
Hope this helps.

Getting "error: closed" twice on "adb reverse"

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).

Install Apk in specific emulator

Im trying to install an apk on an specific emulator using TeamCity. Right now I`m starting an emulator an installing the apk successfully.. but if there is already one or more instances of the emulator running, team city cannot decide in which emulator install the apk (even when I'm starting the emulator from teamcity scripts).
The problem is that I cannot identify the emulator I just started using:
emulator -adv myEmulator
it will start an emulator between ports 5554 to 5587... I know I can set the emulator instance where I want to install my apk:
adb -s emulator-5554 install path/apk
but I don't know the id of the emulator I just started, so it could have any number in its name between that range.
I know I can set an UUID to the emulator (from here), but again.. don't know how to use that uuid.
Right now I will try to save the available emulators before I run my own using BATCH, and then compare both arrays to get my emulator.. but I'm not an expert on BATCH.. so if anyone has a clue it's gonna help,
Regards
You seem to look for -s option of adb:
-s <specific device> - directs command to the device or emulator with
the given serial number or qualifier.
other useful options:
-d - directs command to the only connected USB device
returns an error if more than one USB device is
present.
-e - directs command to the only running emulator.
returns an error if more than one emulator is
running.
and in general adb -h to see them all.
EDIT
You can define what port you want emulator to use:
-ports <consoleport>,<adbport> TCP ports used for the console and adb bridge
so you can assign ports manually and do not bother guessing. to avoid port collisions you can either force ports for all emulators launched (you should not have more than i.e. 3 running at the same time usually) or you can choose high port numbers for your range, high enough so even any other emulator is launched it will be using available ports below your range.
Alternatively you can parse emulator log produced when use with -verbose switch as you can find there:
emulator: control console listening on port 5554, ADB on port 5555
emulator: sent '0012host:emulator:5555' to ADB server
If you want to save emulator log to specific file, use regular stream redirection:
emulator -verbose #MyAVD > log.txt

how could I transfer file from terminal to screen /dev/tty.*(android machine)?

I'm developing android set-top box app.
So, I have android box and its adb is REALLY SLOW.
When I have to install .apk file to debug my project, I use adb connect [ip address] via wifi and then build & run with Android Studio because the set-top box doesn't have USB port.
But it has serial port so I can connect its shell by screen /dev/tty.usb-serialblablabla 115200. when I use that command, I can see exactly same screen as one of adb shell.
Its adb shell(via wifi) shows very very slow performance.
For example, if I want to run pm list packages, I should type 'pm list packages' and wait for 2min.and then type enter key.(...sigh)
Whereas,Using screen /dev/tty.* methods respond promptly.
I don't know where this difference is come from.
but it is not matter of wifi. I checked its speed. it is quite normal.
In this circumstance, I click Run button in Android Studio after adb connect.
gradle build takes about 10sec.
upload .apk(10.2mb) takes about 10min (sigh).
Because screen ... way is much faster then adb connect way, I want push my .apk into device via 'screen'. how can I do? OR is there anything I can do to reduce time for putting .apk in android device?
You really should find out why adb transfers take so long. But if you insist on using serial console for uploads instead - you could just use any terminal application with XMODEM support on PC side to send the file and busybox rx -b <filename.apk> command on android side to save it. Then pm install <filename.apk> to install it.

What is adb in Android?

I get the following errors when I try to run my Android program.
Please explain me What really adb is, and how to restart it?
I am getting the following error
The connection to adb is down, and a severe error has occured.
You must restart adb and Eclipse.
adb is Android Debug Bridge.
To restart adb by command line:
adb kill-server
adb start-server
To restart adb in Eclipse:
Window > Show View > Other... > Android/Devices
When the view is showing: View Menu of "Devices" > Reset adb
Android Debug Bridge
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.
Restarting ADB
adb kill-server && adb start-server
By using above command, that'll restart the adb server. And, if you're using Eclipse means, please see the below image -
In your DDMS one option is there for restarting the adb like in above image. Hope this helps you.
ADB stands for Android Debug Bridge.
Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device.
In depth details can be found here.
As for restarting adb server you can execute following commands
adb kill-server
adb start-server
As for Eclipse simply close the IDE and restart/reopen. Infact restarting Eclipse should restart adb server as well.
PS: Above link goes to my personal blog that has additional details on ADB.
I saw this problem on Eclipse, and it reported that I needed to 'reset adb from the Device's view'. The adb kill&restart-server sequence didn't work for me, but I was successful with just disabling and then re-enabling the 'USB debugging' check box in the phone's Settings->Developer Options
i also came across with this problem, i got this error please ensure that adb is correctly located “Users/semihozkoroglu/ADT/sdk/platform-tools/adb” and can be executed
Click devices dropdown - > reset adb, its works..
ADB is a Android Debug Bridge.
Following for more Details ADB
http://www.addictivetips.com/mobile/what-is-adb-and-how-to-install-it-android/
http://developer.android.com/guide/developing/tools/adb.html
Close And Open Eclipse,Adb is automatically restarted..!
Thanks..!

Categories

Resources