- Homebrew
First, install JAVA. Note that Android SDK is not yet supported JAVA 10, so install JAVA 8:
$ brew tap caskroom/versions
$ brew cask install java8
Export JDK path for Android Studio in ~/.bash_profile
or ~/.zshrc
:
export STUDIO_JDK="$(/usr/libexec/java_home -v1.8)"
Then install fundamental cores for Android dev:
$ brew cask install android-sdk
$ brew cask install android-ndk
Export $ANDROID_HOME
:
export ANDROID_HOME=/usr/local/share/android-sdk
Start from build tools and main packages:
sdkmanager "platforms;android-27"
sdkmanager "build-tools;27.0.3"
sdkmanager "extras;android;m2repository"
sdkmanager "extras;google;m2repository"
sdkmanager "sources;android-27"
Then accept licenses:
sdkmanager --licenses
src: https://developer.android.com/studio/command-line/avdmanager
$ sdkmanager --update
In this case want to use Google Pixel as base device. Remember the id 17
.
$ avdmanager list | grep 'pixel' Device: pixel (Google)
Device: pixel (Google)
id: 17 or "pixel"
id: 18 or "pixel_c"
id: 19 or "pixel_xl"
$ sdkmanager --list | grep system-images
Choose the one you like to go with and install it:
$ sdkmanager 'system-images;android-25;google_apis;x86_64'
There is also image with playstore version, you can get it from:
$ sdkmanager --list | grep "system-images.*playstore"
system-images;android-25;google_apis_playstore;x86 | 9 | Google Play Intel x86 Atom System Image
$ sdkmanager 'system-images;android-25;google_apis_playstore;x86'
-n
: name of the virtual device.-k
: package to use, installed in previous step.-d
: device id for hardware profile.
$ avdmanager create avd -n Pixel -k 'system-images;android-25;google_apis;x86_64' -d 17
$ avdmanager list avd
Name: Pixel
Device: pixel (Google)
Path: /Users/tulakann/.android/avd/Pixel.avd
Target: Google APIs (Google Inc.)
Based on: Android API 25 Tag/ABI: google_apis/x86_64
$ avdmanager delete avd -n Pixel
src: https://developer.android.com/studio/run/emulator-commandline
$ emulator -list-avds
emulator -avd avd_name
Or
emulator @avd_name
By default hw.keyboard
is not set in config.ini
of AVD. To enable hardware keyboard to send to emulator, run commands below:
for file in ~/.android/avd/*avd; do
if cat $file/config.ini | grep "hw.keyboard=yes" > /dev/null; then
echo "✔ hw.keyboard is already added to $(basename $file)"
else
echo "hw.keyboard=yes" >> $file/config.ini
echo "✔ hw.keyboard=yes is added to $(basename $file)"
fi
done
These commands set hw.keyboard
for all AVD available in ~/.android/avd
.