ADB reject shell command (cat/proc/3655/stat):closed - android

I'm using ubuntu 16.10. When I start my emulator from android studio I got this error:
"ADB reject shell command (cat/proc/3655/stat):closed"
And its not opening. But I can run emulator from command line by following command:
"LD_PRELOAD='/usr/lib/x86_64-linux-gnu/libstdc++.so.6' ~/Android/Sdk/tools/emulator -netdelay none -netspeed full -avd Nexus_5X_API_25"
And it shows the warning message:
"emulator: WARNING: encryption is off"

It may be occur due to your 64bit linux didn't match to the avd you installed. Try copy 'lib' folder from your Android sdk location -> ../Android/Sdk/tools/lib64/qt/lib to ../Android/Sdk/tools/lib/qt/lib

Related

custom android 11 update

I try to develop an android system, I have some problems with development.
I get used to ubuntu18 and tag of android 11 is android-11.0.0_r17,
I have built successfully with lunch 30 "aosp_x86-eng" and I have seen $OUT files and checked
then I prepared test_aosp.sh file under ~/bin
the results are like that and no emulator window appears:
$ ./test_aosp.sh
emulator: Android emulator version 30.0.21.0 (build_id 6647651) (CL:N/A)
emulator: Found AVD name 'a25x86'
emulator: Found AVD target architecture: x86
emulator: argv[0]: 'emulator'; program directory: '/home/ubuntu/aosp/prebuilts/android-emulator/linux-x86_64'
PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT
the content of test_aosp.sh is :
#!/bin/sh
emulator -avd a25x86 -verbose -show-kernel -system $OUT/system.img -ramdisk $OUT/ramdisk.img -initdata $OUT/userdata.img
when I checked ROGER YE notes, before that partition he had run ~/Android/Sdk/emulato/emulator #a25x86, also I did it with the last version of android studio.
Also, I try to do the following thing but is has a loop in the command line and the black window of emulator shows up but not appear any menu and any more:
$ sudo ~/Android/Sdk/emulator/emulator -avd a25x86 -verbose -show-kernel -system $OUT/system.img -ramdisk $OUT/ramdisk.img -initdata $OUT/userdata.img
also I have checked the emulator location with the following command:
$ which emulator
/home/ubuntu/aosp/prebuilts/android-emulator/linux-x86_64/emulator
also I want to add following results, maybe you want to check it:
$ printenv |grep ANDROID
ANDROID_DEV_SCRIPTS=/home/ubuntu/aosp/development/scripts:/home/ubuntu/aosp/prebuilts/devtools/tools:/home/ubuntu/aosp/external/selinux/prebuilts/bin:/home/ubuntu/aosp/prebuilts/misc/linux-x86/dtc:/home/ubuntu/aosp/prebuilts/misc/linux-x86/libufdt
ANDROID_TOOLCHAIN_2ND_ARCH=
ANDROID_PRE_BUILD_PATHS=/home/ubuntu/aosp/prebuilts/jdk/jdk11/linux-x86/bin:
ANDROID_HOST_OUT_TESTCASES=/home/ubuntu/aosp/out/host/linux-x86/testcases
ANDROID_JAVA_TOOLCHAIN=/home/ubuntu/aosp/prebuilts/jdk/jdk11/linux-x86/bin
ANDROID_TARGET_OUT_TESTCASES=/home/ubuntu/aosp/out/target/product/generic_x86/testcases
ANDROID_BUILD_TOP=/home/ubuntu/aosp
ANDROID_BUILD_PATHS=/home/ubuntu/aosp/out/soong/host/linux-x86/bin:/home/ubuntu/aosp/out/host/linux-x86/bin:/home/ubuntu/aosp/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin:/home/ubuntu/aosp/development/scripts:/home/ubuntu/aosp/prebuilts/devtools/tools:/home/ubuntu/aosp/external/selinux/prebuilts/bin:/home/ubuntu/aosp/prebuilts/misc/linux-x86/dtc:/home/ubuntu/aosp/prebuilts/misc/linux-x86/libufdt:/home/ubuntu/aosp/prebuilts/clang/host/linux-x86/llvm-binutils-stable:/home/ubuntu/aosp/prebuilts/android-emulator/linux-x86_64:/home/ubuntu/aosp/prebuilts/asuite/acloud/linux-x86:/home/ubuntu/aosp/prebuilts/asuite/aidegen/linux-x86:/home/ubuntu/aosp/prebuilts/asuite/atest/linux-x86:
ANDROID_EMULATOR_PREBUILTS=/home/ubuntu/aosp/prebuilts/android-emulator/linux-x86_64
ANDROID_PRODUCT_OUT=/home/ubuntu/aosp/out/target/product/generic_x86
ANDROID_PYTHONPATH=/home/ubuntu/aosp/development/python-packages:
ANDROID_TOOLCHAIN=/home/ubuntu/aosp/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin
ANDROID_JAVA_HOME=/home/ubuntu/aosp/prebuilts/jdk/jdk11/linux-x86
ANDROID_HOST_OUT=/home/ubuntu/aosp/out/host/linux-x86
Could you guide me?
Thank you
Regards
if you successfully built, you can run emulator without additional arguments. Just typing emulator in console.
Or, please try to set ANDROID_SDK_ROOT as suggested.
export ANDROID_SDK_ROOT=/path/to/your/sdk/for/avd

