Mac Terminal - How to start Android Virtual Device Manager on CLI? - command-line

I am currently developing a mobile web application and I don't have a test device yet so I'm using the android-emulator to check the site. On my mac, I have installed the stand-alone Android SDK. Every time I want to use the AVD Manager, I have to execute the following on my terminal:
monitor
This command (being executed on the installed android sdk path) will open the Android Device Monitor and from here, I go to its menu bar and select Window Virtual Device Manager just to open the AVD Manager. So, is there a shortcut for that? I mean, i want to directly open the AVD manager via cli.

I was able to open it from terminal with:
android avd
You may need to navigate to your SDK tools/ first. Here is reference I used:
AVD Manager

Go to tools directory inside your android sdk like:
cd ~/Android/Sdk/tools
and enter run your avd as
./emulator -avd <your-avd>
You can find your avd name by running:
./emulator -list-avds

You can start emulator use terminal shell
emulator -avd <avd_name> [<options>]
options can be special -http-proxy, -dns-server setting. Get more options here
And to list all avd you can use:
emulator -list-avds
result like following:
4.7_WXGA_API_23
Nexus_5X_Edited_API_23
Example when I start Nexus_5X_Edited_API_23 emulator in OS X 10.11 with proxy setting
~/Library/Android/sdk/tools/emulator -netdelay none -netspeed full -avd Nexus_5X_Edited_API_23 -http-proxy http://username:password#local_server:8080

this is just a small addon to previous solutions presented. What is probably handy to do is to just jam this as a alias into your bash_profile like so:
Open your bash_profile:
nano ~/.bash_profile
Add this:
alias avd='cd /path-to-sdk/tools; ./android avd'
Source it again:
source ~/.bash_profile
In the CLI type:
avd
Now you can open up the AVD by just using avd in the command line. The only thing i haven't figured out how to make it stay alive after closing the terminal. Maybe somebody has tips on that.

Use the Android SDK Tools:
avdmanager
Or you can also start it by using the command below but it's deprecated though on newer version. Before executing it, make sure to export your Android SDK's tools directory in your ~/.bash_profile (i.e. export PATH="/Users/user/Software/android-sdk-macosx/tools:$PATH")
android avd
Old answer:
In order to open the avd manager on terminal, execute the following:
/usr/bin/java -Xmx256M -XstartOnFirstThread \
-Dcom.android.sdkmanager.toolsdir=/path/of/android-sdk-macosx/tools \
-classpath /path/of/android-sdk-macosx/tools/lib/sdkmanager.jar:/path/of/android-sdk-macosx/tools/lib/swtmenubar.jar:/path/of/android-sdk-macosx/tools/lib/x86_64/swt.jar \
com.android.sdkmanager.Main avd

emulator -avd <nameOfYourAvdEmulator>
Find the names of your emulators using avdmanager list avd:
avdmanager list avd
Name: Nexus_5X_API_23_Android_6.0
Device: Nexus 5X (Google)
Path: /Users/edward3/.android/avd/Nexus_5X_API_23_Android_6.0.avd
Target: Google APIs (Google Inc.)
Based on: Android 6.0 (Marshmallow) Tag/ABI: google_apis/x86
Skin: nexus_5x
Sdcard: 512M
Add to your ~/.profile if missing:
# Add to your ~/.profile PATH to easily run emulator and avdmanager commands
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
# Create alias to run your favorite Android emulator
alias avd-run='emulator -avd Nexus_5X_API_23_Android_6.0 &'
Open a new terminal or use source ~/.profile to reload changes made to your ~/.profile
Start your favorite emulator using the alias you created:
avd-run

Related

Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. Flutter 2.0

