Android Studio see device as null [duplicate] - android

This question already has answers here:
set up device for development (???????????? no permissions)
(30 answers)
Closed 4 years ago.
On Ubuntu Android Studio shows devices as null.
Every time I turn on my laptop, I need to run the following console commands to add permissions:
./adb devices
./adb kill-server
sudo ./adb devices
Enter my password and then repeat:
./adb kill-server
./adb devices
Note I'm using a xiaomi phone.
Is there a way to get around this permission issues so I don't have to do it ever time.

Anyway, what I did to solve this problem.
Defined in what cases I need to run these commands. For most ubuntu users there is a home folder (hidden file .bashrc).
In which you can record the launch of these commands. But these commands will be triggered when you enter the bash command in the console.
Since I have a shell .zshrc then I did the following:
open console: gedit .zshrc
When the file opens, add the following line:
./.add_device_permissions.sh
After or before, we need to create this file: .add_device_permissions.sh in which we write the following:
#!/bin/bash
# Add permissions for Xiaomi Redmi Note 5
ADB="/home/vadimm/Android/Sdk/platform-tools/adb"
$ADB devices
$ADB kill-server
cat .permissions_redmi_note | sudo -S $ADB devices
$ADB kill-server
cat .permissions_redmi_note | sudo -S $ADB devices
Also we need create .permissions_redmi_note where we need to hardcode our password.
Not to add to the file .zshrc unnecessary we can specify the path when starting the system itself: Startup Applications Preferences
Where we press on "Add" and write our command: /home/vadimm/.add_device_permissions.sh

Related

Unable to run app - "The target device does not support the 'run-as' command"

Running Android Studio on a Macbook for the first time and I'm getting this error. The program does not start on my device, I just get a crash message.
On Android Studio, I get "The target device does not support the 'run-as' command" and when I plug this into google I get no results. I get a "Learn More" section though which points to this link under the heading "About Instant Run": https://developer.android.com/studio/run/index.html?utm_medium=android-studio#instant-run.
Any suggestions would be highly appreciated.
I recently upgraded to AS 2.2 and this message suddenly appeared today.
Restarting Studio caused this message to disappear.
But the build in general seemed slow - so I used the adb commands to stop and start the server and now it seems Instant run is working better
adb kill-server
adb start-server
my phone is Moto G x1032 w lollipop
I had this same problem after rooting my device and the other answer didn't solve it.
When I ran adb run-as command in the terminal I kept getting
Could not set Capabilities: operation not permitted.
It's a permissions issue. You have to change permissions on run-as file in /system/bin folder. This solved it for me (needs root access):
1. remount /system rw
2. chmod 4750 /system/bin/run-as
3. remount /system ro
If running custom recovery:
1. reboot to recovery
2. find the mount system and check it (make sure 'mount system as read-only' is unchecked)
3. open a terminal and type: adb shell
4. type: chmod 4750 /system/bin/run-as
5. uncheck the System mount and reboot!
See here issue 58373: https://code.google.com/p/android/issues/detail?id=58373

adb shell command from batch file [duplicate]