Error Starting Android Emulators on Ubuntu 18

I'm attempting to start an Android emulator on Jenkins CI, but the startup never completes. On CI the command is running in a Docker image based on ubuntu:18.04. I'm using the following command to start the emulator:
/opt/android-sdk-linux/emulator/emulator -no-audio -no-window -delay-adb \
#Pixel_C_API_25 &
Then I wait for the emulator to complete with:
adb wait-for-device
On my developer machine (macOS 10.14.6), the emulator finishes starting and adb wait-for-device returns, but on CI the emulator never finishes launching. The relevant portions of the log output are here:
Starting emulator
Waiting for emulator
* daemon not running; starting now at tcp:5037
statvfs('/home/ec2-user/.android/avd/Pixel_C_API_25.avd/snapshots/default_boot/ram.img') failed: No such file or directory
### WARNING: could not find /usr/share/zoneinfo/ directory. unable to determine host timezone
emulator: WARNING: encryption is off
Your emulator is out of date, please update by launching Android Studio:
- Start Android Studio
- Select menu "Tools > Android > SDK Manager"
- Click "SDK Tools" tab
- Check "Android Emulator" checkbox
- Click "OK"
* daemon started successfully
### WARNING: could not find /usr/share/zoneinfo/ directory. unable to determine host timezone
Sending interrupt signal to process
Terminated
script returned exit code 143
I think the "emulator is out of date" warning is a red herring, as it doesn't cause problems for me locally. I think the more likely problem is:
statvfs('/home/ec2-user/.android/avd/Pixel_C_API_25.avd/snapshots/default_boot/ram.img') failed: No such file or directory
But I haven't been able to find info on what would cause this problem or fix it. Locally the ram.img file is present.
I've tried with AVDs based on the following system images. Previously there seemed to be an error with x86 not being supported on the x86-related images, but I'm no longer getting that error. Instead, all of them give the above ram.img error:
system-images;android-25;google_apis;arm64-v8a
system-images;android-25;google_apis;armeabi-v7a
system-images;android-28;google_apis;x86_64
system-images;android-28;google_apis;x86
system-images;android-28;default;x86_64
In each case I create the AVD with commands analogous to the following:
sdkmanager --install "system-images;android-25;google_apis;armeabi-v7a"
avdmanager create avd --force --name Pixel_C_API_25 --abi google_apis/armeabi-v7a --package "system-images;android-25;google_apis;armeabi-v7a" --device "pixel_c"
Has anyone successfully gotten an Android emulator to start on Ubuntu 18, and if so, which system image did you use?