I updated My flutter Version from 1.22 to 2.0. There are some errors in Flutter Doctor. How Could I solve this. That happen Afer Updated my Flutter Version.
I am Using Android Studion 4.1.2, Ubuntu 20.04.2 LTS(64 bit)
For Ubuntu 20.04, chromium is managed by snap. I set the environment variable as shown below.
CHROME_EXECUTABLE=/snap/bin/chromium
export CHROME_EXECUTABLE
Try 'type chromium' to make sure of the location on your system. I assume something similar will work for chrome.
For ones who use MacOS and with another chromium-based browser than Google Chrome (Brave in my case). You can set in .zshrc or .bashrc
export CHROME_EXECUTABLE="/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
After that, don't forget to source ~/.zshrc or source ~/.bashrc in the current terminal window.
flutter doctor -v
Now, "Chrome" will be seen as "Brave".
I had the same error in Windows 10, Using VS Code even after setting CHROME_EXECUTABLE system environmental variable to the path of chrome.exe. I solved it by removing the double quotes around the path:
Even though you have a google chrome app in your system. It may have command like google-chrome-stable or chrome or any name to open chrome browser from terminal. Just duplicate the file with google-chrome name in /usr/bin/
Eg: I have google-chrome-stable as executable so my approach is like
sudo cp /usr/bin/google-chrome-stable /usr/bin/google-chrome
You may have bin in snap folder or some other folder depending on your installation way
If you're not having chrome as executable from terminal then create a symbolic link. Find your chrome binary file and use this command
sudo ln -s $PATH/[google-chrome-bin] /usr/bin/google-chrome
Replace [google-chrome-bin] with your binary file name
I'm on a Chromebook. I installed Flutter and Android Studio. When I ran $flutter doctor -v, I got the same error message that you got.
I didn't need to export the file path to my path environment. I just needed to install Chrome so that Flutter could find it on my Chromebook.
Here was the command that worked for me:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
Then I installed it using the Linux beta command (right click on the downloaded file, install using Linux beta). It installed it to this directory:
/usr/bin/
(Alternatively, for the install, I could've used this command:
sudo apt install ./google-chrome-stable_current_amd64.deb)
I ran flutter doctor -v and now it finds Chrome.
you can export PATH in your .bashrc or .zshrc if you use Linux or MAC OS
you can found installed chrome PATH using which
for example
which google-chrome
# example result : /opt/google/chrome/google-chrome
then add to .zshrc or .bashrc like this
# Chrome PATH
export PATH=$PATH:/opt/google/chrome
then restart source
source .zshrc # change if you use .bashrc
running the flutter doctor
you will see the output like this
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.1, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version
30.0.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
The answers here have helped me setup Flutter on Mac with Microsoft Edge instead of Chrome.
For that, you simply run from your terminal:
export CHROME_EXECUTABLE="/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
If you want to make this permanent, you should add the above line to the file
~/.zshenv or ~/.zshrc
Then save and restart terminal.
For Linux users, you can add Edge Browser like this...
first, add this path in .bashrc file path
PATH=$PATH:/usr/bin/microsoft-edge-stable
then execute this command
export CHROME_EXECUTABLE="/usr/bin/microsoft-edge-stable"
For MacOS Users
cd to /Users/<your user>
sudo nano ~/.zshenv
Add the following:
export PATH="$PATH:/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
export CHROME_EXECUTABLE="/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
Save the file and restart the IDE terminal
Run flutter doctor
For MacOs User (Vivaldi Browser)
This command sets your PATH variable for the current terminal window only. To permanently add CHROME_EXECUTABLE to your path
export CHROME_EXECUTABLE="/Applications/Vivaldi.app/Contents/MacOS/Vivaldi"
To permanently add CHROME_EXECUTABLE to your path
Open (or create) the rc file for your shell. Typing echo $SHELL in your Terminal tells you which shell you’re using. If you’re using Bash, edit $HOME/.bash_profile or $HOME/.bashrc. If you’re using Z shell, edit $HOME/.zshrc. If you’re using a different shell, the file path and filename will be different on your machine.
If you are using zsh create .zshrc enter a command touch .zshrc which will create a .zshrc file at your hardisk and vice versa for bash.
Go to your finder and press shift + command + H after that again hit a command shift + command + . you will find .zshrc file.
now open .zrch file and add your path
CHROME_EXECUTABLE="/Applications/Vivaldi.app/Contents/MacOS/Vivaldi"
and restart your terminal and you are done.
in my case it was because the name of my chrome was "google chrome 2.app"
i renamed it to "google chrome.app"
You can also try with just chrome instead of google-chrome.

Is there any command to launch directory in file manager of android using adb?

I want to open Download folder in my android phone using adb. I have example:
start . /path/to/that/folder command for command-prompt and nautilus /path/to/that/folder for ubuntu terminal.

Command in parcel.js --open 'google chrome' does not work on Windows, only works on MacOS

I use parcel.js to set up my project. This command --open 'google chrome' does not work on Windows, only works on MacOS. The error is: Windows cannot find 'google'. Make sure you typed the name correctly, and then try again.
The browser value passed to --open [browser] is platform-dependent:
Windows: chrome
Linux: google-chrome
MacOS: google chrome
Parcel uses the opn package to start the browser. From the opn documentation:
Type: string | string[]
Specify the app to open the target with, or an array with the app
and app arguments.
The app name is platform dependent. Don't hard code it in reusable
modules. For example, Chrome is google chrome on macOS,
google-chrome on Linux and chrome on Windows.
You may also pass in the app's full path. For example on WSL, this can
be /mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe
for the Windows installation of Chrome.

Android emulator reports unknown virtual device

i am having the same problem described in the following post "Android emulator reports unknown virtual device" Why does the Android emulator report "unknown virtual device", when the device is in my user directory? and have followed all of the instructions in an attempt to resolve but still i cannot run my AVD.
I only have one drive on my Windows 7 machine (C:) and the AVD is being created in the correct location -> C:\Users\MyUser\.android
Ive also tried to setup an environment variable "ANDROID_SDK_HOME"
The actual error is:
emulator: ERROR: unknown virtual device name: 'my_AVD'
emulator: could not find virtual device named 'my_AVD'
Can someone please help me?
For another reason i had to re-format my pc. After a quick rebuild its working fine now. I think the problem happened because in the previous installation of windows, i was playing around with HDD's. Somehow this had caused problems..
Solution: you should have a copy od .android in C:\<your user name>\.
Please try the below steps to solve the above issue -
in task manager kill adb in process
in android sdk folder .. /tools/ run adb kill-server in command line
Check the avd folder name in " ../.adroid/avd/" - say it is "avd1"
run command "emulator -avd avd1 " under android folder "../tool/" in command line
it will start the avd1 device
Now start the eclipse and run your project with setting the "manula" option in configuration.
It will ask for choosing the avd between "avd1" and the existing list of avd's in eclipse if any. You choose "avd1" as it is already running.