This question already has an answer here:
windows batch script not execute next line after "adb shell"
(1 answer)
Closed 5 years ago.
I have a .bat file that runs script for testing an app and printing the log to file i have all the commands i tested them manually.
Problem:
after entering the command adb shell, the shell opens in the command prompt. I wrote the next commands that are entered in the shell with root#generic
the commands aren't going through and it just waits at that spot.
what do i have to type in front of the commands to make them appear
example of what i have
cd directory of sdk
adb
adb shell
am instrumentation ... (this is the command that won't go through once the shell is open.
any help appreciated I've tried a few things with no success
Just use the following line in your batch file:
adb shell am instrumentation
that will connect to the shell on the Android device and run the am command.

adb "error device not found" when trying to use 'adb shell' but "adb devices" detects the device

Guys basically I've plugged in a bunch of Android devices to a computer and each of them has adb enabled. I'm running a shell script to push certain files to the devices using the Device Serial Numbers stored in a text file. When I trigger the script the first time it works. if i trigger it again adb throws an error , "error device not found" though the devices are still detected using adb. If i close the terminal and reopen it and run the script it works fine. I plan to eventually automate the script running. How can i stop this from happening.
EDIT: This is the piece of code where the adb shell commands are triggered
cat device_serial | while read line
do
adb -s $line shell
cd /data/
ls
exit
adb -s $line root
adb -s $line push 'stestfile.txt ' /data/
echo "done"
done
I need to look at the script to fix the issue.
But looks like the problem is that the next time you run the script, you are actually in the device's shell instead of your computer's.

adb shell auto-complete under Windows 7

Regarding this post: adb shell auto-complete under Windows 7?
The owner's answer is: "Solved this problem by recompiling adb under cygwin. :)"
Unfortunately I can't send comments asking him how did he recompiled the adb under cygwin.
So my question is: How could I recompile adb under cygwin to get auto-compete working in adb?
EDIT: I realized that actually cygwin is already auto-completing when I type inside android bash, but the text is not being showed. Weird, isn't? E.g:
# ls /data/tem
[TAB]
# ls/data/tem | <<<--- the cursor jumps to here
[ENTER]
It list all files and folders within /data/temp folder.
You can use ADB enhanced Putty
It support auto complete and coloring
you can download it from
ADB Putty
Just start it suing the following command-line:
adb-putty.exe -adb -P 5037 transport-usb
read more at ADB enhanced Putty (replacement for "adb shell" command)
Try PuTTY Tray. Its work for me!
connect to the phone via "adb connect ip:port"
run Putty Tray, select Adb and click "Open"
PS.
You can specify device ID in session settings.
I'm (fortunately) not a Windows user but I guess the problem is not in adb but in your shell that is not letting some keys (i.e. TAB) reach it.
Try this to see if TAB is received by the android shell:
adb shell
# printf '%d\n' "'$(dd bs=1 count=1 2>/dev/null)"
<type TAB+ENTER>
9
If you cannot see 9 (ascii TAB) then your problem is in the Windows shell and you could try cygwin bash to reproduce the test and see the results.
Are you mis-understanding the original post? I think that guy is saying he stopped using the Command Prompt and switched to cygwin.
You can make auto complete work in the Windows command prompt as well. Just run cmd /f instead of cmd. The other post has instructions on how to permanently enable autocomplete.
If you want to use cygwin then focus on trying to get autocomplete to work in cygwin. It's been years since I used cygwin, but I thought it was enabled by default. Maybe you need to turn off case sensitivity? How to deactivate uppercase check in cygwin folder autocompletion?
Regardless which shell you use it will only auto complete folder and file names.

Is it possible to install APK file if more than one emulators/devices are connected [duplicate]

This question already has answers here:
How to use ADB Shell when Multiple Devices are connected? Fails with "error: more than one device and emulator"
(15 answers)
Closed 7 years ago.
I know how to install the apk file in to the emulator by command prompt and all that.
But i want to know is it possible to install same apk file in to multiple emulator by giving any specific name ?
Actually i have to test one apk file in to many device. and for that i have started many device. I know how to install it. if the all device are open then it will not get install. So is there any alternate to install that apk file by giving any specific device Emulator id or any name ???
Please help me if there is any idea for it. . .
Thanks.
Yes, you can install an apk on a particular device.
In command, type:
adb devices
// list of devices and its unique ID...
Then type:
adb -s "<deviceIDfromlist>" install "<path-to-apk>"
Step 1: Get the device Ids of all connected device
adb devices
Step 2: Install to a particular device you want to install
adb -s deviceId install path+apk
Example:
Step 1:
C:\Android\android-sdks\platform-tools>adb devices
List of devices attached emulator-5554 device 014FD87107021017
device
Step 2:
C:\Android\android-sdks\platform-tools>adb -s 014FD87107021017 install C:\Users\
user\Documents\appname.apk
Use the following scripts to install apk on multiple devices/emulators.
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do adb -s $SERIAL install -r /path/to/product.apk;
done
Remove -r if you are not reinstalling the apk. Also you can replace "install -r /path/to/product.apk" to other adb commands like working on one single device.
It works for me on real devices but I believe it should also works for emulators.
It is possible to issue install command simultaneously on all connected devices.
The key is to launch adb in a separate process (&).
I came up with the following script to simultaneously fire-off installation on all of the connected devices of mine and finally launch installed application on each of them:
#!/bin/sh
function install_job {
adb -s ${x[0]} install -r PATH_TO_YOUR_APK
adb -s ${x[0]} shell am start -n "com.example.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
}
#iterate over devices IP-addresses or serial numbers and start a job
while read LINE
do
eval x=($LINE)
install_job ${x[0]} > /dev/null 2>&1 &
done <<< "`adb devices | cut -sf 1`"
echo "WATING FOR INSTALLATION PROCESSES TO COMPLETE"
wait
echo "DONE INSTALLING"
Note 1: the STDOUT and STDERR are suppressed. You won't see any "adb install" operation result. This may be improved, I guess, if you really have to
Note 2: you could also improve script by providing args instead of hardcoded path and activity names.
That way you:
Don't have to manually perform install on each device
Don't have to wait for one install to finish in order to execute another one (adb tasks are launched in parallel)
yes you can install your apk file in multiple emulator for that you have to give the name in command prompt here is the link for guidance
http://developer.android.com/guide/developing/tools/emulator.html
You can install on multiple devices at a time using USB debugging.
In Eclipse
Run--> Run Configurations --> choose your project (on left) -->Target --> Launch on All compatible devices.
The selected project will be installed on all the connected devices

Categories

Resources