Sometimes, you just want to run an Android Emulator and you don’t want to have to deal with an IDE or a bunch of GUI stuff. Sometimes, you just want it simple and command line. Epic Force is getting into the mobile development space, and I was going to help test the Android build of a cool application we’re building. Finding documentation of how to do this 100% command line is tricky, and there is lots of old information to sift through as the process has recently changed.
Here’s how to do it, up-to-date as of May 1st, 2019. Of course, your mileage may vary if you stumble across this in the future.
And, if you need help with your Android or iOS projects, let us know. Epic Force has been developing applications for over 20 years and can either provide you with staffing, or help you do your project at any stage!
First, you need the Android SDK. This is a Zip you get from google. Get the CLI version. Go here: https://developer.android.com/studio/index.html
Then scroll past the Android Studio stuff and pick the appropriate item from the “Command Line Tools Only” list. At the time of this writing, the download for Linux is called “sdk-tools-linux-433796.zip” however that number is sure to change frequently. These instructions should also work (more or less) for Mac and Windows, though I only tested them in Linux.
Make a directory somewhere called “android”, put the zip in there, and unzip it. Note that the zip file does NOT have a “root directory” in it, so if you just unzip it, it will dump a bunch of stuff in the current directory. I hate when zip files do that! Woe be unto you if you already have directories the same name as what is in the zip.
Go into the ‘tools’ directory of the unzipped folder. We are going to use sdkmanager to download the system images, platform tools, and platform that we need. If you made an ‘android’ directory in your home directory and unzipped the SDK into that directory like I did, you’d do this:
./bin/sdkmanager --install 'system-images;android-28;google_apis;x86_64'
./bin/sdkmanager --install 'platforms;android-28'
./bin/sdkmanager --install platform-tools
The “android-28” portion is key; that is the version of android that will be available to you. You can list all the options with:
You will need a system-images and a matching platforms for each version of Android you want to run in the emulator. It is up to the reader to figure out the mapping of Android image numbers to “friendly” Android operating system versions; in my use case, the latest one was fine.
The AVD (Android Virtual Device) is the image that will be used by the emulator. You can have as many of these as you need. To create an AVD, while still in the ‘tools’ directory as in the above steps, type:
./bin/avdmanager create avd -n ImageName -k "system-images;android-28;google_apis;x86_64"
The -k portion should match whatever image you downloaded. It will ask if you want to create a custom hardware profile; the answer is likely “no”.
avdmanager can also delete and edit your images and has reasonably instructive help. Your images (on Linux, and probably Mac) are stored in ~/.android/avd
So the previous steps you should only have to do once (or every time you want to set up a new virtual device). This is what you do when you want to run the emulator. While still in the “tools” directory, because the emulator is incredibly sensitive to what directory you are in, type:
Where ImageName was the AVD image you created in the previous step. It should just work! Please note that the emulator will save your Android’s state however you have it when you close the emulator; personally I find this unhelpful, so I go into the options (See the … on the side bar), pick Snapshots on the left, then the Settings tab, and I turn off Auto-save current state to Quickboot.
If you don’t do this, awkward stuff can happen. For instance, I turned off the emulator with the little ‘On/Off’ button … and it wouldn’t come back on again no matter what I did. Then I closed the emulator, and it saved my emulated android in the off state. Nothing I did would turn it on, so I had to re-make my image. I’m sure there’s a way around this, but good luck finding an answer for it.
But, at least now, you have an answer as to how to run the emulator!