Android Emulator sdcard push error: Read-only file system

I am developing under Android 1.6 (Android SDK 2.1).
I create a avd by using avd manager in Eclipse.
When I launch this avd, I found that the /sdcard directory's permisson is "d---------".
So I can't push file to the sdcard.
Does anyone know how to solve this problem?
I found this works
$./adb shell
$su
mount -o rw,remount rootfs /
chmod 777 /mnt/sdcard
exit
Source: http://www.coderanch.com/t/611842/Android/Mobile/Android-emulator-sdcard-writable
Once you started the Emulator from one shell, login to another shell & type
adb shell
You should see # prompt displayed, this is your device(emulator) shell. Now , type following command at adb shell.
mount -o remount rw /sdcard
This will now remount /sdcard with rw(read-write) permission & now you can push your files into /sdcard by using following command from your host shell.
`adb push filename.mp3 /sdcard,`
where filename.mp3 could be any file that you want to push into Android Emulator.
Hope this helps :)
Ensure two things in the AVD manager utility for the emulator:
SD Card size is mentioned e.g. 512.
From the Hardware tag, press New and select "SD Card Support" from the drop down menu.
Now, start the emulator. SD Card shall now support writing as well.
Android studio version 0.8.9 and above has a bug creating AVDs.
See Issue 78434.
Workaround
go to your ADV folder in .android folder and find your AVD config.ini
open it with a text editor that can handle unix newlines. (Notepad will run the lines together since they don't have CR-LFs.)
change hw.sdCard=no to hw.sdCard=yes
this should work for everyone in new builds
Maybe it sounds stupid but it worked for me when I had the same problem: delete the created avd and create one again through AVD Manager with a sd card of, for example, 512MB.
Check that both have the correct permissions and if not, try to change them with chmod.
And if everything still fails, repeat the process but creating both avd and sd card manually via terminal:
android create avd -n my_avd -t 7
mksdcard -l e 512M mysdcard.img
emulator -avd my_avd -sdcard mysdcard.img
Hope that helps!
I think the problem here is that you forgot to set SD card size
Follow these steps to make it work:
step1: close running emulator
step2: open Android Virtual Device Manager(eclipse menu bar)
step3: choose your emulator -> Edit -> then set SD card size
This works well in my emulator!
Make sure that you had given a value which is greater than zero for SD Card size in the Create AVD Window for that particular emulator.
mount -o remount, rw /sdcard
this is the correct way to remount your sdcard using your emulator.
I tried #user2002993 great help but it one place it need to be a little edit so I edited and here what worked for me on Android Studio, emulator android 5.
Go to your adb folder right click on blank area and select "open command window here" or if you installed adb by adb-installer open cmd and type these commands:
adb devices
It should show your emulator number and detail. Then followed command here:
adb shell
Now it should show you prompt #
su
mount -o rw,remount rootfs
chmod 777 /mnt/sdcard
exit
exit
Yeah double exit needed, now your prompt of adb shell is gone. Put a file in to your adb folder and give this command and see if it got fixed.
adb push "your file name like : 1.jpg" /sdcard/
or
adb push "your file name like : 1.jpg" /storage/sdcard/
Now in cmd it shoudl show you transfer time instead of creepy read-only thing 😊
I increased the virtual memory of sdcard up to 512 MB for the emulator and that was enough
I guess, you didn't insert memory size at the time of creating avd. you can do that by editing the avd.
make sure that you have the correct permissions.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Windows uses backward slashes, linux uses forward slashes.
sometimes this can cause of a very simple reason,
go to your list in eclipse and check whether you have set SDCard size
I had this problem on Android L developer preview, and, at least for this version, I solved it by creating an sdcard with a size that had square 2 size (e.g 128M, 256M etc)
In adb version 1.0.32 and Eclipse Luna (v 4.4.1).
I found a directory in the avd /mnt/media_rw/sdcard that you can write to using the adb command.
adb push {source} /mnt/media_rw/sdcard
There appears to be rw access to this directory.
Hope this helps :-)
Alternate way:
Dismount the drive (from settings/storage) and re-mount the sdcard
also fixes the problem. (verify by moving a file from internal storage to sdcard)
In any case, this simple method saved my butt this time :)
Give any size to Sdcard in Emulator
unchecked the read only option from c:\user...android\avd -> properties
push a file through file explorer
restart the Emulator
It will definitely works
With me in the end helped
In the emulator to run applications manager
and setting permissions for storage.
Try this in a Terminal Emulator as root:
restorecon -v -R /data/media