-list-avds then launch results in PANIC

I listed the emulators using:
emulator -list-avds
Attempt to launch an emulator:
emulator -avd Pixel_XL_API_25
And terminal replies:
PANIC: Unknown AVD name [Pixel_XL_API_25], use -list-avds to see valid list.
ANDROID_AVD_HOME is defined but could not find Pixel_XL_API_25.ini file in $ANDROID_AVD_HOME
(Note: avd is searched in the order of $ANDROID_AVD_HOME,$ANDROID_SDK_HOME/.android/avd and $HOME/.android/avd)
The path actually seems off:
echo $ANDROID_AVD_HOME
Produces:
/Users/alex/.android
Which should be: /Users/alex/.android/avd
Fixed that, new exception:
[140737069994944]:ERROR:./android/qt/qt_setup.cpp:28:Qt library not found at ../emulator/lib64/qt/lib
Could not launch '../emulator/qemu/darwin-x86_64/qemu-system-i386': No such file or directory
Does anyone know how to resolve this?
A solution that worked helped was to update my bash profile:
export ANDROID_HOME=${HOME}/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/emulator
Could not launch emulator in Android Studio
Note:
I still can't use the GUI integrated into Android Studio. I have to run the emulator command:
sudo emulator -avd Nexus_Emulator

How do I run android tests in the emulator using IntelliJ?

I'm trying to run the sample unit tests for the sample code that ships with the android SDK. Some of the tests run as standard unit tests, no problem. Other tests, such as com.example.android.apis.view.Focus2AndroidTest, use android classes, and therefore need to run in the emulator, that is a problem.
I can run applications just fine in my emulator. When I run tests, though, my emulator starts up, and then just sits there. The test never runs. All I see in the output window in IntelliJ is
Waiting for device.
/Users/rfzabick/android-sdk-mac_x86/tools/emulator -avd MyAvd0 -netspeed full -netdelay none
Device connected: emulator-5554
What am I doing wrong?
EDIT:
After #CrazyCoder's advice, I switched to android 4.0.3 (API 15). Here's what I got:
Testing started at 4:34 PM ...
Waiting for device.
/Users/rfzabick/android-sdk-mac_x86/tools/emulator -avd android4.0.3--api15 -netspeed full -netdelay none -wipe-data -no-boot-anim
Device connected: emulator-5554
Device is online: emulator-5554
Target device: emulator-5554 (android4.0.3--api15)
Uploading file
local path: /Users/rfzabick/IdeaProjects/ApiDemos/out/production/Tests/Tests.apk
remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device is not ready. Waiting for 20 sec.
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device is not ready. Waiting for 20 sec.
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device disconnected: emulator-5554
pkg: /data/local/tmp/com.example.android.apis.tests
Running tests
Test running startedTest running failed: com.android.ddmlib.AdbCommandRejectedException: device not found
Empty test suite.
The only relevant thing I see in logcat is
01-21 16:36:22.047: WARN/ActivityManager(91): No content provider found for permission revoke: file:///data/local/tmp/com.example.android.apis.tests
Can you run normal apps in the emulator or USB device? Try to create the new emulator device and see if helps.
I've tried it with IDEA 11.0.1, 4.0.3 Android platform on Windows and it works fine:
Waiting for device.
Target device: emulator-5554 (ICS)
Uploading file
local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\Tests\Tests.apk
remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
pkg: /data/local/tmp/com.example.android.apis.tests
Success
Running tests
Test running startedFinish
You can also try to restart adb with adb kill-server and start the emulator manually from AVD manager.
Verify that there is no pre-installed ApiDemos application in the emulator, or the signatures will not match. Uninstall existing ApiDemos, then try to deploy and run ApiDemos from IntelliJ IDEA, then try to run the test configuration again.
UPDATE: We did some research and found the source of the problem. By default IntelliJ IDEA sets the dependency scope for the application module inside test module to Compile, so that all the production and test classes get compiled into the single Test.apk.
Instead, the scope must be set to Provided and we'll fix it in the next update. Right now you need to correct it manually as shown on the screenshot:
Rebuild the project and run the tests, again, this time 2 separate apk files will be deployed, one for the main app and the second one for the tests, then tests will run:
Waiting for device.
Target device: emulator-5554 (ICS)
Uploading file
local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\Tests\Tests.apk
remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
pkg: /data/local/tmp/com.example.android.apis.tests
Success
Uploading file
local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\ApiDemos\ApiDemos.apk
remote path: /data/local/tmp/com.example.android.apis
Installing com.example.android.apis
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis"
pkg: /data/local/tmp/com.example.android.apis
Success
Running tests
Test running startedFinish
You can run the instrumentation from ant, from the command line of from a script. In case you prefer the latter this post may be of help.
Running unit tests in emulator is not practical (basically takes too long). And since android jars are usefull only to compiling, it seems impossiblble to run them with unit tests. Good alternative is use of advanced mocking framework ( I personally prefer jMockit,
but there are other )
See example:
https://github.com/ko5tik/andject/blob/master/src/test/java/de/pribluda/android/andject/ViewInjectionTest.java
Here I test my class against derived android activity, and it has to call superclass methods
(this runs in maven, eclipse or IDEA on the spot )

