Unable to start emulator from command line - android

I am trying to run the below shell script:
#!/usr/bin/env bash
sdkmanager "emulator" "system-images;android-28;google_apis_playstore;x86_64"
echo no | avdmanager create avd -n "Android" -k "system-images;android-28;google_apis_playstore;x86_64" --device 'Nexus 6P'
$ANDROID_HOME/tools/emulator -avd Android -no-audio -no-boot-anim -no-snapshot -timezone Asia/Phnom_penh
I have added the ANDROID_HOME, ANDROID_AVD_HOME to my PATH (Note: I am using macos with zsh) and i have sourced the zshrc file and also restarted the terminal but keep getting the below error:
./start_emulator.sh: line 3: sdkmanager: command not found
./start_emulator.sh: line 4: avdmanager: command not found
PANIC: Unknown AVD name [ANDROID], use -list-avds to see valid list. ANDROID_AVD_HOME
is defined but there is no file Android.ini in $ANDROID_AVD_HOME/.android/avd (Note:
Directories are searched in the order $ANDROID_AVD_HOME,
$ANDROID_SDK_HOME/avd, and $HOME/.android/avd)

Changing the shell script to below does the job:
#!/bin/zsh
cd $ANDROID_HOME/tools/bin
./sdkmanager "emulator" "system-images;android-28;google_apis_playstore;x86_64"
echo no | ./avdmanager create avd -n "Android" -k "system-images;android-28;google_apis_playstore;x86_64" --device 'Nexus 6P'
$ANDROID_HOME/tools/emulator -avd Android -no-audio-no-boot-anim -no-snapshot -timezone Asia/Phnom_penh
Also running the commands individually(after moving to the folder) seem to work.Not sure if its a permission issue.

Related

How to create an AVD for "system-images;android-27;google_apis;x86" using avdmanager command line in Ubuntu?

I am able to create emulators for android-26 and older using the avdmanager command line, but I am getting the following error when trying to create for android-27 and above:
~/Android/sdk/tools/bin/avdmanager create avd --force -n Tablet -k "system-images;android-27;google_apis;x86" -d 6 --sdcard 200M
Error: Package path is not valid. Valid system image paths are:ository...
system-images;android-26;google_apis;x86
null
The same command for android-26 works:
~/Android/sdk/tools/bin/avdmanager create avd --force -n Tablet -k "system-images;android-26;google_apis;x86" -d 6 --sdcard 200M
Am I missing anything?
P.S.: This is happening in Linux Ubuntu. It seems to work fine in Mac OS.
Your command is correct but problem is that in your system, you don't have "android-27" OS
Please check which OS you have in your system, go into following directory
directory path : ~\Android\Sdk\platforms
if you don't have it please download it first.
download command is : sdkmanager --install "system-images;android-27;google_apis;x86"

AVDMANAGER -> Error: Invalid --tag default for the selected package

$ avdmanager create avd -n test -k "system-images;android-24;google_apis;x86"
Error: Invalid --tag default for the selected package.
How to solve this error?
Use the --abi google_apis/x86 flag.
The data store that the sdkmanager v26.1.1 uses is out of date.
Update your tools with:
sdkmanager --update
It will then have the updated tags to choose from. One can also run:
avdmanager -v create avd -g google_apis -n Android-27 -k "system-images;android-27;google_apis;x86"
But always better to run with updated tools.

Travis CI android emulator can't be created with avdmanager

I want to build and test an Android app using an emulator in Travis CI.
On my local machine I can create emulator with both android and avdmanager tools, examples:
echo no | android create avd --force --name test01 --package 'system-images;android-27;google_apis_playstore;x86'
echo no | avdmanager create avd --force --name test02 --package 'system-images;android-27;google_apis_playstore;x86'
But on Travis there's no avdmanager in $ANDROID_HOME/tools/bin
When I tried to create emulator with android tool (which isn't desired because it's deprecated) it turned out that it's different from version installed on my mac and requires different parameters
My .travis.yml file (vars and build steps removed for clarity):
sudo: true
os: linux
dist: trusty
language: android
android:
components:
- build-tools-26.0.2
- android-26
before_script:
- echo no | android create avd --force --name test --package 'system-images;android-27;google_apis_playstore;x86'
#- echo no | avdmanager create avd --force --name test --package 'system-images;android-27;google_apis_playstore;x86'
script:
- echo "DEBUG searching for avdmanager" && ls -lAp $ANDROID_HOME/tools/bin
So could you please advice how should I create Android emulator in Travis CI?
After playing around the official ways, the simplest way I found to launch one emulator on travis has at least this in travis.xml
before_install:
# Install SDK license so Android Gradle plugin can install deps.
- mkdir "$ANDROID_HOME/licenses" || true
- echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
# Install the rest of tools (e.g. avdmanager)
- sdkmanager tools
# Install the system image.
- sdkmanager "system-images;android-24;default;armeabi-v7a"
# Create and start emulator for the script. Meant to race the install task.
- echo no | avdmanager create avd --force -n emulatorApi24 -k "system-images;android-24;default;armeabi-v7a"
- $ANDROID_HOME/emulator/emulator -avd emulatorApi24 -no-audio -no-window &
before_script:
- android-wait-for-emulator
# Disable animations
- adb shell settings put global window_animation_scale 0 &
- adb shell settings put global transition_animation_scale 0 &
- adb shell settings put global animator_duration_scale 0 &
- adb shell input keyevent 82 &
script: ./gradlew connectedAndroidTest # Run emulator tests
Now my travis build takes 20 minutes :D
As a reference, a good place to check a working example is the U+2020 project.

Not able to Create AVD using command line

I have downloaded the basic Android command line tools from devloper.android.com, now i am creating a new AVD using following command
avdmanager create avd --package 'platforms;android-26;google_apis;x86' -n test-1
Its giving error
Error: Package path is not valid. Valid system image paths are:
I have already installed the package using sdkmanager and its available in my sdk folder under platforms.
First, you need to download the necessary packages.
Here is an example of downloading API 23 packages for x86 emulators:
./sdkmanager "system-images;android-23;google_apis;x86"
and then create your emulator:
./avdmanager create avd -n test -k "system-images;android-23;google_apis;x86" -b x86 -c 100M -d 7 -f
Or you can try with this sample steps:
android update sdk -u --filter platform-tools,android-25
sdkmanager --verbose "system-images;android-25;google_apis;x86"
and then create the avd using:
avdmanager -v create avd -n x86 -k "system-images;android-25;google_apis;x86" -g "google_apis"

Python script unable to run "android" command

I am trying to create "avd" from python script using command :
android create avd -n avd1 -t android-19 -s QVGA -b x86
Everytime i run this command through Terminal i get avd created but if i am running same command from python script i a getting error which says that "android" command was not found.
Python script:
#!/usr/bin/env python
import sys, os
def main():
cmd = "android create avd -n avd1 -t android-19 -s QVGA -b x86"
print cmd
os.system(cmd)
main()
What could be the possible error.
Environment : Ubuntu 13.04
Path variable set to: export PATH=$PATH:~/android-sdks/tools/:~/android-sdks/build-tools/:~/android-sdks/platform-tools/:~/android-sdks/
From Python's documentation:
Changes to sys.stdin, etc. are not reflected in the environment of the
executed command.
os.system has limitations. The subprocess module is preferable.
Try:
import subprocess
cmd = "android create avd -n avd1 -t android-19 -s QVGA -b x86"
subprocess.call(cmd.split())

Categories

Resources