0

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)

Community
  • 1
  • 1
  • Where have you defined the PATH variable in? Did you define in a shell-specific configuration file? It's probably also because you've defined your script to run in `bash` instead of the default `zsh` shell as seen in the first line of your script and you've probably configured the PATH variable on only your zsh config. – Edric Oct 31 '19 at 15:36
  • But i am using zsh as my default shell(so i have added it only to my zshrc file), do i still need to add it to bashrc file? – Electroenthusiast Oct 31 '19 at 15:47
  • The solution here is to change the shell you're using to run the script in. See this guide on what a shebang is for more info: https://bash.cyberciti.biz/guide/Shebang (in this case, just change `bash` to `zsh` and you're good to go!) – Edric Oct 31 '19 at 15:48
  • The error still remains, after changing it to #!/bin/zsh. Additionally i also get the error: Broken AVD system path. – Electroenthusiast Oct 31 '19 at 15:56
  • But as I've mentioned in my original comment, _where have you defined the PATH variable_ and how have you defined it, as well as the other environmental variables? – Edric Oct 31 '19 at 15:57
  • I have added the below variables to my .zshrc file export ANDROID_HOME=$HOME/Library/Android/sdk export PATH=$ANDROID_HOME:$PATH – Electroenthusiast Oct 31 '19 at 15:59
  • What about the `ANDROID_AVD_HOME` variable, as per what the error is mentioning? Did you define that? – Edric Oct 31 '19 at 16:01
  • Yes added as below: export ANDROID_AVD_HOME=$ANDROID_HOME/.android/avd export PATH=ANDROID_AVD_HOME:$PATH – Electroenthusiast Oct 31 '19 at 16:03
  • From the comment you pasted, it seems that you're missing a dollar sign from the `export PATH=ANDROID_AVD_HOME:$PATH` line. A dollar sign should be added before the `ANDROID_AVD_HOME` part. – Edric Oct 31 '19 at 16:06
  • If you notice the error it says ANDROID_AVD_HOME is defined but there is no Android.ini – Electroenthusiast Oct 31 '19 at 16:06
  • I think i pasted it wrong but i has the $ sign prefixed – Electroenthusiast Oct 31 '19 at 16:07
  • Did you ensure that you've exported the environmental variables in the correct sequencing? – Edric Oct 31 '19 at 16:08
  • yes the order is correct – Electroenthusiast Oct 31 '19 at 16:09

1 Answers1

0

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.