0
votes

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)

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
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
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: bash.cyberciti.biz/guide/Shebang (in this case, just change bash to zsh and you're good to go!) - Edric
The error still remains, after changing it to #!/bin/zsh. Additionally i also get the error: Broken AVD system path. - Electroenthusiast
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

1 Answers

0
votes

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.