How do I launch the Android emulator from the command line?

I'm on Mac, working on Android development from the terminal. I have successfully created the HelloWorld project and now I'm trying to run it from the command line in the Android emulator. Which command runs the emulator for my HelloWorld project?
I already have the Android tools and platform-tools in my PATH.
Edit:
How do I tell the emulator to run my HelloWorld project from the command line? I've already built the project with ant.
I assume that you have built your project and just need to launch it, but you don't have any AVDs created and have to use command line for all the actions. You have to do the following.
Create a new virtual device (AVD) for the platform you need. If you have to use command line for creating your AVD, you can call android create avd -n <name> -t <targetID> where targetID is the API level you need. If you can use GUI, just type in android avd and it will launch the manager, where you can do the same. You can read more about AVD management through GUI and through command line.
Run the AVD either by using command emulator -avd <name> or through previously launched GUI. Wait until the emulator fully loads, it takes some time. You can read about additional options here.
Now you have to install the application to your AVD. Usually during development you just use the same Ant script you used to build the project, just select install target. However, you can install the application manually using command adb install <path-to-your-APK>.
Now switch to emulator and launch your application like on any normal device, through the launcher. Or, as an alternative, you can use the following command: adb shell am start -a android.intent.action.MAIN -n <package>/<activity class>. For example: adb shell am start -a android.intent.action.MAIN -n org.sample.helloworld/org.sample.helloworld.HelloWorld. As a commenter suggested, you can also replace org.sample.helloworld.HelloWorld in the line above with just .HelloWorld, and it will work too.
List all your emulators:
emulator -list-avds
Run one of the listed emulators with -avd flag:
emulator -avd name-of-your-emulator
where the emulator executable is under:
${ANDROID_SDK}/tools/emulator
Or, for newer SDKs, try:
cd ${ANDROID_HOME}/emulator
emulator -avd name-of-your-emulator
I think the best way to reach it via terminal is :
cd ~/Library/Android/sdk/emulator
Or for Windows:
cd %userProfile%\AppData\Local\Android\sdk\emulator
To run a certain AVD directly:
./emulator -avd {AVD_NAME}
To list your AVDs use :
./emulator -list-avds
Just to add here, whenever you get "error: device offline" means that connection with emulator & adb bridge has been broken due to time taken in emulator startup.
Rather than re-starting emulator at this point try below two commands which stops & start adb bridge again.
adb kill-server
adb start-server
Here you can check the options to execute this command via command-line:
emulator -avd avd_name [-option [value]] ... [-qemu args]
For example, I use it like this below:
emulator -avd ICS_ARM -wipe-data -no-boot-anim -cpu-delay 0
open CMD
Open Command Prompt
type the path of emulator in my case
C:\adt-bundle-windows-x86_64-20140702\sdk\tools
write "emulator -avd emulatorname" in my case
emulator -avd AdilVD
If you are strictly trying to run the emulator from the command line try this in OSX.
"/Applications/Android Studio.app/sdk/tools/emulator" -avd <NAMEOFDEVICE> -netspeed full -netdelay none
You can simplify it by adding an alias to the .bash_profile, and sending it to a background job.
alias android='/Applications/Android\ Studio.app/sdk/tools/emulator <NAMEOFDEVICE> -netspeed full -netdelay none &'
Let Bash know about the changes.
source ~/.bash_profile
Instructions for Mac with zsh:
Open terminal window (CTRL+ALT+T)
Run command
nano ~/.zshrc
to edit your profile
Add following lines in the opened file:
export ANDROID_SDK_HOME="~/Library/Android/Sdk"
alias emulator="$ANDROID_SDK_HOME/emulator/emulator"
Save the file (CTRL+O, CTRL+X)
Source the profile by running command source ~/.zshrc or just log out and log back in
Test by running the command:
emulator -help or emulator -list-avds
to show your simulator in terminal
and run Android emulator with command:
emulator -avd <name>
NOTE: Should be same for bash by replacing .zshrc with .bashrc
Open command prompt and go to <android-Home>\sdk\tools>emulator -avd <AVD_NAME>
Here "emulator" is the command used to open your Android Virtual Device.
If you have Git Bash you can open your emulator with a double-click, with some initial setup (tested in Windows 10 only):
Open Git Bash.
Run cd ~/AppData/Local/Android/sdk/emulator
Run ./emulator -list-avds and keep note of the emulator's name. MY_EMULATOR for example.
Open Notepad and add these two lines (insert your emulator's name instead of MY_EMULATOR):
cd ~/AppData/Local/Android/sdk/emulator; ./emulator -avd MY_EMULATOR
Save the file somewhere convinient as myfile.sh. You can change "myfile" as suits you best, but the extension .sh is needed.
Open Git Bash at the directory where you stored myfile.sh and run chmod +x myfile.sh. Remember to put your file's name instead of myfile.
And that's it! From now on, everytime you need to start that emulator, just locate your myfile.sh and double click on it and wait for your Android emulator to launch!
To list all the devices installed: emulator -list-avds
This will list all the devices installed inside your Android Studio.
To run emulator: emulator -avd device_name
For example, if you got Pixel_3a_API_30_x86 after running the command in option 1, then your command to run emulator will be: emulator -avd Pixel_3a_API_30_x86
The android create avd command is deprecated. It's now recommended to use avdmanager instead to launch emulators from the command line.
First, create a new emulator if one doesn't already exist:
avdmanager create avd --name "MyEmulator" -k "system-images;android-
26;google_apis;x86"
This assumes that you already have an X86 system image installed that matches API 26, and has the Google APIs installed.
You can then launch the emulator with emulator #MyEmulator.
Open CMD
To get all Emulator list (C:\Users\DJango\AppData\Local\Android\sdk\emulator>emulator -list-avds)
Choose any emulator
(C:\Users\DJango\AppData\Local\Android\sdk\emulator>emulator -avd Pixel_2_API_28)
(Linux)
In you terminal Copy & Paste and changing the three fields in blue
/home/YouUser/Folder/adt-bundle-linux-x86_64-20140702/sdk/tools/emulator64-x86 -avd Android5.1.1
YouUser = user of session in linux
Folder = path of folfer
Android5.1.1 = You version of android in the emulator,for example (Android4.4.2)
you can view the emulators in you folder home
cd /home/Youuser/.android/avd/
Nowadays asuming you have Android Studio installed (2.2) in my case and just 1 emulator you might use this one liner
export ANDROID_SDK_ROOT=~/Library/Android/sdk/ && emulator '#'`emulator -list-avds`
If you do this often, make it easier:
$ echo 'export ANDROID_SDK_ROOT=~/Library/Android/sdk/' >> ~/.profile
Add an alias to ~.aliases
alias androidup="emulator '#'`emulator -list-avds`"
Recall to source ~/.profile ~/.aliases before testing it
Next time just $ androidup
Go to the directory where emulator is located
${ANDROID_SDK}/tools/emulator
Check emulator list from CLI
emulator -list-avds
Run a AVD from the list
emulator -avd {avd_name}
list of avd name available on
.android/avd
/SDK_PATH/tools/emulator -netdelay none -netspeed full -avd
"AVD_NAME"
In windows, I use this PowerShell script to start it up.
$em = $env:USERPROFILE+"\AppData\Local\Android\sdk\tools\emulator.exe";
Start-Process $em " -avd Nexus_5X_API_24" -WindowStyle Hidden;
For automation (CI) we did something like below steps:
Frist, find SDK's tools location, and store in variable for later use.
tools=$ANDROID_HOME/cmdline-tools/latest/bin
arch="x86_64"
package="system-images;android-23;google_apis;$arch"
Ensure Android-image's downloaded.
$tools/sdkmanager "$package"
Accept the licenses.
echo yes | $tools/sdkmanager --licenses
Create AVD.
echo no | $tools/avdmanager create avd --force --name MyAVD --abi google_apis/$arch --package "$package"
Says "no" to "Do you wish to create a custom hardware profile? ..."
Launch emulator parallel.
$ANDROID_HOME/emulator/emulator -netdelay none -netspeed full -no-snapshot-load -no-snapshot -avd MyAVD > /dev/null &
Build APK.
./gradlew assembleDebug
At last, Android-tests (Instrumented tests) automatically detect and run on Emulator.
./gradlew connectedAndroidTest
Note that because we launch Emulator parallel, you need to wait until Emulator is ready, and that before Step #7.
Maybe count build-time with script, and if build takes less than what Emulator-launch takes, call sleep.
I am late, here but want to share so may be it help some one and me too when ever needed later :) ,
So below is the way to open emulator from command line with one command using bash script.
I am using MX Linux but process is same on all operating systems
1- First Check the installed emulators
emulator -list-avds
it will result like below
emulator -list-avds
Nexus_4_API_28
Pixel_2_API_28
2- open any plain text or code editor and create a new file and write as below
#!/bin/sh
emulator -avd Nexus_4_API_28
Nexus_4_API_28 is the emulator that i want to open you write yours which you got from first step
save this file with .sh extension
3- Then, change the permissions on the file to make it executable:
chmod u+x emu.sh
4- Now open the emulator just executing this bash script file with following command
./emu.sh
For one-click (BATCH file) launch, this is what I've done:
got the name of AVD from Android Studio -> Tools -> AVD Manager -> Click on Arrow Down and choose View Details ( for me it's Pixel_2_API_28, so change accordingly below)
create an start.bat file and put the following inside:
c:
cd C:\Program Files (x86)\Android\android-sdk\emulator\
emulator -avd Pixel_2_API_28
Explanations:
First line: for me was necessary because I am launching it from d:
Second line: for me was not working the tools\emulator
Third line:
make sure you change the name of the AVD with yours (here
Pixel_2_API_28)
Using:
launch start.bat from command line
easily type this command in cmd.
replace after Users\ your user name \
if you don't have this file reinstall android studio.
On Mac (and Linux I think), after you have created your AVD, you can make an alias:
alias run-android='~/Library/Android/sdk/tools/emulator -avd ${YOUR_AVD_NAME} &'
Note: the execution of the alias will not lock your terminal, if you want that, just remove the last '&'.
Run emulator it self will give you an error because he expect that, in your current position, you have: /emulator/qemu/${YOUR_PATFORM}/qemu-system-x86_64' to start the emulator.
I wrote this simple shell script using Zenity that lets you pick which avd you want to run. If you don't have ANDROID_HOME defined, you can just replace that with the full path to emulator.
This would be easy to do with select instead of Zenity also, but I opted for Zenity since I'm running it from the xfce-application menu (though a .desktop-file).
#!/bin/sh
opt=$(zenity --title="Choose AVD" --text="Choose which emulator to start" --list \
--column="Devices" --separator="\n" `$ANDROID_HOME/emulator/emulator -list-avds`);
$ANDROID_HOME/emulator/emulator -avd $opt
Run the first emulator available:
~/Library/Android/sdk/tools/emulator -avd `~/Library/Android/sdk/tools/emulator -list-avds | awk '{print $1}'`
A launcher script which lists existing AVDs and lets you pick the one you want. Requires python3 (at least v3.4) and a valid environment variable ANDROID_HOME or ANDROID_SDK pointing to the Android SDK dir.
#!/usr/bin/env python3
import os
import subprocess
from pathlib import Path
android_emulator_dir: Path = Path(os.environ['ANDROID_HOME'] or os.environ['ANDROID_SDK']) / 'emulator'
if android_emulator_dir.exists():
emulator_dir = android_emulator_dir.absolute()
print(f'SDK emulator dir: {emulator_dir}', end='\n\n')
proc = subprocess.Popen(['./emulator', '-list-avds'], stdout=subprocess.PIPE, cwd=emulator_dir, text=True)
avds = {idx: avd_name.strip() for idx, avd_name in enumerate(proc.stdout, start=1)}
print('\n'.join([f'{idx}: {avd_name}' for idx, avd_name in avds.items()]))
avd_idx = input("\nType AVD index and press Enter... ")
avd_name = avds.get(int(avd_idx))
if avd_name:
subprocess.Popen(['./emulator', '-avd', avd_name, '-no-boot-anim'], cwd=emulator_dir)
else:
print('Invalid AVD index')
else:
print(f'Either $ANDROID_HOME or $ANDROID_SDK must be defined!')
AppleScript version (MacOS only)
osascript -e '
set avds to paragraphs of (do shell script "~/Library/Android/sdk/emulator/emulator -list-avds")
set avd to (choose from list avds with prompt "Please select an AVD to start" default items "None" OK button name {"Start"} cancel button name {"Cancel"})
do shell script "~/Library/Android/sdk/emulator/emulator -avd " & avd & " -no-boot-anim > /dev/null 2>&1 &"
'
The script above can also be run from the Script Editor.app or from Automator.app (the bit between the single quotes). Also you can use Script Editor to save it as a native macos app: select File on the menu, press and hold the ⌥ (Option) key, select Save As and then select File Format: Application.
windows 10 what helped me:
1 cd C:\Users\xxx\AppData\Local\Android\Sdk\emulator
2 list all the available: emulator -list-avds
3 start as NON-GUI mode: emulator -avd Pixel_3a_API_30_x86 -no-window
For Windows:
Search Environment in Windows Search Bar and choose "Edit the System Environment Variable"
In the System Properties window, click on Environment Variable and specify the value of the PATH environment variable:
C:\Users\{USER}\AppData\Local\Android\Sdk\emulator.
Now open CMD or Powershell and type:
emulator -list-avds
This will show list of all AVDs.
To run specific AVD, type in CMD/Powershell: emulator -avd {EmulatorName}
If you have added correct path of the android emulator, AVD will open.
If you already have emulator and wanted to use that using command just use this 1 line code only
cd C:\Users\yourUserName\AppData\Local\Android\Sdk\emulator | ./emulator -avd Pixel_5_API_32
Thanks me Later...
Starting emulator from command line with dns help
Emulator program location : /Users/{{UserName}}/Library/Android/sdk/tools
Check existing avd :-
emulator -list-avds
Start emulator with dns set
/Users/{{UserName}}/Library/Android/sdk/tools/emulator -avd Pixel_API_26 -dns-server 8.8.8.8

Categories

Resources